-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPapyrusParserSSE.g4
More file actions
224 lines (170 loc) · 7.52 KB
/
PapyrusParserSSE.g4
File metadata and controls
224 lines (170 loc) · 7.52 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MIT License
*
* Copyright 2026 Open Papyrus Project
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
parser grammar PapyrusParserSSE;
options { tokenVocab=PapyrusLexerSSE; }
script : terminator? header definitionOrBlock* EOF
;
header : SCRIPTNAME ID ( EXTENDS ID )? userFlags? terminator (DOCSTRING terminator)?
;
userFlags : (ID | GLOBAL | NATIVE)+
;
definitionOrBlock : fieldDefinition
| import_obj
| function
| eventFunc
| stateBlock
| propertyBlock
;
fieldDefinition : type ID ( EQUALS constant )? userFlags? terminator
;
import_obj : IMPORT ID terminator
;
function : functionHeader functionBlock
;
functionHeader : type? FUNCTION ID LPAREN callParameters? RPAREN userFlags? terminator (DOCSTRING terminator)?
;
functionBlock : terminator
| terminator statement* ENDFUNCTION terminator
;
eventFunc : eventHeader eventBlock
;
eventHeader : EVENT eventName LPAREN callParameters? RPAREN userFlags? terminator (DOCSTRING terminator)?
;
eventName : ID DOT ID
| ID
;
eventBlock : terminator ENDEVENT
| terminator statement* ENDEVENT terminator
;
callParameters : callParameter ( COMMA callParameter )*
;
callParameter : type ID? ( EQUALS constant )?
;
stateBlock : AUTO? STATE ID terminator stateFuncOrEvent* ENDSTATE terminator
;
stateFuncOrEvent : function
| eventFunc
;
propertyBlock : propertyHeader propertyFunc ( propertyFunc )* ENDPROPERTY terminator
| autoPropertyHeader
| readOnlyPropertyHeader
;
propertyHeader : type PROPERTY ID userFlags? terminator (DOCSTRING terminator)?
;
autoPropertyHeader : type PROPERTY ID ( EQUALS constant )? AUTO userFlags? terminator (DOCSTRING terminator)?
;
readOnlyPropertyHeader : BASETYPE PROPERTY ID EQUALS constant AUTOREADONLY userFlags? terminator (DOCSTRING terminator)?
;
propertyFunc : function
;
statement : localDefinition
| l_value PLUSEQUALS expression terminator
| l_value MINUSEQUALS expression terminator
| l_value MULTEQUALS expression terminator
| l_value DIVEQUALS expression terminator
| l_value MODEQUALS expression terminator
| l_value EQUALS expression terminator
| expression terminator
| return_stat
| ifBlock
| whileBlock
;
l_value : LPAREN expression RPAREN DOT ID
| LPAREN expression RPAREN LBRACKET expression RBRACKET
| basic_l_value
;
basic_l_value : array_func_or_id DOT basic_l_value
| func_or_id LBRACKET expression RBRACKET
| ID
;
localDefinition : type ID (EQUALS expression)? terminator
;
expression : and_expression ( OR and_expression )*
;
and_expression : bool_expression ( AND bool_expression )*
;
bool_expression : add_expression ( ( EQ | GT | GTE | LT | LTE | NE ) add_expression )*
;
add_expression : mult_expression ( ( PLUS | MINUS ) mult_expression )*
;
mult_expression : unary_expression ( ( MULT | DIVIDE | MOD ) unary_expression )*
;
unary_expression : MINUS cast_atom
| NOT cast_atom
| cast_atom
;
cast_atom : dot_atom ( ( AS | IS ) type )?
;
dot_atom : array_atom ( DOT array_func_or_id )*
| constant
;
array_atom : atom ( LBRACKET expression RBRACKET )
| atom
;
atom : LPAREN expression RPAREN
| new_expr
| func_or_id
;
new_expr : NEW BASETYPE LBRACKET expression RBRACKET
| NEW ID ( LBRACKET expression RBRACKET )?
;
array_func_or_id : function_call LBRACKET expression RBRACKET
| ID LBRACKET expression RBRACKET
| func_or_id
;
func_or_id : function_call
| ID
| LENGTH
;
return_stat : RETURN expression? terminator
;
ifBlock : IF expression terminator statement* elseIfBlock* elseBlock? ENDIF terminator
;
elseIfBlock : ELSEIF expression terminator statement*
;
elseBlock : ELSE terminator statement*
;
whileBlock : WHILE expression terminator statement* ENDWHILE terminator
;
function_call : ID LPAREN parameters? RPAREN
;
parameters : parameter ( COMMA parameter )*
;
parameter : ( ID EQUALS )? expression
;
constant : MINUS? number
| STRING
| BOOL
| NONE
;
number : INTEGER
| FLOAT
;
type : ID
| ID LBRACKET RBRACKET
| BASETYPE
| BASETYPE LBRACKET RBRACKET
;
terminator : WS? EOL*
;