39
39
* 1. Preprocessor statements (#if, #else, ...) must not interfere with regular
40
40
* statements.
41
41
*
42
- * 2. Comments are skipped.
43
- *
44
- *
45
42
* Change log:
46
43
*
47
44
* v1.4 Rubberduck
75
72
* - optional parameters can be a valueStmt.
76
73
* - added support for Octal and Currency literals.
77
74
* - implemented proper specs for DATELITERAL.
75
+ * - added comments to parse tree (removes known limitation #2).
76
+ * - macroConstStmt now allowed in blockStmt.
78
77
*
79
78
*======================================================================================
80
79
*
@@ -98,13 +97,14 @@ grammar VBA;
98
97
startRule : module EOF ;
99
98
100
99
module :
100
+ WS ?
101
101
endOfLine*
102
102
(moduleHeader endOfLine*)?
103
103
moduleConfig? endOfLine*
104
104
moduleAttributes? endOfLine*
105
105
moduleDeclarations? endOfLine*
106
106
moduleBody? endOfLine*
107
- endOfLine*
107
+ WS ?
108
108
;
109
109
110
110
moduleHeader : VERSION WS DOUBLELITERAL WS CLASS ;
@@ -121,13 +121,13 @@ moduleConfigElement :
121
121
122
122
moduleAttributes : (attributeStmt endOfLine+)+;
123
123
124
- moduleDeclarations : moduleDeclarationsElement (endOfLine+ moduleDeclarationsElement)*;
124
+ moduleDeclarations : moduleDeclarationsElement (endOfLine+ moduleDeclarationsElement)* endOfLine* ;
125
125
126
126
moduleOption :
127
- OPTION_BASE WS ? SHORTLITERAL # optionBaseStmt
128
- | OPTION_COMPARE WS ? (BINARY | TEXT | DATABASE ) # optionCompareStmt
129
- | OPTION_EXPLICIT # optionExplicitStmt
130
- | OPTION_PRIVATE_MODULE # optionPrivateModuleStmt
127
+ OPTION_BASE WS SHORTLITERAL # optionBaseStmt
128
+ | OPTION_COMPARE WS (BINARY | TEXT | DATABASE ) # optionCompareStmt
129
+ | OPTION_EXPLICIT # optionExplicitStmt
130
+ | OPTION_PRIVATE_MODULE # optionPrivateModuleStmt
131
131
;
132
132
133
133
moduleDeclarationsElement :
@@ -138,23 +138,25 @@ moduleDeclarationsElement :
138
138
| constStmt
139
139
| implementsStmt
140
140
| variableStmt
141
- | macroConstStmt
142
- | macroIfThenElseStmt
143
141
| moduleOption
144
142
| typeStmt
143
+ | macroStmt
145
144
;
146
145
146
+ macroStmt :
147
+ macroConstStmt
148
+ | macroIfThenElseStmt;
149
+
147
150
moduleBody :
148
- moduleBodyElement (endOfStatement moduleBodyElement)* endOfStatement ;
151
+ moduleBodyElement (endOfLine+ moduleBodyElement)* endOfLine* ;
149
152
150
153
moduleBodyElement :
151
154
functionStmt
152
- | macroIfThenElseStmt
153
- | macroConstStmt
154
155
| propertyGetStmt
155
156
| propertySetStmt
156
157
| propertyLetStmt
157
158
| subStmt
159
+ | macroStmt
158
160
;
159
161
160
162
@@ -197,7 +199,7 @@ blockStmt :
197
199
| loadStmt
198
200
| lockStmt
199
201
| lsetStmt
200
- | macroIfThenElseStmt
202
+ | macroStmt
201
203
| midStmt
202
204
| mkdirStmt
203
205
| nameStmt
@@ -368,17 +370,17 @@ macroIfThenElseStmt : macroIfBlockStmt macroElseIfBlockStmt* macroElseBlockStmt?
368
370
369
371
macroIfBlockStmt :
370
372
MACRO_IF WS ? ifConditionStmt WS THEN endOfStatement
371
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
373
+ (moduleDeclarations | moduleBody | block)*
372
374
;
373
375
374
376
macroElseIfBlockStmt :
375
377
MACRO_ELSEIF WS ? ifConditionStmt WS THEN endOfStatement
376
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
378
+ (moduleDeclarations | moduleBody | block)*
377
379
;
378
380
379
381
macroElseBlockStmt :
380
382
MACRO_ELSE endOfStatement
381
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
383
+ (moduleDeclarations | moduleBody | block)*
382
384
;
383
385
384
386
midStmt : MID WS ? LPAREN WS ? argsCall WS ? RPAREN ;
@@ -809,11 +811,11 @@ LOCK_READ : L O C K WS R E A D;
809
811
LOCK_WRITE : L O C K WS W R I T E ;
810
812
LOCK_READ_WRITE : L O C K WS R E A D WS W R I T E ;
811
813
LSET : L S E T ;
812
- MACRO_CONST : ' #' C O N S T WS ;
813
- MACRO_IF : ' #' I F WS ;
814
- MACRO_ELSEIF : ' #' E L S E I F WS ;
815
- MACRO_ELSE : ' #' E L S E NEWLINE ;
816
- MACRO_END_IF : ' #' E N D WS I F NEWLINE ;
814
+ MACRO_CONST : ' #' C O N S T ;
815
+ MACRO_IF : ' #' I F ;
816
+ MACRO_ELSEIF : ' #' E L S E I F ;
817
+ MACRO_ELSE : ' #' E L S E ;
818
+ MACRO_END_IF : ' #' E N D WS ? I F ;
817
819
ME : M E ;
818
820
MID : M I D ;
819
821
MKDIR : M K D I R ;
@@ -829,9 +831,9 @@ ON_ERROR : O N WS E R R O R;
829
831
ON_LOCAL_ERROR : O N WS L O C A L WS E R R O R ;
830
832
OPEN : O P E N ;
831
833
OPTIONAL : O P T I O N A L ;
832
- OPTION_BASE : O P T I O N WS B A S E WS ;
834
+ OPTION_BASE : O P T I O N WS B A S E ;
833
835
OPTION_EXPLICIT : O P T I O N WS E X P L I C I T ;
834
- OPTION_COMPARE : O P T I O N WS C O M P A R E WS ;
836
+ OPTION_COMPARE : O P T I O N WS C O M P A R E ;
835
837
OPTION_PRIVATE_MODULE : O P T I O N WS P R I V A T E WS M O D U L E ;
836
838
OR : O R ;
837
839
OUTPUT : O U T P U T ;
@@ -981,4 +983,4 @@ fragment V:('v'|'V');
981
983
fragment W:(' w' |' W ' );
982
984
fragment X:(' x' |' X ' );
983
985
fragment Y:(' y' |' Y ' );
984
- fragment Z:(' z' |' Z ' );
986
+ fragment Z:(' z' |' Z ' );
0 commit comments