faster: Finish the big grammar

This commit is contained in:
John Doty 2024-04-17 17:23:14 -07:00
parent de0a76818e
commit 6fa89a9757

View file

@ -132,6 +132,9 @@ MATCH = Token("Match")
EXPORT = Token("Export") EXPORT = Token("Export")
UNDERSCORE = Token("Underscore") UNDERSCORE = Token("Underscore")
NEW = Token("New") NEW = Token("New")
LSQUARE = Token("LeftBracket")
RSQUARE = Token("RightBracket")
# fmt: off # fmt: off
precedence = [ precedence = [
@ -206,7 +209,7 @@ grammar = {
"ExportStatement": [ "ExportStatement": [
[EXPORT, "ClassDeclaration"], [EXPORT, "ClassDeclaration"],
[EXPORT, "FunctionDeclaration"], [EXPORT, "FunctionDeclaration"],
# [EXPORT, "LetStatement"], [EXPORT, "LetStatement"],
[EXPORT, "ExportList", SEMICOLON], [EXPORT, "ExportList", SEMICOLON],
], ],
"ExportList": [ "ExportList": [
@ -252,35 +255,35 @@ grammar = {
"Statement": [ "Statement": [
["FunctionDeclaration"], ["FunctionDeclaration"],
["LetStatement"], ["LetStatement"],
# ["ReturnStatement"], ["ReturnStatement"],
# ["ForStatement"], ["ForStatement"],
["IfStatement"], ["IfStatement"],
# ["WhileStatement"], ["WhileStatement"],
# ["ExpressionStatement"], ["ExpressionStatement"],
], ],
"LetStatement": [ "LetStatement": [
[LET, IDENTIFIER, EQUAL, "Expression", SEMICOLON], [LET, IDENTIFIER, EQUAL, "Expression", SEMICOLON],
], ],
# "ReturnStatement": [ "ReturnStatement": [
# [RETURN, "Expression", SEMICOLON], [RETURN, "Expression", SEMICOLON],
# ], ],
# "ForStatement": [ "ForStatement": [
# [FOR, "IteratorVariable", IN, "Expression", "Block"], [FOR, "IteratorVariable", IN, "Expression", "Block"],
# ], ],
# "IteratorVariable": [[IDENTIFIER]], "IteratorVariable": [[IDENTIFIER]],
"IfStatement": [["ConditionalExpression"]], "IfStatement": [["ConditionalExpression"]],
# "WhileStatement": [ "WhileStatement": [
# [WHILE, "Expression", "Block"], [WHILE, "Expression", "Block"],
# ], ],
# "ExpressionStatement": [ "ExpressionStatement": [
# ["Expression", SEMICOLON], ["Expression", SEMICOLON],
# ], ],
# Expressions # Expressions
"Expression": [["AssignmentExpression"]], "Expression": [["AssignmentExpression"]],
@ -294,7 +297,7 @@ grammar = {
["IsExpression"], ["IsExpression"],
], ],
"IsExpression": [ "IsExpression": [
# ["IsExpression", IS, "Pattern"], ["IsExpression", IS, "Pattern"],
["AndExpression"], ["AndExpression"],
], ],
"AndExpression": [ "AndExpression": [
@ -335,12 +338,12 @@ grammar = {
["Block"], ["Block"],
["ConditionalExpression"], ["ConditionalExpression"],
# ["ListConstructorExpression"], ["ListConstructorExpression"],
# ["ObjectConstructorExpression"], ["ObjectConstructorExpression"],
# ["MatchExpression"], ["MatchExpression"],
# ["PrimaryExpression", LPAREN, "ExpressionList", RPAREN], ["PrimaryExpression", LPAREN, "ExpressionList", RPAREN],
# ["PrimaryExpression", DOT, IDENTIFIER], ["PrimaryExpression", DOT, IDENTIFIER],
[LPAREN, "Expression", RPAREN], [LPAREN, "Expression", RPAREN],
], ],
@ -351,62 +354,65 @@ grammar = {
[IF, "Expression", "Block", ELSE, "Block"], [IF, "Expression", "Block", ELSE, "Block"],
], ],
# "ListConstructorExpression": [ "ListConstructorExpression": [
# [LCURLY, "ExpressionList", RCURLY], [LSQUARE, RSQUARE],
# ], [LSQUARE, "ExpressionList", RSQUARE],
],
# "ExpressionList": [ "ExpressionList": [
# [], ["Expression"],
# ["Expression"], ["Expression", COMMA],
# ["Expression", COMMA, "ExpressionList"], ["Expression", COMMA, "ExpressionList"],
# ], ],
# # Match Expression # Match Expression
# "MatchExpression": [ "MatchExpression": [
# [MATCH, "MatchBody"], [MATCH, "MatchBody"],
# ], ],
# "MatchBody": [ "MatchBody": [
# [LCURLY, "MatchArms", RCURLY], [LCURLY, RCURLY],
# ], [LCURLY, "MatchArms", RCURLY],
# "MatchArms": [ ],
# [], "MatchArms": [
# ["MatchArm"], ["MatchArm"],
# ["MatchArm", COMMA, "MatchArms"], ["MatchArm", COMMA],
# ], ["MatchArm", COMMA, "MatchArms"],
# "MatchArm": [ ],
# ["Pattern", ARROW, "Expression"], "MatchArm": [
# ], ["Pattern", ARROW, "Expression"],
],
# # Pattern # Pattern
# "Pattern": [ "Pattern": [
# ["VariableBinding", "PatternCore", AND, "AndExpression"], ["VariableBinding", "PatternCore", AND, "AndExpression"],
# ["VariableBinding", "PatternCore"], ["VariableBinding", "PatternCore"],
# ["PatternCore", AND, "AndExpression"], ["PatternCore", AND, "AndExpression"],
# ["PatternCore"], ["PatternCore"],
# ], ],
# "PatternCore": [ "PatternCore": [
# ["TypeExpression"], ["TypeExpression"],
# ["WildcardPattern"], ["WildcardPattern"],
# ], ],
# "WildcardPattern": [[UNDERSCORE]], "WildcardPattern": [[UNDERSCORE]],
# "VariableBinding": [[IDENTIFIER, COLON]], "VariableBinding": [[IDENTIFIER, COLON]],
# # Object Constructor # Object Constructor
# "ObjectConstructorExpression": [ "ObjectConstructorExpression": [
# [NEW, "TypeIdentifier", "FieldList"], [NEW, "TypeIdentifier", "FieldList"],
# ], ],
# "FieldList": [ "FieldList": [
# [LCURLY, "FieldValues", RCURLY], [LCURLY, RCURLY],
# ], [LCURLY, "FieldValues", RCURLY],
# "FieldValues": [ ],
# [], "FieldValues": [
# ["FieldValue"], ["FieldValue"],
# ["FieldValue", COMMA, "FieldValues"], ["FieldValue", COMMA],
# ], ["FieldValue", COMMA, "FieldValues"],
# "FieldValue": [ ],
# [IDENTIFIER], "FieldValue": [
# [IDENTIFIER, COLON, "Expression"], [IDENTIFIER],
# ], [IDENTIFIER, COLON, "Expression"],
],
} }
# fmt: on # fmt: on