Skip to content

Commit

Permalink
fix parse order
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianPommerening committed Nov 21, 2023
1 parent a63f23e commit 7ad2d81
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/search/parser/lexical_analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ static vector<pair<TokenType, regex>> construct_token_type_expressions() {
{TokenType::LET, R"(let)"},
{TokenType::BOOLEAN, R"(true|false)"},
{TokenType::STRING, R"("(\\\\|\\"|\\n|[^"\\])*")"},
{TokenType::INTEGER, R"([+-]?(infinity|\d+([kmg]\b)?))"},
/*
Floats have to be parsed before integers, so tokens like '1.2' are
parsed as one float token rather than an integer token '1' followed
by a float token '.2'.
*/
{TokenType::FLOAT,
R"([+-]?(((\d*\.\d+|\d+\.)(e[+-]?\d+|[kmg]\b)?)|\d+e[+-]?\d+))"},
{TokenType::INTEGER, R"([+-]?(infinity|\d+([kmg]\b)?))"},
/*
Identifiers have to be parsed last to prevent reserved words (
'infinity', 'true', 'false', and 'let') from being recognized as
identifiers.
*/
{TokenType::IDENTIFIER, R"([a-zA-Z_]\w*)"}
};
vector<pair<TokenType, regex>> token_type_expression;
Expand Down

0 comments on commit 7ad2d81

Please sign in to comment.