-
-
Save ColinTimBarndt/aebc51177b93b7c6c002bb765ff1a941 to your computer and use it in GitHub Desktop.
WIP ANTLR grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar Minescripten; | |
module: definition* EOF; | |
definition: function | struct; | |
function: | |
'fn' Identifier '(' ( | |
functionArgument (',' functionArgument)+ | |
)? ')' ('->' Identifier)? '{' code '}'; | |
functionArgument: Identifier ':' Identifier; | |
struct: 'struct' Identifier; | |
code: functionCall ';'; | |
functionCall: | |
path '(' functionArgument (',' functionArgument)+ ')'; | |
variableDefinition: 'let' Identifier '=' expression; | |
expression: functionCall | path; | |
path: Identifier ('.' path)?; | |
literal: StringLiteral | IntegerLiteral | BooleanLiteral; | |
StringLiteral: '"' (StringCharacter | EscapeSequence)* '"'; | |
IntegerLiteral: [1-9] Digit+ | '0x' HexDigit+; | |
BooleanLiteral: 'true' | 'false'; | |
Identifier: Letter LetterOrDigit*; | |
fragment EscapeSequence: '\\' [nr"\\] | UnicodeEscapeSequence; | |
fragment UnicodeEscapeSequence: | |
'\\u' HexDigit HexDigit HexDigit HexDigit; | |
fragment Letter: [A-Za-z_]; | |
fragment LetterOrDigit: [A-Za-z_0-9]; | |
fragment StringCharacter: ~["\\\r\n]; | |
fragment Digit: [0-9]; | |
fragment HexDigit: [0-9a-fA-F]; | |
WS: [ \t\r\n]+ -> skip; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment