Skip to content

Instantly share code, notes, and snippets.

@jorendorff
Last active October 7, 2023 23:17
Show Gist options
  • Save jorendorff/ce26cb12aa57b04848e94616c26910bc to your computer and use it in GitHub Desktop.
Save jorendorff/ce26cb12aa57b04848e94616c26910bc to your computer and use it in GitHub Desktop.
Tokens after which the next token is never a RegularExpressionLiteral:
BooleanLiteral => div
"Name" => div
NoSubstitutionTemplate => div
NullLiteral => div
NumericLiteral => div
RegularExpressionLiteral => div
StringLiteral => div
TemplateTail => div
"]" => div
"as" => div
"async" => div
"break" => div
"catch" => div
"class" => div
"const" => div
"continue" => div
"debugger" => div
"enum" => div
"export" => div
"false" => div
"finally" => div
"for" => div
"from" => div
"function" => div
"get" => div
"if" => div
"implements" => div
"import" => div
"interface" => div
"let" => div
"null" => div
"package" => div
"private" => div
"protected" => div
"public" => div
"set" => div
"static" => div
"super" => div
"switch" => div
"target" => div
"this" => div
"true" => div
"try" => div
"var" => div
"while" => div
"with" => div
Expression nonterminals -- you can ignore these:
AdditiveExpression => div
ArrayLiteral => div
AsyncFunctionExpression => div
AsyncGeneratorExpression => div
AwaitExpression => div
BitwiseANDExpression[~In] => div
BitwiseANDExpression[+In] => div
BitwiseORExpression[~In] => div
BitwiseORExpression[+In] => div
BitwiseXORExpression[~In] => div
BitwiseXORExpression[+In] => div
CallExpression => div
ClassExpression => div
EqualityExpression[~In] => div
EqualityExpression[+In] => div
ExponentiationExpression => div
FunctionExpression => div
GeneratorExpression => div
IdentifierReference => div
ImportCall => div
LeftHandSideExpression => div
Literal => div
LogicalANDExpression[~In] => div
LogicalANDExpression[+In] => div
LogicalORExpression[~In] => div
LogicalORExpression[+In] => div
MemberExpression => div
MetaProperty => div
MultiplicativeExpression => div
NewExpression => div
NewTarget => div
ObjectLiteral => div
PrimaryExpression => div
RelationalExpression[~In] => div
RelationalExpression[+In] => div
ShiftExpression => div
SubstitutionTemplate => div
SuperCall => div
SuperProperty => div
TemplateLiteral => div
UnaryExpression => div
UpdateExpression => div
Other nonterminals for trailing bits of expressions. Ignore these too:
Arguments => div
CoverCallExpressionAndAsyncArrowHead => div
CoverParenthesizedExpressionAndArrowParameterList => div
TemplateSpans => div
Keywords that can appear before expressions. All of these can also appear after "."
with a different meaning (property names).
"." "await" => div
<other> "await" => re
"." "case" => div
<other> "case" => re
"." "default" => div
<other> "default" => re
"." "delete" => div
<other> "delete" => re
"." "do" => div
<other> "do" => re
"." "else" => div
<other> "else" => re
"." "extends" => div
<other> "extends" => re
"." "in" => div
<other> "in" => re
"." "instanceof" => div
<other> "instanceof" => re
"." "new" => div
<other> "new" => re
"." "return" => div
<other> "return" => re
"." "throw" => div
<other> "throw" => re
"." "typeof" => div
<other> "typeof" => re
"." "void" => div
<other> "void" => re
"." "yield" => div
<other> "yield" => re
One keyword, `of`, is tricky. When it's a keyword, a regexp can appear after it;
but `of` can also be an identifier.
<div context> "of" => re
ForBinding "of" => re
ForDeclaration "of" => re
LeftHandSideExpression "of" => re
<other> "of" => div
";" ")" => re
"(" AssignmentExpression[+In] ")" => div
"of" AssignmentExpression[+In] ")" => re
<re context> "(" Expression[+In] ")" => div
"if" "(" Expression[+In] ")" => re
"while" "(" Expression[+In] ")" => re
"with" "(" Expression[+In] ")" => re
<other> "(" Expression[+In] ")" => div
<other> Expression[+In] ")" => re
<other> ")" => div
<div context> "++" => div
<other> "++" => re
<div context> "--" => div
<other> "--" => re
"," "}" => div
ObjectLiteral => div
<decl context> FunctionOrClass => re
<other> FunctionOrClass => div
where <decl context> is anywhere a FunctionDeclaration could appear;
roughly speaking, one of:
<start of script/module>
"default"
"export"
<decl context> "{"
<decl context> LabelIdentifier ":"
<decl context> StatementList
<decl context> ModuleItemList
"if" "(" Expression ")"
"else"
...and probably many others. This is necessary because <re context> includes
both statement starts and expression starts. Note that StatementList includes
many things that end with "}", like Block, TryStatement, and preceding declarations.
In all other contexts, including at the start of a script or module, a slash is
the start of a regular expression.
<other> => re
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment