TODO
Bool : 'true' | 'false' ;
Integer : 0 | [1-9][0-9]* ;
Real : Integer '.' [0-9]* ;
Identifier : [_a-zA-Z][_a-zA-Z0-9]* ;
ValidSymbol
: [^\n\t\r\'\"\\]
| Escape
;
// TODO
Escape
: '\' (ValidSymbol|'\''|'"'|'\\')
;
Space : '\n' | '\t' | '\r' ;
// TODO
String
: '"' (ValidSymbol|'\''|Space)* '"'
;
// TODO
Char
: '\'' (ValidSymbol|'"') '\''
;
Program : EOL* Decls? EOL* EOF ;
Decls
: Decl
| Decls EOL+ Decl
;
Decl
: Stmt
;
Stmt
: VarStmt
| Expr
;
Pattern
: TypedPattern
| InferredPattern
;
TypedPattern
: Identifier EOL* ':' EOL* Type
;
InferredPattern
: Identifier
;
// TODO: make type initializer optional
VarStmt
: 'var' Pattern EOL* '=' Expr
;
Type
: IDENTIFIER
;
Expr
: Assignment
;
// s.t. change
Assignment
: Assignable '=' Assignment
| Addition
;
Addition
: Multiplication (('+'|'-') Multiplication)*
;
Multiplication
: Unary (('*'|'/') Unary)*
;
Unary
: ('-'|'+') Unary
| Primary
;
Primary
: Identifier
| Integer
| Real
| String
| Bool
| Char
| '(' EOL* Expr EOL* ')'
| IfExpr
| BlockExpr
| WhileExpr
| UnitExpr
;
UnitExpr
: 'unit'
;
Assignable
: Identifier
;
IfExpr
: 'if' '(' EOL* Expr EOL* ')' Expr (EOL* 'else' Expr)?
;
BlockExpr
: '{' EOL* Stmts? EOL* '}'
;
Stmts
: Stmt
| Stmts EOL+ Stmt
;
WhileExpr
: 'while' '(' EOL* Expr EOL* ')' Expr
;