Example #1
0
        private IReadOnlyList <Token> ParseTokens(string query, out Expr immediateResult)
        {
            try
            {
                if (string.IsNullOrEmpty(query))
                {
                    immediateResult = new IdentityExpr(new Location(1, 1));
                    return(null);
                }

                var lexer = new Lexer(
                    operators: new [] {
                    "|", "|<", "&", ".", "(", "[?", "[", "{", "}", "]", ")", ".", "@", "*",
                    "?", ":", ",", "-", "+", "/", "%", "==", "!=", "&&", "||", "??", "..",
                    "<", "<=", ">", ">=", "=", "$", ";", "...", "!"
                },
                    charKind: "STRING",
                    charsMustBeOneChar: false,
                    backtickStringKind: "STRING",
                    intKind: "NUMBER",
                    floatKind: "NUMBER",
                    stringKind: "STRING",
                    hasVariables: true
                    );

                // Take a guess as to the size of the list so that it doesn't have to get rebuilt a bunch.
                var tokens = new List <Token>(query.Length / 3);
                foreach (var token in lexer.Parse(query))
                {
                    tokens.Add(token);
                }

                immediateResult = null;
                return(tokens);
            }
            catch (ParseException ex)
            {
                immediateResult = new ErrorExpr(ex.Location, ex.Message);
                return(null);
            }
            catch (Exception ex)
            {
                immediateResult = new ErrorExpr(new Location(0, 0), ex.Message);
                return(null);
            }
        }
Example #2
0
 public virtual void Visit(IdentityExpr expr)
 {
 }
Example #3
0
 public override void Visit(IdentityExpr expr) => _needsAsync   = true;