This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Wyst.g4
65 lines (59 loc) · 1.73 KB
/
Wyst.g4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
grammar Wyst;
COMMENT: '//' ~[\r\n]* -> skip;
MULTILINE_COMMENT: '/*' .*? '*/' -> skip;
WS: [ \t\r\n]+ -> skip;
NUMBER: [1-9][0-9]* | '0';
HEX: '0x' [a-fA-F0-9]*;
IDENTIFIER: [a-zA-Z_] [a-zA-Z0-9_]* ('::' [a-zA-Z_] [a-zA-Z0-9_]*)*;
GOIDENTIFIER: '^' [a-zA-Z_] [a-zA-Z0-9_]* ('.' [a-zA-Z_] [a-zA-Z0-9_]*)*;
MATH: '+' | '-' | '*' | '/' | '==' | '!=' | '>=' | '<=';
fragment ESC: '\\' . ;
STRING: ('"' (ESC | ~["\\])* '"') | ('\'' (ESC | ~["\\])* '\'') ;
MODULE_NAME: [a-zA-Z_] [a-zA-Z0-9_]*;
round_def: '(' (var_def (',' var_def)* ','?)? ')';
enum_curly: '{' (var_def ';')* '}';
round_call: '(' (expr (',' expr)* ','?)? ')';
fn_call: IDENTIFIER round_call;
func_def: IDENTIFIER IDENTIFIER round_def code_block;
var_def: IDENTIFIER IDENTIFIER;
var_def_set: var_def '=' expr;
call_tree: (fn_call|IDENTIFIER) ('.' (fn_call|IDENTIFIER))*;
struct_def: 'struct' IDENTIFIER enum_curly;
namespace: 'namespace' IDENTIFIER '{' (((var_def|var_def_set) ';')|func_def)* '}';
import_statement: 'include' MODULE_NAME ';';
use_statement: 'use' IDENTIFIER ';';
go_import: '%import' STRING ';';
map: '%map' IDENTIFIER ',' IDENTIFIER ';';
go_call: GOIDENTIFIER round_call;
// if else statements
if_expr: '(' expr (('&&'|'||') expr)* ')';
if_statement: 'if' if_expr code_block*;
elseif_statement: 'else' if_statement;
else_statement: 'else' code_block*;
if_tree: if_statement elseif_statement* else_statement?;
expr:
(
call_tree |
NUMBER |
HEX |
IDENTIFIER |
STRING |
go_call |
GOIDENTIFIER
) (MATH expr)*;
code_block: '{' (((
expr |
var_def |
var_def_set
) ';') | (
if_tree
))* '}';
top: (
func_def |
struct_def |
namespace |
import_statement |
use_statement |
go_import |
map
)*;