forked from mvz/vb2py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbgrammar.txt
720 lines (524 loc) · 19.1 KB
/
vbgrammar.txt
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
#@+leo-ver=5-thin
#@+node:pap.120703001453.161: * @file vbgrammar.txt
#@+others
#@+node:pap.120703001453.162: ** Basic building blocks
#@+node:pap.120703001453.163: *3* Basic elements
identifier ::=
(safe_letter/("_", safe_letter)), (safe_letter / digit / "_")*, type_marker?
type_marker ::=
"$" / "%" / "#" / "&"
NEWLINE ::=
"\n"
<wsp> ::=
(" "/"\t")
# Also includes the hack for a unicode marker
<safe_letter> ::=
letter / '~~'
<letter> ::=
lowercase / uppercase
lowercase ::=
[a-z]
uppercase ::=
[A-Z]
<digit> ::=
[0-9]
stringliteral ::=
'"', stringitem*, '"'
<stringitem> ::=
stringchar / escapeseq / '""'
stringchar ::= -('"' / NEWLINE)+
dateliteral ::=
"#", integer, "/", integer, ("/", integer)?, "#"
escapeseq ::=
"\\", stringchar
longinteger ::=
integer, ("l" / "L")
integer ::=
"-"?, decimalinteger, ("%" / "&")?
decimalinteger ::=
digit+
octinteger ::=
"0", octdigit+
hexinteger ::=
"&H", hexdigit+, "&"?
<nonzerodigit> ::=
[1-9]
<octdigit> ::=
[0-7]
<hexdigit> ::=
digit / [a-f] / [A-F]
floatnumber ::=
("-"?, (exponentfloat / pointfloat)) / (integer, "#")
<pointfloat> ::=
(intpart?, fraction) / (intpart, ".")
<exponentfloat> ::=
(pointfloat / intpart),
exponent
<intpart> ::=
digit+
<fraction> ::=
".", digit+
<exponent> ::=
("e" / "E"), ("+" / "-")?, digit+
atom ::=
object / literal
literal ::=
dateliteral / stringliteral / floatnumber / integer / longinteger / hexinteger
name ::=
identifier
colon ::=
wsp*, ":", wsp*
hash ::=
"#"
#@+node:pap.120703001453.164: *3* Blocks and lines
block ::=
block_content+
block_content ::=
?-block_terminator, line
# The inline_if_statement appears here and also as a statement because sometimes the
# implicit_call_statement in the inline_if consumes the line_end - presumably there is a way
# to prevent this and simplify what is going on here!
line ::=
(?-label_definition, line_body) / (label_definition, line_body?)
line_body ::=
(explicit_call_statement / implicit_call_statement / ((compound_statement / single_statement), (line_end / (colon, line_end?))) / inline_if_statement)
line_end ::=
comment_statement?, NEWLINE
compound_line ::=
block
file ::=
block+
block_terminator ::=
(end_terminator / c"Else" / c"ElseIf" / c"Case" / c"Next"), (wsp+ / line_end)
end_terminator ::=
(c"End", wsp+, (c"If" / c"Function" / c"Subroutine")) / "END"
#@+node:pap.120703001453.165: *3* Statements
statement ::=
multi_statement_line / single_statement
single_statement ::=
(
comment_statement /
external_declaration /
open_statement /
on_statement /
print_statement /
get_statement /
input_statement /
line_input_statement /
put_statement /
call_statement /
inline_if_statement /
const_statement /
dim_statement /
inline_for_statement /
redim_statement /
exit_statement /
set_statement /
assignment_statement /
lset_statement /
rset_statement /
label_statement /
goto_statement /
resume_statement /
name_statement /
non_vb_statement /
option_statement /
event_definition /
close_statement /
end_statement /
seek_statement
)
compound_statement ::=
for_statement /
for_each_statement /
select_statement /
while_statement /
do_statement /
if_statement /
sub_definition /
fn_definition /
with_statement /
user_type_definition /
enumeration_definition /
property_definition /
non_vb_block
multi_statement_line ::=
((single_statement, colon) / label_statement), (wsp+, (compound_statement / statement))?
#@+node:pap.120703001453.166: *3* Keywords
keyword ::=
normal_keyword / block_terminator
# NB: 'BEGIN' is case sensitive because it is not a VB keyword
normal_keyword ::=
(
c"Function" / c"Sub" / c"Do" / c"While" / c"Wend" / c"Loop" / c"For" / c"Next" / c"Exit" /
c"If" / c"Select" / c"Type" / c"Set" / c"ReDim" / c"Dim" / c"Print" / c"Open" / c"With" /
c"Enum" / c"Property" / c"Input" / c"Close" / c"Then" / c"Else" / c"Resume" / c"To" /
c"Public" / c"Private" / c"Static" / c"Attribute" / c"Const" / c"Option" / c"End" /
"Event" / c"Seek" / "BEGIN" / c"Rem" / c"Let" / c"Reset" / c"LSet" / c"RSet"
), (wsp / line_end)
#@+node:pap.120703001453.167: *3* Expressions
expression ::=
(pre_named_argument?, passing_semantics?, pre_operator?, sign?, par_expression,
(operation, par_expression)*) / line_expression
par_expression ::=
point / (l_bracket, expression, r_bracket) / base_expression
base_expression ::=
simple_expr, (operation, simple_expr)?
simple_expr ::=
pre_operator?, wsp*, (sign, wsp*)*, (call / atom / channelid), wsp*
l_bracket ::=
wsp*, "(", wsp*
r_bracket ::=
wsp*, ")", wsp*
operation ::=
"+" / "-" / "*" / "/" / "^" / "&&" / "&" / "||" / "\\" / c"Not" / c"Mod" / compare
compare ::=
c"Or" / c"And" / c"Xor" / "=" / "<=" / ">=" / "<>" / "<" / ">" / c"Is" / c"Like"
sign ::=
"-" / "+"
pre_named_argument ::=
wsp*, named_argument, ":=", wsp*
named_argument ::=
identifier
pre_operator ::=
pre_not / pre_typeof
pre_not ::=
wsp*, c"Not", wsp+
pre_typeof ::=
wsp*, c"TypeOf", wsp+
channelid ::=
"#", atom
#@+node:pap.120703001453.168: *3* Line (connecting points)
line_expression ::=
point, wsp*, "-", wsp*, point
point ::=
(l_bracket, expression, wsp*, ",", wsp*, expression, r_bracket)
#@+node:pap.120703001453.169: *3* Single statements
#@+node:pap.120703001453.170: *4* Assigment
assignment_statement ::=
(c"Let", wsp+)?, assignment_body
assignment_body ::=
object, wsp*, "=", wsp*, expression
set_statement ::=
c"Set", wsp+, object, wsp*, "=", new_keyword?, expression
new_keyword ::=
wsp?, c"New", wsp+
object ::=
?-keyword, implicit_object?, (primary, ((".", attribute) / parameter_list)*)
bare_object ::=
?-keyword, implicit_object?, primary, (".", attribute)*
qualified_object ::=
bare_object, parameter_list
implicit_object ::=
"."
primary ::=
identifier
attribute ::=
"["?, identifier, "]"?
lset_statement ::=
c"LSet", wsp+, assignment_body
rset_statement ::=
c"RSet", wsp+, assignment_body
#@+node:pap.120703001453.171: *4* Comment
comment_statement ::=
wsp*, comment_start, (vb2py_directive / comment_body)
comment_body ::=
(stringitem / '"')*
comment_start ::=
"'" / c"Rem"
#@+node:pap.120703001453.172: *4* External libraries
external_declaration ::=
(scope, wsp+)?, c"Declare", wsp+, (c"Sub" / c"Function"), wsp+, identifier, wsp+, c"Lib", wsp+,
stringliteral, wsp+, (c"Alias", wsp+, stringliteral, wsp+)?, formal_param_list, type_definition?
#@+node:pap.120703001453.173: *4* Labels and GoTo
label_definition ::=
label_statement, (wsp+ / line_end)
label_statement ::=
(label, ":") / decimalinteger
label ::=
(identifier / decimalinteger)
goto_statement ::=
c"GoTo", wsp+, label
#@+node:pap.120703001453.174: *4* Dim
dim_statement ::=
unscoped_dim / scoped_dim
unscoped_dim ::=
c"Dim", wsp+, basic_dim
scoped_dim ::=
scope, wsp+, (c"Dim", wsp+)?, basic_dim
basic_dim ::=
object_definition, (",", wsp*, object_definition)*
object_definition ::=
with_events?, bare_object, (unsized_definition / size_definition)?, type_definition?
const_statement ::=
(scope, wsp+)?, c"Const", wsp+, const_definition, (",", wsp*, const_definition)*
const_definition ::=
identifier, type_definition?, wsp*, "=", wsp*, expression
type_definition ::=
(wsp+, c"As", wsp+, new_keyword?, type, array_indicator?, string_size_definition?, wsp*)
unsized_definition ::=
"(", wsp*, ")"
size_definition ::=
"(", (size_range / size)?, (",", wsp*, (size_range / size))*, ")"
size ::=
expression
size_range ::=
size, wsp*, c"To", wsp*, size
type ::=
primary, (".", attribute)*
scope ::=
c"Global" / c"Private" / c"Public" / c"Static" / c"Friend"
value ::=
literal
redim_statement ::=
c"ReDim", wsp+, preserve_keyword?, basic_dim
preserve_keyword ::=
c"Preserve", wsp+
array_indicator ::=
wsp*, "()"
string_size_definition ::=
wsp*, "*", wsp*, string_size_indicator
string_size_indicator ::=
atom
with_events ::=
wsp*, c"WithEvents", wsp+
#@+node:pap.120703001453.175: *4* On Error Goto
on_statement ::=
(on_error_goto / on_error_resume / on_goto)
on_error_goto ::=
on_error, c"GoTo", wsp+, label
on_error_resume ::=
on_error, c"Resume", wsp+, c"Next"
on_goto ::=
on_variable, c"GoTo", wsp+, bare_list
on_error ::=
label_definition?, c"On", wsp+, local?, c"Error", wsp+
on_variable ::=
label_definition?, c"On", wsp+, expression
local ::=
c"Local", wsp+
#@+node:pap.120703001453.176: *4* Print / Get
print_statement ::=
label_statement?, c"Print", (wsp+, channel_id, wsp*, ",", wsp*)?, print_list?
channel_id ::=
"#", expression
hold_cr ::=
";"
get_statement ::=
label_statement?, c"Get", wsp+, channel_id, wsp*, bare_list
input_statement ::=
label_statement?, c"Input", wsp+, channel_id, wsp*, bare_list
line_input_statement ::=
label_statement?, c"Line", wsp+, input_statement
put_statement ::=
label_statement?, c"Put", wsp+, channel_id, wsp*, bare_list, hold_cr?
print_list ::=
wsp*, print_separator*, (expression, wsp*, print_separator*, wsp*)*
print_separator ::=
"," / ";"
#@+node:pap.120703001453.177: *4* Seek
seek_statement ::=
label_statement?, c"Seek", wsp+, channel_id, wsp*, ",", wsp*, expression
#@+node:pap.120703001453.178: *4* Open/Close
open_statement ::=
label_definition?, c"Open", wsp+, filename, c"For", wsp+, open_mode+, c"As", wsp+, "#"?, channel,
(wsp*, c"Len", wsp*, "=", wsp*, access_length)?
filename ::=
expression
channel ::=
expression
access_length ::=
expression
open_mode ::=
?-c"As", identifier, wsp+
close_statement ::=
label_definition?, (c"Close" / c"Reset"), (wsp+, channel_number, (",", wsp*, channel_number)*)?
channel_number ::=
(channel_id / expression)
#@+node:pap.120703001453.179: *4* Calls
call_statement ::=
label_definition?, (c"Call", wsp+, object, list?)
implicit_call_statement ::=
label_definition?, ?-keyword, (simple_expr, bare_list, (line_end / colon))
explicit_call_statement ::=
label_definition?, ?-keyword, (qualified_object, (line_end / colon))
inline_implicit_call ::=
label_definition?, ?-keyword, (simple_expr, bare_list)
list ::=
"(", bare_list, ")"
bare_list ::=
# (wsp*, bare_list_item?, (list_separator, wsp*, bare_list_item?)*)?
(wsp*, positional_item*, bare_list_item?)
call ::=
?-keyword, object, parameter_list?
positional_item ::=
(bare_list_item / missing_positional), list_separator
missing_positional ::=
wsp*
bare_list_item ::=
addressof?, expression
addressof ::=
c"AddressOf", wsp+
list_separator ::=
"," / ";"
#@+node:pap.120703001453.180: *4* Resume statement
resume_statement ::=
label_definition?, c"Resume", (wsp+, resume_location)?
resume_location ::=
c"Next" / label
#@+node:pap.120703001453.181: *4* Exit statement
exit_statement ::=
c"Exit", wsp+, (c"Sub" / c"Function" / c"For" / c"Do" / c"Loop" / c"Property")
#@+node:pap.120703001453.182: *4* Name statement
name_statement ::=
label_definition?, c"Name", wsp+, expression, c"As", expression
#@+node:pap.120703001453.183: *4* End statement
end_statement ::=
c"End"
#@+node:pap.120703001453.184: *4* Event definition
event_definition ::=
label_statement?, (scope, wsp+)?, c"Event", wsp+, object, formal_param_list?
#@+node:pap.120703001453.185: ** Compound statements
#@+node:pap.120703001453.186: *3* Do/While etc
while_statement ::=
c"While", wsp+, expression, line_end, block, label_definition?, (c"End While" / c"Wend")
do_statement ::=
c"Do", (while_clause / until_clause)?, line_end, block,
label_definition?, c"Loop", (post_until_clause / post_while_clause)?
while_clause ::=
(wsp+, c"While", wsp+, expression)
until_clause ::=
(wsp+, c"Until", wsp+, expression)
post_until_clause ::=
until_clause
post_while_clause ::=
while_clause
#@+node:pap.120703001453.187: *3* Select case
select_statement ::=
c"Select", wsp+, c"Case", wsp+, expression, line_end,
case_comment_block?,
case_item_block*,
case_else_block?,
label_definition?, c"End Select"
case_item_block ::=
label_definition?, c"Case", wsp+, case_list, case_body
case_else_block ::=
label_definition?, c"Case", wsp+, c"Else", case_body
case_body ::=
(colon, line_end, block?) / ((line_end / colon), block?)
case_list ::=
?-c"Else", (case_expression, (",", case_expression)*)?
case_expression ::=
expression, (to_keyword, expression)?
to_keyword ::=
c"To"
case_comment_block ::=
block
#@+node:pap.120703001453.188: *3* If
inline_if_statement ::=
label_definition?, hash?, c"If", condition, hash?, c"Then", wsp+, inline_if_block,
(wsp*, hash?, c"Else", wsp+, inline_else_block)?
if_statement ::=
hash?, c"If", condition, hash?, c"Then", line_end, if_block?,
else_if_statement*,
else_statement?,
label_definition?, hash?, c"End If"
if_block ::=
block
else_if_statement ::=
(label_definition?, hash?, c"ElseIf", condition, hash?, c"Then", line_end, else_if_block?)
else_statement ::=
(label_definition?, hash?, c"Else", wsp*, line_end, else_block?)
else_block ::= block
else_if_block ::= block
condition ::= expression
inline_if_block ::=
?-comment_statement, inline_block
inline_else_block ::=
inline_block
inline_block ::=
(statement / inline_implicit_call)
#@+node:pap.120703001453.189: *3* For and for each
for_statement ::=
c"For", wsp+, object, wsp*, "=", wsp*,
expression, c"To", wsp+, expression, for_stepping?, line_end,
block?,
label_definition?, c"Next", (wsp+, object)?
for_stepping ::=
c"Step", expression
for_each_statement ::=
c"For", wsp+, c"Each", wsp+, object, wsp*, c"In", wsp+,
expression, line_end,
block?,
label_definition?, c"Next", (wsp+, object)?
inline_for_statement ::=
c"For", wsp+, object, wsp*, "=", wsp*,
expression, c"To", wsp+, expression, for_stepping?,
colon, body, c"Next", (wsp+, object)?
body ::=
(implicit_call_statement / (single_statement, colon))*
#@+node:pap.120703001453.190: *3* Subs and functions
sub_definition ::=
label_definition?, (scope, wsp*)?, (static, wsp*)?, c"Sub", wsp+, identifier, wsp*,
formal_param_list, line_end, block?, label_definition?, c"End Sub"
formal_param_list ::=
"(", wsp*, formal_param?, (wsp*, ",", wsp*, formal_param)*, ")"
formal_param ::=
optional?, passing_semantics?, (object / identifier), array_indicator?, type_definition?, default_value?
optional ::=
c"Optional", wsp+
passing_semantics ::=
(c"ByVal" / c"ByRef"), wsp+
parameter_list ::=
list
fn_definition ::=
label_definition?, (scope, wsp*)?, c"Function", wsp+, identifier, wsp*,
formal_param_list, type_definition?, line_end, block?, label_definition?, c"End Function"
default_value ::=
wsp*, "=", expression
static ::=
"Static"
#@+node:pap.120703001453.191: *3* Properties
property_definition ::=
label_definition?, (scope, wsp*)?, c"Property", wsp+, property_decorator_type, wsp+, identifier,
formal_param_list, type_definition?, line_end, block?, label_definition?, c"End Property"
property_decorator_type ::=
c"Get" / c"Set" / c"Let"
#@+node:pap.120703001453.192: *3* User Types
user_type_definition ::=
(scope, wsp+)?, c"Type", wsp+, identifier, line_end, ((object_definition / comment_statement), line_end)*, label_definition?, c"End Type"
#@+node:pap.120703001453.193: *3* With
with_statement ::=
label_definition?, c"With", wsp+, expression, line_end, block?, label_definition?, c"End With"
#@+node:pap.120703001453.194: *3* Enumerations
enumeration_definition ::=
(scope, wsp+)?, c"Enum", wsp, identifier, line_end, (enumeration_item, line_end)*, c"End Enum"
enumeration_item ::=
?-c"End", identifier, (wsp*, "=", wsp*, expression)?
#@+node:pap.120703001453.195: ** Non VB stuff
non_vb_statement ::=
class_header_statement / attribute_statement
non_vb_block ::=
class_header_block
#@+node:pap.120703001453.196: *3* Class file headers
class_header_statement ::=
c"VERSION", wsp+, floatnumber, wsp+, c"CLASS"
class_header_block ::=
"BEGIN", line_end, block, "END"
#@+node:pap.120703001453.197: *3* vb2py Directives
vb2py_directive ::=
wsp*, c"VB2PY-", directive_type, wsp*, ":", wsp*, directive_body
directive_type ::=
identifier
directive_body ::=
config_section, ".", config_name, wsp*, ("=", wsp*, expression)?
config_section ::= identifier
config_name ::= identifier
#@+node:pap.120703001453.198: *3* attribute statement
attribute_statement ::=
c"Attribute", wsp+, object, wsp*, "=", wsp*, expression, (wsp*, ",", wsp*, expression)*
#@+node:pap.120703001453.199: *3* option_statement
option_statement ::=
c"Option", wsp+, atom, (wsp*, atom)*, comment_statement?
#@-others
#@-leo