Skip to content

Instantly share code, notes, and snippets.

@i64
Last active September 11, 2020 18:45
Show Gist options
  • Save i64/98a3fd8210d3c411f99a7a6d84312591 to your computer and use it in GitHub Desktop.
Save i64/98a3fd8210d3c411f99a7a6d84312591 to your computer and use it in GitHub Desktop.
module JavaScript {
VariableDeclarationKind = Var | Let | Const
CompoundAssignmentOperator = PLUSEQUAL | MINEQUAL | STAREQUAL | SLASHEQUAL
| PERCENTEQUAL | DOUBLESTAREQUAL | LEFTSHIFTEQUAL
| RIGHTSHIFTEQUAL | UNSIGNEDRIGHTSHIFTASSIG | VBAREQUAL
| CIRCUMFLEXEQUAL | AMPEREQUAL
BinaryOperator = EQEQUAL | NOTEQUAL | EQEQEQUAL
| NOTEQEQUAL | LESS | LESSEQUAL
| GREATER | GREATEREQUAL | IN | instanceof
| LEFTSHIFT | RIGHTSHIFT | UNSIGNEDRIGHSHIFT | PLUS
| MINUS | STAR | SLASH | PERCENT | DOUBLESTAR
| COMMA | LOGICALOR | LOGICALAND | VBAR | CIRCUMFLEX | AMPER
UnaryOperator = PLUS | MINUS | NOT | TILDE | typeof | void | delete
UpdateOperator = DOUBLE_PLUS | DOUBLE_MINUS
Function = attributes(bool isAsync, bool isGenerator, FormalParameters params, FunctionBody body)
Class = attributes(Expression? super, ClassElement* elements)
-- identifier = DOMString
Node = PropertyName()
| ArrayBinding(BindingOrBindingWithDefault elements, Binding? rest)
| ObjectProperty()
| ImportDeclaration(string moduleSpecifier)
| ExportDeclaration()
| VariableReference(Identifier name)
| BindingWithDefault(Binding binding, Expression init)
| MemberAssignmentTarget(ExpressionOrSuper object)
| ObjectBinding(BindingProperty* properties, BindingIdentifier? rest)
| BindingProperty()
| AssignmentTargetWithDefault(AssignmentTarget binding, Expression init)
| ArrayAssignmentTarget(AssignmentTargetOrAssignmentTargetWithDefault elements, AssignmentTarget? rest)
| ObjectAssignmentTarget(AssignmentTargetProperty* properties, SimpleAssignmentTarget? rest)
| AssignmentTargetProperty()
| ClassElement(bool isStatic, MethodDefinition method)
| ImportSpecifier(IdentifierName? name, BindingIdentifier binding)
| ExportFromSpecifier(IdentifierName name, IdentifierName? exportedName)
| ExportLocalSpecifier(IdentifierExpression name, IdentifierName? exportedName)
| CatchClause(Binding? binding, Block body)
| Directive(string rawValue)
| FormalParameters(Parameter* items, Binding? rest)
| FunctionBody(Directive* directives, Statement* statements)
| SpreadElement(Expression expression)
| Super()
| SwitchCase(Expression test, Statement* consequent)
| SwitchDefault(Statement* consequent)
| TemplateElement(string rawValue)
| VariableDeclaration(VariableDeclarationKind kind, VariableDeclarator* declarators)
| VariableDeclarator(Binding binding, Expression? init)
| BindingProperty()
| Expression
| Program
-- attributes (Type type)
Expression = MemberExpression(ExpressionOrSuper object)
| ClassExpression(BindingIdentifier? name)
| LiteralBooleanExpression(bool value)
| LiteralInfinityExpression()
| LiteralNullExpression()
| LiteralNumericExpression(float value)
| LiteralRegExpExpression(string pattern, bool _global, bool ignoreCase, bool multiLine, bool dotAll, bool unicode, bool sticky)
| LiteralStringExpression(string value)
| ArrayExpression(SpreadElementOrExpression elements)
| ArrowExpression(bool isAsync, FormalParameters params, FunctionBodyOrExpression body)
| AssignmentExpression(AssignmentTarget binding, Expression expression)
| BinaryExpression(BinaryOperator operator, Expression left, Expression right)
| CallExpression(ExpressionOrSuper callee, Arguments arguments)
| CompoundAssignmentExpression(CompoundAssignmentOperator operator, SimpleAssignmentTarget binding, Expression expression)
| ComputedMemberExpression(Expression expression)
| ConditionalExpression(Expression test, Expression consequent, Expression alternate)
| FunctionExpression(BindingIdentifier? name)
| IdentifierExpression()
| NewExpression(Expression callee, Arguments arguments)
| NewTargetExpression()
| ObjectExpression(ObjectProperty* properties)
| UnaryExpression(UnaryOperator operator, Expression operand)
| StaticMemberExpression(IdentifierName property)
| TemplateExpression(Expression? tag, ExpressionOrTemplateElement elements)
| ThisExpression()
| UpdateExpression(bool isPrefix, UpdateOperator operator, SimpleAssignmentTarget operand)
| YieldExpression(Expression? expression)
| YieldGeneratorExpression(Expression expression)
| AwaitExpression(Expression expression)
Statement = IterationStatement(Statement body)
| BlockStatement(Block block)
| BreakStatement(Label? label)
| ContinueStatement(Label? label)
| DebuggerStatement()
| DoWhileStatement(Expression test)
| EmptyStatement()
| ExpressionStatement(Expression expression)
| ForInStatement(VariableDeclarationOrAssignmentTarget left, Expression right)
| ForOfStatement(VariableDeclarationOrAssignmentTarget left, Expression right)
| ForAwaitStatement(VariableDeclarationOrAssignmentTarget left, Expression right)
| ForStatement(VariableDeclarationOrExpression init, Expression? test, Expression? update)
| IfStatement(Expression test, Statement consequent, Statement? alternate)
| LabeledStatement(Label label, Statement body)
| ReturnStatement(Expression? expression)
| SwitchStatement(Expression discriminant, SwitchCase* cases)
| SwitchStatementWithDefault(Expression discriminant, SwitchCase* preDefaultCases, SwitchDefault defaultCase, SwitchCase* postDefaultCases)
| ThrowStatement(Expression expression)
| TryCatchStatement(Block body, CatchClause catchClause)
| TryFinallyStatement(Block body, CatchClause? catchClause, Block finalizer)
| VariableDeclarationStatement(VariableDeclaration declaration)
| WhileStatement(Expression test)
| WithStatement(Expression object, Statement body)
| Block(Statement* statements)
| ClassDeclaration(BindingIdentifier name)
| FunctionDeclaration(BindingIdentifier name)
DOMString = Identifier
| IdentifierName
| Label
SimpleAssignmentTarget = AssignmentTargetIdentifier()
| MemberAssignmentTarget
Arguments = SpreadElement(Expression expression)
| Expression
Parameter = Binding | BindingWithDefault
VariableReference = BindingIdentifier()
| AssignmentTargetIdentifier()
| DataProperty(Expression expression)
attributes (Identifier name)
NamedObjectProperty = ObjectProperty()
| MethodDefinition(FunctionBody body)
attributes (PropertyName name)
MemberAssignmentTarget = ComputedMemberAssignmentTarget(Expression expression)
| StaticMemberAssignmentTarget(IdentifierName property)
attributes (ExpressionOrSuper object)
BindingProperty = BindingPropertyIdentifier(BindingIdentifier binding, Expression? init)
| BindingPropertyProperty(PropertyName name, BindingOrBindingWithDefault binding)
AssignmentTargetProperty = AssignmentTargetPropertyIdentifier(AssignmentTargetIdentifier binding, Expression? init)
| AssignmentTargetPropertyProperty(PropertyName name, AssignmentTargetOrAssignmentTargetWithDefault binding)
ImportDeclaration = Import(BindingIdentifier? defaultBinding, ImportSpecifier* namedImports)
| ImportNamespace(BindingIdentifier? defaultBinding, BindingIdentifier namespaceBinding)
attributes (string moduleSpecifier)
ExportDeclaration = ExportAllFrom(string moduleSpecifier)
| ExportFrom(ExportFromSpecifier* namedExports, string moduleSpecifier)
| ExportLocals(ExportLocalSpecifier* namedExports)
| Export(FunctionDeclarationOrClassDeclarationOrVariableDeclaration declaration)
| ExportDefault(FunctionDeclarationOrClassDeclarationOrExpression body)
MethodDefinition = Method(bool isAsync, bool isGenerator, FormalParameters params)
| Getter()
| Setter(Parameter param)
ObjectProperty = ShorthandProperty(IdentifierExpression name)
| SpreadProperty(Expression expression)
PropertyName = ComputedPropertyName(Expression expression)
| StaticPropertyName(string value)
Program = Script(Directive* directives, Statement* statements)
| Module(Directive* directives, ImportDeclarationOrExportDeclarationOrStatement items)
ExpressionOrSuper = Expression | Super
BindingOrBindingWithDefault = Binding | BindingWithDefault
AssignmentTargetOrAssignmentTargetWithDefault = AssignmentTarget | AssignmentTargetWithDefault
ImportDeclarationOrExportDeclarationOrStatement = ImportDeclaration | ExportDeclaration | Statement
FunctionDeclarationOrClassDeclarationOrVariableDeclaration = FunctionDeclaration | ClassDeclaration | VariableDeclaration
FunctionDeclarationOrClassDeclarationOrExpression = FunctionDeclaration | ClassDeclaration | Expression
SpreadElementOrExpression = SpreadElement | Expression
FunctionBodyOrExpression = FunctionBody | Expression
ExpressionOrTemplateElement = Expression | TemplateElement
VariableDeclarationOrAssignmentTarget = VariableDeclaration | AssignmentTarget
VariableDeclarationOrExpression = VariableDeclaration | Expression
}
from __future__ import annotations
from typing import List, Optional, Union
string = Union[str, bytes]
constant = Union[str, bytes, int, float, complex, bool, tuple, frozenset, None, type(Ellipsis)]
class AST:
...
class VariableDeclarationKind(AST):
...
class Var(VariableDeclarationKind):
...
class Let(VariableDeclarationKind):
...
class Const(VariableDeclarationKind):
...
class CompoundAssignmentOperator(AST):
...
class PLUSEQUAL(CompoundAssignmentOperator):
...
class MINEQUAL(CompoundAssignmentOperator):
...
class STAREQUAL(CompoundAssignmentOperator):
...
class SLASHEQUAL(CompoundAssignmentOperator):
...
class PERCENTEQUAL(CompoundAssignmentOperator):
...
class DOUBLESTAREQUAL(CompoundAssignmentOperator):
...
class LEFTSHIFTEQUAL(CompoundAssignmentOperator):
...
class RIGHTSHIFTEQUAL(CompoundAssignmentOperator):
...
class UNSIGNEDRIGHTSHIFTASSIG(CompoundAssignmentOperator):
...
class VBAREQUAL(CompoundAssignmentOperator):
...
class CIRCUMFLEXEQUAL(CompoundAssignmentOperator):
...
class AMPEREQUAL(CompoundAssignmentOperator):
...
class BinaryOperator(AST):
...
class EQEQUAL(BinaryOperator):
...
class NOTEQUAL(BinaryOperator):
...
class EQEQEQUAL(BinaryOperator):
...
class NOTEQEQUAL(BinaryOperator):
...
class LESS(BinaryOperator):
...
class LESSEQUAL(BinaryOperator):
...
class GREATER(BinaryOperator):
...
class GREATEREQUAL(BinaryOperator):
...
class IN(BinaryOperator):
...
class instanceof(BinaryOperator):
...
class LEFTSHIFT(BinaryOperator):
...
class RIGHTSHIFT(BinaryOperator):
...
class UNSIGNEDRIGHSHIFT(BinaryOperator):
...
class PLUS(BinaryOperator):
...
class MINUS(BinaryOperator):
...
class STAR(BinaryOperator):
...
class SLASH(BinaryOperator):
...
class PERCENT(BinaryOperator):
...
class DOUBLESTAR(BinaryOperator):
...
class COMMA(BinaryOperator):
...
class LOGICALOR(BinaryOperator):
...
class LOGICALAND(BinaryOperator):
...
class VBAR(BinaryOperator):
...
class CIRCUMFLEX(BinaryOperator):
...
class AMPER(BinaryOperator):
...
class UnaryOperator(AST):
...
class PLUS(UnaryOperator):
...
class MINUS(UnaryOperator):
...
class NOT(UnaryOperator):
...
class TILDE(UnaryOperator):
...
class typeof(UnaryOperator):
...
class void(UnaryOperator):
...
class delete(UnaryOperator):
...
class UpdateOperator(AST):
...
class DOUBLE_PLUS(UpdateOperator):
...
class DOUBLE_MINUS(UpdateOperator):
...
class Function(AST):
isAsync: bool
isGenerator: bool
params: FormalParameters
body: FunctionBody
class Class(AST):
...
class Class(AST):
super: Optional[Expression]
elements: List[ClassElement]
class Node(AST):
...
class PropertyName(Node):
...
class ArrayBinding(Node):
elements: BindingOrBindingWithDefault
rest: Optional[Binding]
class ObjectProperty(Node):
...
class ImportDeclaration(Node):
moduleSpecifier: string
class ExportDeclaration(Node):
...
class BindingWithDefault(Node):
binding: Binding
init: Expression
class ObjectBinding(Node):
properties: List[BindingProperty]
rest: Optional[BindingIdentifier]
class BindingProperty(Node):
...
class AssignmentTargetWithDefault(Node):
binding: AssignmentTarget
init: Expression
class ArrayAssignmentTarget(Node):
elements: AssignmentTargetOrAssignmentTargetWithDefault
rest: Optional[AssignmentTarget]
class ObjectAssignmentTarget(Node):
properties: List[AssignmentTargetProperty]
rest: Optional[SimpleAssignmentTarget]
class ClassElement(Node):
isStatic: bool
method: MethodDefinition
class ImportSpecifier(Node):
name: Optional[IdentifierName]
binding: BindingIdentifier
class ExportFromSpecifier(Node):
name: IdentifierName
exportedName: Optional[IdentifierName]
class ExportLocalSpecifier(Node):
name: IdentifierExpression
exportedName: Optional[IdentifierName]
class CatchClause(Node):
binding: Optional[Binding]
body: Block
class Directive(Node):
rawValue: string
class FormalParameters(Node):
items: List[Parameter]
rest: Optional[Binding]
class FunctionBody(Node):
directives: List[Directive]
statements: List[Statement]
class SpreadElement(Node):
expression: Expression
class Super(Node):
...
class SwitchCase(Node):
test: Expression
consequent: List[Statement]
class SwitchDefault(Node):
consequent: List[Statement]
class TemplateElement(Node):
rawValue: string
class VariableDeclaration(Node):
kind: VariableDeclarationKind
declarators: List[VariableDeclarator]
class VariableDeclarator(Node):
binding: Binding
init: Optional[Expression]
class BindingProperty(Node):
...
class Expression(Node):
...
class Program(Node):
...
class Expression(AST):
...
class MemberExpression(Expression):
object: ExpressionOrSuper
class ClassExpression(Expression):
name: Optional[BindingIdentifier]
class LiteralBooleanExpression(Expression):
value: bool
class LiteralInfinityExpression(Expression):
...
class LiteralNullExpression(Expression):
...
class LiteralNumericExpression(Expression):
value: float
class LiteralRegExpExpression(Expression):
pattern: string
_global: bool
ignoreCase: bool
multiLine: bool
dotAll: bool
unicode: bool
sticky: bool
class LiteralStringExpression(Expression):
value: string
class ArrayExpression(Expression):
elements: SpreadElementOrExpression
class ArrowExpression(Expression):
isAsync: bool
params: FormalParameters
body: FunctionBodyOrExpression
class AssignmentExpression(Expression):
binding: AssignmentTarget
expression: Expression
class BinaryExpression(Expression):
operator: BinaryOperator
left: Expression
right: Expression
class CallExpression(Expression):
callee: ExpressionOrSuper
arguments: Arguments
class CompoundAssignmentExpression(Expression):
operator: CompoundAssignmentOperator
binding: SimpleAssignmentTarget
expression: Expression
class ComputedMemberExpression(Expression):
expression: Expression
class ConditionalExpression(Expression):
test: Expression
consequent: Expression
alternate: Expression
class FunctionExpression(Expression):
name: Optional[BindingIdentifier]
class IdentifierExpression(Expression):
...
class NewExpression(Expression):
callee: Expression
arguments: Arguments
class NewTargetExpression(Expression):
...
class ObjectExpression(Expression):
properties: List[ObjectProperty]
class UnaryExpression(Expression):
operator: UnaryOperator
operand: Expression
class StaticMemberExpression(Expression):
property: IdentifierName
class TemplateExpression(Expression):
tag: Optional[Expression]
elements: ExpressionOrTemplateElement
class ThisExpression(Expression):
...
class UpdateExpression(Expression):
isPrefix: bool
operator: UpdateOperator
operand: SimpleAssignmentTarget
class YieldExpression(Expression):
expression: Optional[Expression]
class YieldGeneratorExpression(Expression):
expression: Expression
class AwaitExpression(Expression):
expression: Expression
class Statement(AST):
...
class IterationStatement(Statement):
body: Statement
class BlockStatement(Statement):
block: Block
class BreakStatement(Statement):
label: Optional[Label]
class ContinueStatement(Statement):
label: Optional[Label]
class DebuggerStatement(Statement):
...
class DoWhileStatement(Statement):
test: Expression
class EmptyStatement(Statement):
...
class ExpressionStatement(Statement):
expression: Expression
class ForInStatement(Statement):
left: VariableDeclarationOrAssignmentTarget
right: Expression
class ForOfStatement(Statement):
left: VariableDeclarationOrAssignmentTarget
right: Expression
class ForAwaitStatement(Statement):
left: VariableDeclarationOrAssignmentTarget
right: Expression
class ForStatement(Statement):
init: VariableDeclarationOrExpression
test: Optional[Expression]
update: Optional[Expression]
class IfStatement(Statement):
test: Expression
consequent: Statement
alternate: Optional[Statement]
class LabeledStatement(Statement):
label: Label
body: Statement
class ReturnStatement(Statement):
expression: Optional[Expression]
class SwitchStatement(Statement):
discriminant: Expression
cases: List[SwitchCase]
class SwitchStatementWithDefault(Statement):
discriminant: Expression
preDefaultCases: List[SwitchCase]
defaultCase: SwitchDefault
postDefaultCases: List[SwitchCase]
class ThrowStatement(Statement):
expression: Expression
class TryCatchStatement(Statement):
body: Block
catchClause: CatchClause
class TryFinallyStatement(Statement):
body: Block
catchClause: Optional[CatchClause]
finalizer: Block
class VariableDeclarationStatement(Statement):
declaration: VariableDeclaration
class WhileStatement(Statement):
test: Expression
class WithStatement(Statement):
object: Expression
body: Statement
class Block(Statement):
statements: List[Statement]
class ClassDeclaration(Statement):
name: BindingIdentifier
class FunctionDeclaration(Statement):
name: BindingIdentifier
class DOMString(str):
...
class Identifier(DOMString):
...
class IdentifierName(DOMString):
...
class Label(DOMString):
...
class SimpleAssignmentTarget(AST):
...
class AssignmentTargetIdentifier(SimpleAssignmentTarget):
...
class MemberAssignmentTarget(Node, SimpleAssignmentTarget):
object: ExpressionOrSuper
class Arguments(AST):
...
class SpreadElement(Arguments):
expression: Expression
class Expression(Arguments):
...
class Parameter(AST):
...
class Binding(Parameter):
...
class BindingWithDefault(Parameter):
...
class VariableReference(Node):
name: Identifier
class BindingIdentifier(VariableReference):
...
class AssignmentTargetIdentifier(VariableReference):
...
class DataProperty(VariableReference):
expression: Expression
class NamedObjectProperty(AST):
name: PropertyName
class ObjectProperty(Node, NamedObjectProperty):
...
class MethodDefinition(NamedObjectProperty):
body: FunctionBody
class ComputedMemberAssignmentTarget(MemberAssignmentTarget):
expression: Expression
class StaticMemberAssignmentTarget(MemberAssignmentTarget):
property: IdentifierName
class BindingProperty(AST):
...
class BindingPropertyIdentifier(BindingProperty):
binding: BindingIdentifier
init: Optional[Expression]
class BindingPropertyProperty(BindingProperty):
name: PropertyName
binding: BindingOrBindingWithDefault
class AssignmentTargetProperty(Node):
...
class AssignmentTargetPropertyIdentifier(AssignmentTargetProperty):
binding: AssignmentTargetIdentifier
init: Optional[Expression]
class AssignmentTargetPropertyProperty(AssignmentTargetProperty):
name: PropertyName
binding: AssignmentTargetOrAssignmentTargetWithDefault
class Import(ImportDeclaration):
defaultBinding: Optional[BindingIdentifier]
namedImports: List[ImportSpecifier]
class ImportNamespace(ImportDeclaration):
defaultBinding: Optional[BindingIdentifier]
namespaceBinding: BindingIdentifier
class ExportAllFrom(ExportDeclaration):
moduleSpecifier: string
class ExportFrom(ExportDeclaration):
namedExports: List[ExportFromSpecifier]
moduleSpecifier: string
class ExportLocals(ExportDeclaration):
namedExports: List[ExportLocalSpecifier]
class Export(ExportDeclaration):
declaration: FunctionDeclarationOrClassDeclarationOrVariableDeclaration
class ExportDefault(ExportDeclaration):
body: FunctionDeclarationOrClassDeclarationOrExpression
class Method(MethodDefinition):
isAsync: bool
isGenerator: bool
params: FormalParameters
class Getter(MethodDefinition):
...
class Setter(MethodDefinition):
param: Parameter
class ShorthandProperty(ObjectProperty):
name: IdentifierExpression
class SpreadProperty(ObjectProperty):
expression: Expression
class ComputedPropertyName(PropertyName):
expression: Expression
class StaticPropertyName(PropertyName):
value: string
class Script(Program):
directives: List[Directive]
statements: List[Statement]
class Module(Program):
directives: List[Directive]
items: ImportDeclarationOrExportDeclarationOrStatement
class ExpressionOrSuper(AST):
...
class Expression(ExpressionOrSuper):
...
class Super(ExpressionOrSuper):
...
class BindingOrBindingWithDefault(AST):
...
class Binding(BindingOrBindingWithDefault):
...
class BindingWithDefault(BindingOrBindingWithDefault):
...
class AssignmentTargetOrAssignmentTargetWithDefault(AST):
...
class AssignmentTarget(AssignmentTargetOrAssignmentTargetWithDefault):
...
class AssignmentTargetWithDefault(AssignmentTargetOrAssignmentTargetWithDefault):
...
class ImportDeclarationOrExportDeclarationOrStatement(AST):
...
class ImportDeclaration(ImportDeclarationOrExportDeclarationOrStatement):
...
class ExportDeclaration(ImportDeclarationOrExportDeclarationOrStatement):
...
class Statement(ImportDeclarationOrExportDeclarationOrStatement):
...
class FunctionDeclarationOrClassDeclarationOrVariableDeclaration(AST):
...
class FunctionDeclaration(FunctionDeclarationOrClassDeclarationOrVariableDeclaration):
...
class ClassDeclaration(FunctionDeclarationOrClassDeclarationOrVariableDeclaration):
...
class VariableDeclaration(FunctionDeclarationOrClassDeclarationOrVariableDeclaration):
...
class FunctionDeclarationOrClassDeclarationOrExpression(AST):
...
class FunctionDeclaration(FunctionDeclarationOrClassDeclarationOrExpression):
...
class ClassDeclaration(FunctionDeclarationOrClassDeclarationOrExpression):
...
class Expression(FunctionDeclarationOrClassDeclarationOrExpression):
...
class SpreadElementOrExpression(AST):
...
class SpreadElement(SpreadElementOrExpression):
...
class Expression(SpreadElementOrExpression):
...
class FunctionBodyOrExpression(AST):
...
class FunctionBody(FunctionBodyOrExpression):
...
class Expression(FunctionBodyOrExpression):
...
class ExpressionOrTemplateElement(AST):
...
class Expression(ExpressionOrTemplateElement):
...
class TemplateElement(ExpressionOrTemplateElement):
...
class VariableDeclarationOrAssignmentTarget(AST):
...
class VariableDeclaration(VariableDeclarationOrAssignmentTarget):
...
class AssignmentTarget(VariableDeclarationOrAssignmentTarget):
...
class VariableDeclarationOrExpression(AST):
...
class VariableDeclaration(VariableDeclarationOrExpression):
...
class Expression(VariableDeclarationOrExpression):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment