// Lexical WhiteSpace: Space {Space} Space: ' ' '\t' '\v' '\u000C' EndOfLine Comment EndOfLine: '\r' '\n' '\r\n' '\n\r' EndOfFile EndOfFile: physical end of file '\0' Comment: '/*' {Character} '*/' '//' {Character} EndOfLine NestedComment NestedComment: '/+' {Character | NestedComment} '+/' Token: Identifier Keyword CharLiteral StringLiteral IntLiteral FloatLiteral '+' '+=' '++' '-' '-=' '--' '~' '~=' '*' '*=' '/' '/=' '%' '%=' '<' '<=' '<=>' '<<' '<<=' '>' '>=' '>>' '>>=' '>>>' '>>>=' '&' '&=' '&&' '|' '|=' '||' '^' '^=' '=' '==' '?' '?=' '.' '..' '!' '!=' '(' ')' '[' ']' '{' '}' ':' ',' ';' '#' '\' '->' '$' '@' EOF Identifier: IdentifierStart {IdentifierChar} IdentifierStart: '_' Letter IdentifierChar: IdentifierStart DecimalDigit Keyword: 'as' 'assert' 'break' 'case' 'catch' 'class' 'continue' 'coroutine' 'default' 'do' 'else' 'false' 'finally' 'for' 'foreach' 'function' 'global' 'if' 'import' 'in' 'is' 'local' 'module' 'namespace' 'null' 'return' 'scope' 'super' 'switch' 'this' 'throw' 'true' 'try' 'vararg' 'while' 'with' 'yield' CharLiteral: "'" (Character | EscapeSequence) "'" StringLiteral: RegularString WysiwygString AltWysiwygString RegularString: '"' {Character | EscapeSequence | EndOfLine} '"' EscapeSequence: '\'' '\"' '\\' '\a' '\b' '\f' '\n' '\r' '\t' '\v' '\x' HexDigit HexDigit '\u' HexDigit HexDigit HexDigit HexDigit '\U' HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit HexDigit '\ ' DecimalDigit [DecimalDigit [DecimalDigit]] WysiwygString: '@"' {Character | EndOfLine | '""'} '"' AltWysiwygString: '`' {Character | EndOfLine | '``'} '`' IntLiteral: Decimal Binary Hexadecimal Decimal: DecimalDigit {DecimalDigit | '_'} DecimalDigit: '0' .. '9' Binary: '0' ('b' | 'B') (BinaryDigit | '_') {BinaryDigit | '_'} BinaryDigit: '0' '1' Hexadecimal: '0' ('x' | 'X') (HexDigit | '_') {HexDigit | '_'} HexDigit: '0' .. '9' 'a' .. 'f' 'A' .. 'F' FloatLiteral: [DecimalDigit {DecimalDigit | '_'}] '.' (DecimalDigit | '_') {DecimalDigit | '_'} [Exponent] DecimalDigit {DecimalDigit | '_'} [Exponent] Exponent: ('e' | 'E')['+' | '-'] (DecimalDigit | '_') {DecimalDigit | '_'} // ----------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------- // Syntax Module: ModuleDeclaration {Statement} EOF ModuleDeclaration: [Decorators] 'module' Identifier {'.' Identifier} StatementTerminator StatementTerminator: ';' EndOfLine // not consumed '}' // not consumed ')' // not consumed ']' // not consumed Statement: AssertStatement ImportStatement BlockStatement ExpressionStatement DeclarationStatement IfStatement WhileStatement DoWhileStatement ForStatement ForeachStatement SwitchStatement ContinueStatement BreakStatement ReturnStatement TryCatchStatement ThrowStatement ScopeActionStatement Assignment AssertStatement: 'assert' '(' Expression [',' Expression] ')' StatementTerminator ImportStatement: 'import' [Identifier '='] Identifier {'.' Identifier} [SelectiveImports] StatementTerminator 'import' [Identifier '='] '(' Expression ')' [SelectiveImports] StatementTerminator SelectiveImports: ':' SelectiveImport {',' SelectiveImport} SelectiveImport: [Identifier '='] Identifier BlockStatement: '{' {Statement} '}' ExpressionStatement: Expression StatementTerminator DeclarationStatement: VariableDeclaration StatementTerminator [Decorators] OtherDeclaration Decorators: Decorator {Decorator} Decorator: '@' Identifier {'.' Identifier} [ArgumentsWith] OtherDeclaration: FunctionDeclaration ClassDeclaration NamespaceDeclaration VariableDeclaration: LocalVarDeclaration GlobalVarDeclaration LocalVarDeclaration: 'local' Identifier {',' Identifier} ['=' ExpressionList] GlobalVarDeclaration: 'global' Identifier {',' Identifier} ['=' ExpressionList] FunctionDeclaration: ['local' | 'global'] SimpleFunctionDeclaration SimpleFunctionDeclaration: 'function' Identifier FunctionBody FunctionBody: '(' Parameters ')' (Statement | '=' Expression) Parameters: [('this' ':' Type | Parameter) {',' Parameter} [',' 'vararg']] 'vararg' Parameter: Identifier [':' Type] ['=' Expression] Type: BasicType '!' 'null' 'any' BasicType: BasicType '|' BasicType 'null' 'bool' 'int' 'float' 'char' 'string' 'table' 'array' 'function' 'class' 'instance' [(Identifier {'.' Identifier}) | ('(' Expression')')] Identifier {'.' Identifier} 'namespace' 'thread' 'nativeobj' 'weakref' ClassDeclaration: ['local' | 'global'] 'class' Identifier [':' Expression] '{' {ClassMember} '}' ClassMember: [Decorators] SimpleFunctionDeclaration [Decorators] 'this' FunctionBody [Decorators] Identifier ['=' Expression] StatementTerminator NamespaceDeclaration: ['local' | 'global'] 'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}' NamespaceMember: [Decorators] SimpleFunctionDeclaration [Decorators] Identifier ['=' Expression] StatementTerminator IfStatement: 'if' '(' ['local' Identifier '='] Expression ')' Statement ['else' Statement] WhileStatement: 'while' '(' ['local' Identifier '='] Expression ')' Statement DoWhileStatement: 'do' Statement 'while' '(' Expression ')' ForStatement: 'for' '(' [ForInitializer] ';' [Expression] ';' [ForIncrement] ')' Statement 'for' '(' Identifier (':' | ';') Expression '..' Expression [',' Expression] ')' Statement ForInitializer: ForInitializer ',' ForInitializer Expression LocalVarDeclaration Assignment ForIncrement: ForIncrement ',' ForIncrement Expression Assignment ForeachStatement: 'foreach' '(' Identifier {',' Identifier} ';' Expression [',' Expression [',' Expression]] ')' Statement SwitchStatement: 'switch' '(' Expression ')' '{' CaseStatement {CaseStatement} [DefaultStatement] '}' CaseStatement: 'case' Expression ({',' Expression} | '..' Expression) ':' {Statement} DefaultStatement: 'default' ':' {Statement} ContinueStatement: 'continue' StatementTerminator BreakStatement: 'break' StatementTerminator ReturnStatement: 'return' [ExpressionList] StatementTerminator TryCatchStatement: 'try' Statement (('catch' '(' Identifier ')' Statement) || ('finally' Statement)) ThrowStatement: 'throw' Expression StatementTerminator ScopeActionStatement: 'scope' '(' ('exit' | 'success' | 'failure') ')' Statement Assignment: AssignmentLHS {',' AssignmentLHS} '=' ExpressionList AssignmentLHS '+=' Expression AssignmentLHS '-=' Expression AssignmentLHS '~=' Expression AssignmentLHS '*=' Expression AssignmentLHS '/=' Expression AssignmentLHS '%=' Expression AssignmentLHS '<<=' Expression AssignmentLHS '>>=' Expression AssignmentLHS '>>>=' Expression AssignmentLHS '|=' Expression AssignmentLHS '^=' Expression AssignmentLHS '&=' Expression AssignmentLHS '?=' Expression '++' PrimaryExpression '--' PrimaryExpression PrimaryExpression '++' PrimaryExpression '--' AssignmentLHS: Identifier // Note - for these, the PostfixExpression must start with Identifier, 'this', or '#'. PostfixExpression '[' ']' PostfixExpression '[' Expression ']' PostfixExpression '[' [Expression] '..' [Expression] ']' DotExpression Expression: ConditionalExpression ConditionalExpression: OrOrExpression OrOrExpression '?' Expression ':' ConditionalExpression OrOrExpression: AndAndExpression OrOrExpression '||' AndAndExpression AndAndExpression: OrExpression AndAndExpression '&&' OrExpression OrExpression: XorExpression OrExpression '|' XorExpression XorExpression: AndExpression XorExpression '^' AndExpression AndExpression: CompareExpression AndExpression '&' CompareExpression CompareExpression: ShiftExpression EqualExpression RelExpression EqualExpression: ShiftExpression '==' ShiftExpression ShiftExpression '!=' ShiftExpression ShiftExpression 'is' ShiftExpression ShiftExpression '!' 'is' ShiftExpression RelExpression: ShiftExpression '<' ShiftExpression ShiftExpression '<=' ShiftExpression ShiftExpression '>' ShiftExpression ShiftExpression '>=' ShiftExpression ShiftExpression '<=>' ShiftExpression ShiftExpression 'as' ShiftExpression ShiftExpression 'in' ShiftExpression ShiftExpression '!' 'in' ShiftExpression ShiftExpression: AddExpression ShiftExpression '<<' AddExpression ShiftExpression '>>' AddExpression ShiftExpression '>>>' AddExpression AddExpression: MulExpression AddExpression '+' MulExpression AddExpression '-' MulExpression AddExpression '~' MulExpression MulExpression: UnaryExpression MulExpression '*' UnaryExpression MulExpression '/' UnaryExpression MulExpression '%' UnaryExpression UnaryExpression: PostfixExpression '-' UnaryExpression '!' UnaryExpression '~' UnaryExpression '#' UnaryExpression 'coroutine' UnaryExpression PostfixExpression: PrimaryExpression CallExpression PostfixExpression '[' ']' PostfixExpression '[' Expression ']' PostfixExpression '[' [Expression] '..' [Expression] ']' PostfixExpression '.' 'super' DotExpression DotExpression: PostfixExpression '.' (Identifier | '(' Expression ')') CallExpression: PostfixExpression ArgumentsWith DotExpression ArgumentsWith 'super' ['.' (Identifier | '(' Expression ')')] Arguments ArgumentsWith: Arguments '(' 'with' Expression [',' ExpressionList] ')' Arguments: '(' [ExpressionList] ')' '$' ExpressionList ExpressionList: Expression {',' Expression} PrimaryExpression: Identifier 'this' 'null' 'true' 'false' 'vararg' IntLiteral FloatLiteral CharLiteral StringLiteral ':' (Identifier | 'super' | '(' Expression ')') 'function' [Identifier] FunctionBody '\' Parameters (('->' Expression) | BlockStatement) 'class' [Identifier] [':' Expression] '{' {ClassMember} '}' '(' Expression ')' TableCtorExp ArrayLiteral 'namespace' Identifier [':' Expression] '{' {NamespaceMember} '}' 'yield' '(' [Arguments] ')' ArrayLiteral: '[' [Expression [','] {Expression [',']}] ']' '[' Expression ForComprehension ']' TableCtorExp: '{' [TableField [','] { TableField [',']}] '}' '{' PlainTableField ForComprehension '}' TableField: Identifier '=' Expression PlainTableField SimpleFunctionDeclaration PlainTableField: '[' Expression ']' '=' Expression ForComprehension: 'for' Identifier {',' Identifier} 'in' Expression [',' Expression [',' Expression]] [IfComprehension] [ForComprehension] 'for' Identifier 'in' Expression '..' Expression [',' Expression] [IfComprehension] [ForComprehension] IfComprehension: 'if' Expression