-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCFBuilder.g4
146 lines (102 loc) · 4.81 KB
/
MCFBuilder.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
grammar MCFBuilder;
program: line* EOF;
line: assignFunction | statement | ifBlock | executeBlock | whileBlock | forBlock | assignFile | COMMENT | command;
statement: (assignment | functionCall | return | global) SEMI;
ifBlock
: 'if' ifConditionalBlock+ block ('else' elseIfBlock)? #ifConditionalExpression
| 'if' '(' expression ')' block ('else' elseIfBlock)? #IfStandardExpression
;
ifConditionalBlock
: 'entity' '(' selector ')' #IfEntityExpression
| 'score' '(' IDENTIFIER selector compareOp expression ')' #IfScoreMatchesCompareExpression
| 'score' expression ('to' expression)? '(' IDENTIFIER selector ')' #IfScoreMatchesExpression
| 'score' '('IDENTIFIER selector compareOp IDENTIFIER selector ')' #IfScoreCompareExpression
| 'predicate' '(' expression ',' expression ')' #IfPredicateExpression
| 'block' vector '(' expression ')' #IfBlockExpression
| 'blocks' vector vector vector '(' IFBLOCKSTYPE ')' #IfBlocksExpression
| 'data' 'block' vector '(' expression ')' #IfDataBlockExpression
| 'data' 'entity' selector '(' expression? ')' #IfDataEntityExpression
| 'data' 'storage' expression '(' expression ')' #IfDataStorageExpression
;
executeBlock: 'execute' (executeTypes)+ block ;
executeTypes
: ('as' selector) #ExecuteAsExpression
| ('at' selector) #ExecuteAtExpression
| ('positioned' (('as' selector) | (vector))) #ExeuctePositionedExpression
;
vector
: '~' expression? '~' expression? '~' expression? #ExactVectorExpression
| '^' expression? '^' expression? '^' expression? #RelativeVectorExpression
;
elseIfBlock: block | ifBlock;
whileBlock: WHILE '(' expression ')' block;
WHILE: 'while';
forBlock: 'for' '(' IDENTIFIER 'in' (INTEGER 'to' INTEGER | dict | list | IDENTIFIER) ')' block;
assignFunction: 'def' IDENTIFIER '(' IDENTIFIER? (',' IDENTIFIER)* ')' block ;
// assignment: ((VARIABLES_TYPE)? IDENTIFIER ( ':' IDENTIFIER ) selector assignOp expression selector? )
// | ((VARIABLES_TYPE)? IDENTIFIER assignOp expression)
// | ((VARIABLES_TYPE)? IDENTIFIER selector assignOp expression);
assignment: localScoresAssignment || scoresEqual || localTagsAssignment || generalAssignment ;
generalAssignment: localAssignment || operation;
localTagsAssignment: 'tag' 'var' IDENTIFIER (selector '=' BOOL)? ;
localAssignment: 'var' IDENTIFIER ('=' expression)? ;
localScoresAssignment: 'score' 'var' IDENTIFIER selector '=' expression;
global: globalAssignment || globalScoresAssignment || globalTagsAssignment ;
globalTagsAssignment: 'tag' 'global' IDENTIFIER (selector '=' BOOL)? ;
globalAssignment: 'global' IDENTIFIER ('=' expression)? ;
globalScoresAssignment: 'score' 'global' IDENTIFIER selector '=' expression;
operation: expression selector? assignOp expression ;
// scoresOperation: 'score' IDENTIFIER selector assignOp expression ;
// tagsOperation: 'tag' IDENTIFIER selector '=' BOOL ;
scoresEqual: IDENTIFIER selector assignOp IDENTIFIER selector ;
selector: SELECTOR | expression ;
VARIABLES_TYPE: ('var' | 'global') ;
createClass: 'new' IDENTIFIER '(' (expression (',' expression)*)? ')' ;
classVariables: IDENTIFIER DOT IDENTIFIER ;
functionCall: IDENTIFIER (DOT IDENTIFIER)? '(' (expression (',' expression)*)? ')';
return: 'return' expression;
expression
: expression '[' expression ']' #getIdentifierDataExpression
| constant #constantExpression
| IDENTIFIER #identifierExpression
| createClass #createClassExpression
| classVariables #classVariablesExpression
| functionCall #functionCallExpression
| '(' expression ')' #parenthesizedExpression
| '!' expression #notExpression
| expression multOp expression #multiplicativeExpression
| expression addOp expression #additiveExpression
| expression compareOp expression #comparisionExpression
| expression boolOp expression #booleanExpression
| SELECTOR #selectorExpressionInExpression
;
assignFile : AssignFile;
AssignFile: '#' (IDENTIFIER ('/' IDENTIFIER)*) ~[\r\n]* ;
//operator
multOp: '*' | '/';
addOp: '+' | '-' ;
compareOp: '==' | '!=' | '>' | '<' | '<=' | '>=';
boolOp: BOOL_OPERATOR;
assignOp: '=' | '+=' | '-=' | '%=' | '*=' | '/=' ;
BOOL_OPERATOR: '&&' | '||';
//data type
constant: INTEGER | FLOAT | STRING | BOOL | dict | list | NULL;
list: '[' expression? (',' expression)* ']' ;
dict: '{' (STRING ':' expression)? (',' STRING ':' expression)* '}' ;
number: INTEGER | FLOAT ;
INTEGER: [0-9]+;
FLOAT: [0-9]+ '.' [0-9]+;
STRING: ('"' ~'"'* '"') | ('\'' ~'\''* '\'');
BOOL: 'true' | 'false';
NULL: 'null';
block: '{' line* '}';
DOT: '.';
IFTYPES: 'entity' | 'score' ;
IFBLOCKSTYPE: 'all' | 'masked' ;
SELECTOR: ('@' ('s'|'a'|'r'|'e'|'p'));
command: COMMAND ;
COMMAND: '/' ~[\r\n]*;
COMMENT: '//' ~[\r\n]* -> skip;
WS: [ \t\r\n]+ -> skip;
IDENTIFIER: [a-zA-Z0-9_][a-zA-Z0-9_]*;
SEMI: ';';