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);
        }
 private void SetParsingError(Range source, string message)
 {
     if (IsCancellationRequested)
     {
         return;
     }
     ParsingError = new ParsingError(message, source.Start, source.Length);
 }
Example #3
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 IEnumerable <IFormulaToken> Tokenize(string input, out ParsingError parsingError)
        {
            if (input == null)
            {
                parsingError = null;
                return(null);
            }

            InitTokenMappings(ServiceLocator.CultureService.GetCulture());

            var tokens = new List <IFormulaToken>();

            for (var index = 0; index < input.Length;)
            {
                // ignore whitespace
                if (char.IsWhiteSpace(input[index]))
                {
                    index++;
                    continue;
                }

                var match = Tokenize(_invariantTokenMappings, input, index)
                            ?? Tokenize(_cultureSpecificTokenMappings, input, index)
                            ?? Tokenize(_localizationSpecificTokenMappings, input, index)
                            ?? Tokenize(_instanceSpecificTokenMappings, input, index);
                if (match == null)
                {
                    // TODO: translate parsing error
                    parsingError = new ParsingError("Unknown token. ", index, 0);
                    return(null);
                }
                tokens.Add(match.Item2);
                index += match.Item1.Length;
            }

            parsingError = null;
            return(tokens);
        }
        public IEnumerable<IFormulaToken> Tokenize(string input, out ParsingError parsingError)
        {
            if (input == null)
            {
                parsingError = null;
                return null;
            }

            InitTokenMappings(ServiceLocator.CultureService.GetCulture());

            var tokens = new List<IFormulaToken>();
            for (var index = 0; index < input.Length; )
            {
                // ignore whitespace
                if (char.IsWhiteSpace(input[index]))
                {
                    index++;
                    continue;
                }

                var match = Tokenize(_invariantTokenMappings, input, index)
                            ?? Tokenize(_cultureSpecificTokenMappings, input, index)
                            ?? Tokenize(_localizationSpecificTokenMappings, input, index)
                            ?? Tokenize(_instanceSpecificTokenMappings, input, index);
                if (match == null)
                {
                    // TODO: translate parsing error
                    parsingError = new ParsingError("Unknown token. ", index, 0);
                    return null;
                }
                tokens.Add(match.Item2);
                index += match.Item1.Length;
            }

            parsingError = null;
            return tokens;
        }
 private void SetParsingError2(Range source, string message)
 {
     ParsingError = new ParsingError(message, source.Start, source.Length);
 }
 private void SetParsingError(Range source, string message)
 {
     if (IsCancellationRequested) return;
     ParsingError = new ParsingError(message, source.Start, source.Length);
 }
 private void SetParsingError2(Range source, string message)
 {
     ParsingError = new ParsingError(message, source.Start, source.Length);
 }