using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using NTERA.Engine.Compiler; namespace NTERA.Engine.Runtime.Base { public class KeywordAttribute : Attribute { public string Name { get; } public bool ImplicitString { get; } public bool ImplicitFormatted { get; } public KeywordAttribute(string name, bool implicitString = false, bool implicitFormatted = false) { if (implicitFormatted && !implicitString) throw new ArgumentException("Keyword cannot support formatting if it does not use implicit strings"); Name = name; ImplicitString = implicitString; ImplicitFormatted = implicitFormatted; } } public static class Keywords { public static Dictionary> StaticKeywords { get; } = _getKeywords(); private static Dictionary> _getKeywords() { var output = new Dictionary>(); foreach (MethodInfo method in typeof(Keywords).GetMethods(BindingFlags.Public | BindingFlags.Static)) { var keyword = method.GetCustomAttribute(); if (keyword != null) output[keyword.Name] = (runtime, set, node) => { method.Invoke(null, new object[] { runtime, set, node }); }; } return output; } [Keyword("DRAWLINE")] public static void DrawLine(EraRuntime runtime, ExecutionSet set, ExecutionNode node) { runtime.Console.PrintBar(); } [Keyword("DRAWLINEFORM", true, true)] public static void DrawLineForm(EraRuntime runtime, ExecutionSet set, ExecutionNode node) { var value = runtime.ComputeExpression(set, node.SubNodes.Single()); runtime.Console.printCustomBar(value.ToString().Trim()); } } }