public void Parse(SourceSpan source, XElement element, PredefinedFormulaContext context)
            {
                var name   = element.AttributeValue("name");
                var result = context[name];

                Debug.Assert(result != null);
                this.Result = result;
            }
            public object?Parse(string value, PredefinedFormulaContext context)
            {
                if (value == null)
                {
                    return(null);
                }

                var formula = context[value];

                Debug.Assert(formula != null);
                return(formula);
            }
        private static object?[] GetArgumentValues(IEnumerable <XElement> args, PredefinedFormulaContext context)
        {
            var result = new List <object?>();

            foreach (var curArg in args)
            {
                var typeName = curArg.AttributeValue("type");
                var value    = curArg.AttributeValue("value");

                var parser = argValueParsers[typeName];
                result.Add(parser.Parse(value, context));
            }

            return(result.ToArray());
        }
            public void Parse(SourceSpan source, XElement element, PredefinedFormulaContext context)
            {
                var methodName = element.AttributeValue("name");
                var objectName = element.AttributeValue("formula");
                var args       = element.Elements("Argument");

                var formula = context[objectName];

                Debug.Assert(formula != null);

                var argTypes  = GetArgumentTypes(args);
                var argValues = GetArgumentValues(args, context);

                var helper           = new TexFormulaHelper(formula, source);
                var methodInvocation = typeof(TexFormulaHelper).GetMethod(methodName, argTypes) !;

                methodInvocation.Invoke(helper, argValues);
            }
        private TexFormula?ParseFormula(SourceSpan source, XElement formulaElement)
        {
            var context = new PredefinedFormulaContext();

            foreach (var element in formulaElement.Elements())
            {
                var parser = actionParsers[element.Name.ToString()];
                if (parser == null)
                {
                    continue;
                }

                parser.Parse(source, element, context);
                if (parser is ReturnParser)
                {
                    return(((ReturnParser)parser).Result);
                }
            }
            return(null);
        }
            public void Parse(SourceSpan source, XElement element, PredefinedFormulaContext context)
            {
                var name = element.AttributeValue("name");
                var args = element.Elements("Argument");

                var argValues = GetArgumentValues(args, context);

                Debug.Assert(argValues.Length == 1 || argValues.Length == 0);
                TexFormula formula;

                if (argValues.Length == 1)
                {
                    var parser = new TexFormulaParser();
                    formula = parser.Parse((string)argValues[0] !); // Nullable TODO: This might need null checking
                }
                else
                {
                    formula = new TexFormula {
                        Source = source
                    };
                }

                context.AddFormula(name, formula);
            }
 public object Parse(string value, PredefinedFormulaContext context)
 {
     return(Enum.Parse(this.enumType, value));
 }
 public object?Parse(string value, PredefinedFormulaContext context)
 {
     return(typeof(Color).GetField(value) !.GetValue(null));
 }
 public object Parse(string value, PredefinedFormulaContext context)
 {
     return(value);
 }
 public object Parse(string value, PredefinedFormulaContext context)
 {
     return(int.Parse(value, CultureInfo.InvariantCulture));
 }
 public object Parse(string value, PredefinedFormulaContext context)
 {
     Debug.Assert(value.Length == 1);
     return(value[0]);
 }