Skip to content

Commit 0fd139a

Browse files
committed
Merge pull request #1120 from autoboosh/macrofix
fix macro rules and some other whitespace issues (#1119)
2 parents 2aeb70a + 6c4a687 commit 0fd139a

File tree

3 files changed

+3887
-3897
lines changed

3 files changed

+3887
-3897
lines changed

Rubberduck.Parsing/Grammar/VBA.g4

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
* 1. Preprocessor statements (#if, #else, ...) must not interfere with regular
4040
* statements.
4141
*
42-
* 2. Comments are skipped.
43-
*
44-
*
4542
* Change log:
4643
*
4744
* v1.4 Rubberduck
@@ -75,6 +72,8 @@
7572
* - optional parameters can be a valueStmt.
7673
* - added support for Octal and Currency literals.
7774
* - implemented proper specs for DATELITERAL.
75+
* - added comments to parse tree (removes known limitation #2).
76+
* - macroConstStmt now allowed in blockStmt.
7877
*
7978
*======================================================================================
8079
*
@@ -98,13 +97,14 @@ grammar VBA;
9897
startRule : module EOF;
9998

10099
module :
100+
WS?
101101
endOfLine*
102102
(moduleHeader endOfLine*)?
103103
moduleConfig? endOfLine*
104104
moduleAttributes? endOfLine*
105105
moduleDeclarations? endOfLine*
106106
moduleBody? endOfLine*
107-
endOfLine*
107+
WS?
108108
;
109109

110110
moduleHeader : VERSION WS DOUBLELITERAL WS CLASS;
@@ -124,10 +124,10 @@ moduleAttributes : (attributeStmt endOfLine+)+;
124124
moduleDeclarations : moduleDeclarationsElement (endOfLine+ moduleDeclarationsElement)*;
125125

126126
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
131131
;
132132

133133
moduleDeclarationsElement :
@@ -138,23 +138,23 @@ moduleDeclarationsElement :
138138
| constStmt
139139
| implementsStmt
140140
| variableStmt
141-
| macroConstStmt
142-
| macroIfThenElseStmt
143141
| moduleOption
144142
| typeStmt
143+
| macroConstStmt
144+
| macroIfThenElseStmt
145145
;
146146

147147
moduleBody :
148-
moduleBodyElement (endOfStatement moduleBodyElement)* endOfStatement;
148+
moduleBodyElement (endOfLine+ moduleBodyElement)*;
149149

150150
moduleBodyElement :
151151
functionStmt
152-
| macroIfThenElseStmt
153-
| macroConstStmt
154152
| propertyGetStmt
155153
| propertySetStmt
156154
| propertyLetStmt
157155
| subStmt
156+
| macroConstStmt
157+
| macroIfThenElseStmt
158158
;
159159

160160

@@ -197,6 +197,7 @@ blockStmt :
197197
| loadStmt
198198
| lockStmt
199199
| lsetStmt
200+
| macroConstStmt
200201
| macroIfThenElseStmt
201202
| midStmt
202203
| mkdirStmt
@@ -368,17 +369,17 @@ macroIfThenElseStmt : macroIfBlockStmt macroElseIfBlockStmt* macroElseBlockStmt?
368369

369370
macroIfBlockStmt :
370371
MACRO_IF WS? ifConditionStmt WS THEN endOfStatement
371-
((moduleDeclarationsElement | moduleBody | block) endOfStatement)*
372+
(moduleDeclarations | moduleBody | block)*
372373
;
373374

374375
macroElseIfBlockStmt :
375376
MACRO_ELSEIF WS? ifConditionStmt WS THEN endOfStatement
376-
((moduleDeclarationsElement | moduleBody | block) endOfStatement)*
377+
(moduleDeclarations | moduleBody | block)*
377378
;
378379

379380
macroElseBlockStmt :
380381
MACRO_ELSE endOfStatement
381-
((moduleDeclarationsElement | moduleBody | block) endOfStatement)*
382+
(moduleDeclarations | moduleBody | block)*
382383
;
383384

384385
midStmt : MID WS? LPAREN WS? argsCall WS? RPAREN;
@@ -809,11 +810,11 @@ LOCK_READ : L O C K WS R E A D;
809810
LOCK_WRITE : L O C K WS W R I T E;
810811
LOCK_READ_WRITE : L O C K WS R E A D WS W R I T E;
811812
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;
817818
ME : M E;
818819
MID : M I D;
819820
MKDIR : M K D I R;
@@ -829,9 +830,9 @@ ON_ERROR : O N WS E R R O R;
829830
ON_LOCAL_ERROR : O N WS L O C A L WS E R R O R;
830831
OPEN : O P E N;
831832
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;
833834
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;
835836
OPTION_PRIVATE_MODULE : O P T I O N WS P R I V A T E WS M O D U L E;
836837
OR : O R;
837838
OUTPUT : O U T P U T;
@@ -981,4 +982,4 @@ fragment V:('v'|'V');
981982
fragment W:('w'|'W');
982983
fragment X:('x'|'X');
983984
fragment Y:('y'|'Y');
984-
fragment Z:('z'|'Z');
985+
fragment Z:('z'|'Z');

0 commit comments

Comments
 (0)