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 ;
@@ -124,10 +124,10 @@ moduleAttributes : (attributeStmt endOfLine+)+;
124
124
moduleDeclarations : moduleDeclarationsElement (endOfLine+ moduleDeclarationsElement)*;
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,23 @@ moduleDeclarationsElement :
138
138
| constStmt
139
139
| implementsStmt
140
140
| variableStmt
141
- | macroConstStmt
142
- | macroIfThenElseStmt
143
141
| moduleOption
144
142
| typeStmt
143
+ | macroConstStmt
144
+ | macroIfThenElseStmt
145
145
;
146
146
147
147
moduleBody :
148
- moduleBodyElement (endOfStatement moduleBodyElement)* endOfStatement ;
148
+ moduleBodyElement (endOfLine+ moduleBodyElement)*;
149
149
150
150
moduleBodyElement :
151
151
functionStmt
152
- | macroIfThenElseStmt
153
- | macroConstStmt
154
152
| propertyGetStmt
155
153
| propertySetStmt
156
154
| propertyLetStmt
157
155
| subStmt
156
+ | macroConstStmt
157
+ | macroIfThenElseStmt
158
158
;
159
159
160
160
@@ -197,6 +197,7 @@ blockStmt :
197
197
| loadStmt
198
198
| lockStmt
199
199
| lsetStmt
200
+ | macroConstStmt
200
201
| macroIfThenElseStmt
201
202
| midStmt
202
203
| mkdirStmt
@@ -368,17 +369,17 @@ macroIfThenElseStmt : macroIfBlockStmt macroElseIfBlockStmt* macroElseBlockStmt?
368
369
369
370
macroIfBlockStmt :
370
371
MACRO_IF WS ? ifConditionStmt WS THEN endOfStatement
371
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
372
+ (moduleDeclarations | moduleBody | block)*
372
373
;
373
374
374
375
macroElseIfBlockStmt :
375
376
MACRO_ELSEIF WS ? ifConditionStmt WS THEN endOfStatement
376
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
377
+ (moduleDeclarations | moduleBody | block)*
377
378
;
378
379
379
380
macroElseBlockStmt :
380
381
MACRO_ELSE endOfStatement
381
- ((moduleDeclarationsElement | moduleBody | block) endOfStatement )*
382
+ (moduleDeclarations | moduleBody | block)*
382
383
;
383
384
384
385
midStmt : MID WS ? LPAREN WS ? argsCall WS ? RPAREN ;
@@ -809,11 +810,11 @@ LOCK_READ : L O C K WS R E A D;
809
810
LOCK_WRITE : L O C K WS W R I T E ;
810
811
LOCK_READ_WRITE : L O C K WS R E A D WS W R I T E ;
811
812
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 ;
813
+ MACRO_CONST : ' #' C O N S T ;
814
+ MACRO_IF : ' #' I F ;
815
+ MACRO_ELSEIF : ' #' E L S E I F ;
816
+ MACRO_ELSE : ' #' E L S E ;
817
+ MACRO_END_IF : ' #' E N D WS ? I F ;
817
818
ME : M E ;
818
819
MID : M I D ;
819
820
MKDIR : M K D I R ;
@@ -829,9 +830,9 @@ ON_ERROR : O N WS E R R O R;
829
830
ON_LOCAL_ERROR : O N WS L O C A L WS E R R O R ;
830
831
OPEN : O P E N ;
831
832
OPTIONAL : O P T I O N A L ;
832
- OPTION_BASE : O P T I O N WS B A S E WS ;
833
+ OPTION_BASE : O P T I O N WS B A S E ;
833
834
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 ;
835
+ OPTION_COMPARE : O P T I O N WS C O M P A R E ;
835
836
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
837
OR : O R ;
837
838
OUTPUT : O U T P U T ;
@@ -981,4 +982,4 @@ fragment V:('v'|'V');
981
982
fragment W:(' w' |' W ' );
982
983
fragment X:(' x' |' X ' );
983
984
fragment Y:(' y' |' Y ' );
984
- fragment Z:(' z' |' Z ' );
985
+ fragment Z:(' z' |' Z ' );
0 commit comments