This class is implemented manually to improve parsing errors.

All functions have running time O(n).

This class internally uses yield return to report early errors first.

Parsing error and token tracking is implemented with local members to improve readability (see ParsingError and _origin).

Exemplo n.º 1
0
        public FormulaTree Parse(string input, out ParsingError parsingError)
        {
            var tokens = _tokenizer.Tokenize(input, out parsingError);

            if (parsingError != null)
            {
                return(null);
            }

            return(tokens == null ? null : FormulaInterpreter.Interpret(tokens.ToList(), out parsingError));
        }
        public static FormulaTree Interpret(IList<IFormulaToken> tokens, out ParsingError parsingError)
        {
            // TODO: split to InterpretNumber and InterpretLogic
            //var sw = new Stopwatch();
            //sw.Start();

            // interpret tokens
            var instance = new FormulaInterpreter();
            var result = instance.Interpret2(tokens);
            parsingError = instance.ParsingError;

            //sw.Stop();
            // Debug.WriteLine("Interpreter.Interpret needed " + sw.ElapsedMilliseconds + "ms");

            return result;
        }
        public static FormulaTree Interpret(IList <IFormulaToken> tokens, out ParsingError parsingError)
        {
            // TODO: split to InterpretNumber and InterpretLogic
            //var sw = new Stopwatch();
            //sw.Start();

            // interpret tokens
            var instance = new FormulaInterpreter();
            var result   = instance.Interpret2(tokens);

            parsingError = instance.ParsingError;

            //sw.Stop();
            // Debug.WriteLine("Interpreter.Interpret needed " + sw.ElapsedMilliseconds + "ms");

            return(result);
        }
        public static Range Complete(IList<IFormulaToken> tokens, int index)
        {
            //var sw = new Stopwatch();
            //sw.Start();

            // validate input
            if (tokens == null || !(0 <= index && index < tokens.Count)) return Range.Empty(0);

            // complete token
            var instance = new FormulaInterpreter();
            var result = instance.Complete2(tokens, index);

            //sw.Stop();
            // Debug.WriteLine("Interpreter.CompleteToken needed " + sw.ElapsedMilliseconds + "ms");

            return result;
        }
        public static Range Complete(IList <IFormulaToken> tokens, int index)
        {
            //var sw = new Stopwatch();
            //sw.Start();

            // validate input
            if (tokens == null || !(0 <= index && index < tokens.Count))
            {
                return(Range.Empty(0));
            }

            // complete token
            var instance = new FormulaInterpreter();
            var result   = instance.Complete2(tokens, index);

            //sw.Stop();
            // Debug.WriteLine("Interpreter.CompleteToken needed " + sw.ElapsedMilliseconds + "ms");

            return(result);
        }