diff options
author | Stephan Unverwerth <s.unverwerth@gmx.de> | 2020-03-12 23:02:41 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-14 00:11:24 +0100 |
commit | 15d5b2d29e5b375a7b0601e7c456ac49868c606d (patch) | |
tree | 7c0d4da55a7565f5d3ca54eedd441b26f800f80a /Libraries/LibJS/Token.h | |
parent | f347dd5c5e261fc8c77917508e47680dbd166be5 (diff) | |
download | serenity-15d5b2d29e5b375a7b0601e7c456ac49868c606d.zip |
LibJS: Add operator precedence parsing
Obey precedence and associativity rules when parsing expressions
with chained operators.
Diffstat (limited to 'Libraries/LibJS/Token.h')
-rw-r--r-- | Libraries/LibJS/Token.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Libraries/LibJS/Token.h b/Libraries/LibJS/Token.h index 9a7463ce51..8d442e4a7d 100644 --- a/Libraries/LibJS/Token.h +++ b/Libraries/LibJS/Token.h @@ -35,10 +35,13 @@ enum class TokenType { Ampersand, AmpersandEquals, Asterisk, + AsteriskAsteriskEquals, AsteriskEquals, + Await, BoolLiteral, BracketClose, BracketOpen, + Caret, Catch, Class, Comma, @@ -48,7 +51,9 @@ enum class TokenType { Delete, Do, DoubleAmpersand, + DoubleAsterisk, DoublePipe, + DoubleQuestionMark, Else, Eof, Equals, @@ -64,6 +69,8 @@ enum class TokenType { GreaterThanEquals, Identifier, If, + In, + Instanceof, Interface, Invalid, LessThan, @@ -86,17 +93,26 @@ enum class TokenType { PlusEquals, PlusPlus, QuestionMark, + QuestionMarkPeriod, RegexLiteral, Return, Semicolon, ShiftLeft, + ShiftLeftEquals, ShiftRight, + ShiftRightEquals, Slash, SlashEquals, StringLiteral, + Tilde, Try, + Typeof, + UnsignedShiftRight, + UnsignedShiftRightEquals, Var, - While + Void, + While, + Yield, }; class Token { @@ -125,3 +141,11 @@ private: }; } + +namespace AK { +template<> +struct Traits<JS::TokenType> : public GenericTraits<JS::TokenType> { + static constexpr bool is_trivial() { return true; } + static unsigned hash(JS::TokenType t) { return int_hash((int)t); } +}; +} |