handled reserved words whether an expression is allowed or not

This commit is contained in:
Pagwin 2025-12-31 15:16:55 -05:00
parent 7388aee8d1
commit cd5e094eca
No known key found for this signature in database
GPG key ID: 81137023740CA260

View file

@ -219,7 +219,7 @@ token =
-- briefly was concerned about {} but then realized that isn't a literal -- briefly was concerned about {} but then realized that isn't a literal
try literal <* exprNotAllowed, try literal <* exprNotAllowed,
-- handled on a case by case basis -- handled on a case by case basis
try punctuator <* error "TODO", try punctuator <* exprNoop "Decided on a case by case basis",
try linebreak <* exprNoop "technically wrong due to semicolon insertion but hopefully that never comes up usage for this", try linebreak <* exprNoop "technically wrong due to semicolon insertion but hopefully that never comes up usage for this",
whitespace <* exprNoop "non linebreak whitespace doesn't change whether an expression is allowed or not, same as comments" whitespace <* exprNoop "non linebreak whitespace doesn't change whether an expression is allowed or not, same as comments"
] ]
@ -246,42 +246,42 @@ reserved_word :: (Logger m, Characters s) => Parser s m (Token s)
reserved_word = reserved_word =
choice choice
[ try await <* exprAllowed, [ try await <* exprAllowed,
try break <* error "TODO exprAllowed", try break <* exprNotAllowed,
try case_ <* exprAllowed, try case_ <* exprAllowed,
try catch_ <* error "TODO exprAllowed", try catch_ <* exprAllowed, -- literally invalid this is pure guess work
try class_ <* error "TODO exprAllowed", try class_ <* exprAllowed, -- literally invalid this is pure guess work
try const <* error "TODO exprAllowed", try const <* exprAllowed, -- literally invalid this is pure guess work
try continue <* error "TODO exprAllowed", try continue <* exprNotAllowed,
try debugger <* error "TODO exprAllowed", try debugger <* exprNotAllowed,
try default_ <* error "TODO exprAllowed", try default_ <* exprNotAllowed, -- literally invalid this is pure guess work
try delete <* exprAllowed, try delete <* exprAllowed,
try do_ <* error "TODO exprAllowed", try do_ <* exprNotAllowed,
try else_ <* error "TODO exprAllowed", try if_ <* exprAllowed, -- literally invalid this is pure guess work
try enum <* error "TODO exprAllowed", try else_ <* exprAllowed, -- literally invalid this is pure guess work
try export <* error "TODO exprAllowed", try enum <* exprNotAllowed, -- literally invalid this is pure guess work
try extends <* error "TODO exprAllowed", try export <* exprNotAllowed, -- literally invalid this is pure guess work
try extends <* exprAllowed,
try false <* exprNotAllowed, try false <* exprNotAllowed,
try finally_ <* error "TODO exprAllowed", try finally_ <* exprNotAllowed, -- literally invalid this is pure guess work
try for_ <* error "TODO exprAllowed", try for_ <* exprNotAllowed, -- literally invalid this is pure guess work
try function <* error "TODO exprAllowed", try function <* exprNotAllowed, -- literally invalid this is pure guess work
try if_ <* error "TODO exprAllowed", try import_ <* exprNotAllowed, -- literally invalid this is pure guess work
try import_ <* error "TODO exprAllowed",
try in_ <* exprAllowed, try in_ <* exprAllowed,
try instanceof <* exprAllowed, try instanceof <* exprAllowed,
try new <* error "TODO exprAllowed", try new <* exprAllowed,
try null <* error "TODO exprAllowed", try null <* exprNotAllowed,
try return <* exprAllowed, try return <* exprAllowed,
try super <* error "TODO exprAllowed", try super <* exprNotAllowed,
try switch <* error "TODO exprAllowed", try switch <* exprNotAllowed,
try this <* error "TODO exprAllowed", try this <* exprNotAllowed,
try throw_ <* exprAllowed, try throw_ <* exprAllowed,
try true <* exprNotAllowed, try true <* exprNotAllowed,
try try_ <* error "TODO exprAllowed", try try_ <* exprNotAllowed, -- literally invalid this is pure guess work
try typeof <* exprAllowed, try typeof <* exprAllowed,
try var <* exprNotAllowed, try var <* exprNotAllowed,
try void <* error "TODO exprAllowed", try void <* exprNotAllowed, -- literally invalid this is pure guess work
try while <* error "TODO exprAllowed", try while <* exprNotAllowed, -- literally invalid this is pure guess work
try with <* error "TODO exprAllowed", try with <* exprNotAllowed, -- literally invalid this is pure guess work
yield <* exprNotAllowed yield <* exprNotAllowed
] ]
where where
@ -394,58 +394,59 @@ punctuator :: (Logger m, Characters s) => Parser s m (Token s)
punctuator = punctuator =
Punc Punc
<$> ( choice <$> ( choice
[ try $ string ">>>=" *> pure UnsignedRightShiftAssign, [ try $ string ">>>=" *> pure UnsignedRightShiftAssign <* exprAllowed,
try $ string "..." *> pure Spread, try $ string "..." *> pure Spread <* exprNotAllowed,
try $ string "===" *> pure TripleEqual, try $ string "===" *> pure TripleEqual <* exprAllowed,
try $ string "!==" *> pure DoubleNotEqual, try $ string "!==" *> pure DoubleNotEqual <* exprAllowed,
try $ string "<<=" *> pure LeftShiftAssign, try $ string "<<=" *> pure LeftShiftAssign <* exprAllowed,
try $ string ">>=" *> pure RightShiftAssign, try $ string ">>=" *> pure RightShiftAssign <* exprAllowed,
try $ string ">>>" *> pure UnsignedRightShift, try $ string ">>>" *> pure UnsignedRightShift <* exprAllowed,
try $ string "**=" *> pure ExpAssign, try $ string "**=" *> pure ExpAssign <* exprAllowed,
try $ string "&&=" *> pure LogicalAndAssign, try $ string "&&=" *> pure LogicalAndAssign <* exprAllowed,
try $ string "||=" *> pure LogicalOrAssign, try $ string "||=" *> pure LogicalOrAssign <* exprAllowed,
try $ string "??=" *> pure NullishAssign, try $ string "??=" *> pure NullishAssign <* exprAllowed,
try $ string "?." *> (notFollowedBy digitChar) *> pure OptionalChain, try $ string "++" *> pure Inc <* error "TODO: Ambiguous precrement vs postcrement",
try $ string "**" *> pure Exp, try $ string "--" *> pure Dec <* error "TODO: Ambiguous precrement postcrement",
try $ string "++" *> pure Inc, try $ string "?." *> (notFollowedBy digitChar) *> pure OptionalChain <* exprNotAllowed,
try $ string "--" *> pure Dec, try $ string "**" *> pure Exp <* exprAllowed,
try $ string "<=" *> pure LTEQ, try $ string "<=" *> pure LTEQ <* exprAllowed,
try $ string ">=" *> pure GTEQ, try $ string ">=" *> pure GTEQ <* exprAllowed,
try $ string "==" *> pure DoubleEqual, try $ string "==" *> pure DoubleEqual <* exprAllowed,
try $ string "!=" *> pure NotEqual, try $ string "!=" *> pure NotEqual <* exprAllowed,
try $ string "<<" *> pure LeftShift, try $ string "<<" *> pure LeftShift <* exprAllowed,
try $ string ">>" *> pure RightShift, try $ string ">>" *> pure RightShift <* exprAllowed,
try $ string "+=" *> pure AddAssign, try $ string "+=" *> pure AddAssign <* exprAllowed,
try $ string "-=" *> pure SubAssign, try $ string "-=" *> pure SubAssign <* exprAllowed,
try $ string "*=" *> pure MultAssign, try $ string "*=" *> pure MultAssign <* exprAllowed,
try $ string "%=" *> pure ModAssign, try $ string "%=" *> pure ModAssign <* exprAllowed,
try $ string "&=" *> pure BitwiseAndAssign, try $ string "&=" *> pure BitwiseAndAssign <* exprAllowed,
try $ string "|=" *> pure BitwiseOrAssign, try $ string "|=" *> pure BitwiseOrAssign <* exprAllowed,
try $ string "^=" *> pure BitwiseXorAssign, try $ string "^=" *> pure BitwiseXorAssign <* exprAllowed,
try $ string "&&" *> pure LogicalAnd, try $ string "&&" *> pure LogicalAnd <* exprAllowed,
try $ string "||" *> pure LogicalOr, try $ string "||" *> pure LogicalOr <* exprAllowed,
try $ string "??" *> pure Nullish, try $ string "??" *> pure Nullish <* exprAllowed,
char '+' *> pure Add, char '+' *> pure Add <* exprAllowed,
char '-' *> pure Sub, char '-' *> pure Sub <* exprAllowed,
char '*' *> pure Mult, char '*' *> pure Mult <* exprAllowed,
char '%' *> pure Mod, char '%' *> pure Mod <* exprAllowed,
char '<' *> pure Utilities.Javascript.LT, char '<' *> pure Utilities.Javascript.LT <* exprAllowed,
char '>' *> pure Utilities.Javascript.GT, char '>' *> pure Utilities.Javascript.GT <* exprAllowed,
char '&' *> pure BitwiseAnd, char '&' *> pure BitwiseAnd <* exprAllowed,
char '|' *> pure BitwiseOr, char '|' *> pure BitwiseOr <* exprAllowed,
char '^' *> pure BitwiseXor, char '^' *> pure BitwiseXor <* exprAllowed,
char '~' *> pure BitwiseNot, char '~' *> pure BitwiseNot <* exprAllowed,
char '=' *> pure Assign, char '=' *> pure Assign <* exprAllowed,
char '(' *> pure LParen, char ';' *> pure Semicolon <* exprAllowed,
char ')' *> pure RParen, char ',' *> pure Comma <* exprAllowed,
char '{' *> pure LCurly, char '!' *> pure LogicalNot <* exprAllowed,
char '}' *> pure RCurly, -- HERE
char '[' *> pure LSquare, char '(' *> pure LParen <* exprNotAllowed,
char ']' *> pure RSquare, char ')' *> pure RParen <* exprNotAllowed,
char '.' *> pure Dot, char '{' *> pure LCurly <* error "TODO: Ambiguous",
char ';' *> pure Semicolon, char '}' *> pure RCurly <* error "TODO: Ambiguous",
char ',' *> pure Comma, char '[' *> pure LSquare <* exprNotAllowed,
char '!' *> pure LogicalNot char ']' *> pure RSquare <* exprNotAllowed,
char '.' *> pure Dot <* exprNotAllowed
] ]
) )