9393
9494grammar vba;
9595
96- options { caseInsensitive = true ; }
96+ // options { caseInsensitive = true; }
9797
9898// module ----------------------------------
9999
100100startRule : module EOF ;
101101
102102module :
103103 WS ?
104- endOfLine*
105- (moduleHeader endOfLine* | errorWords )?
106- ( moduleConfig? endOfLine* | errorWords)
104+ ( endOfLine | unknownLine) *
105+ (moduleHeader endOfLine*)?
106+ moduleConfig? endOfLine*
107107 moduleAttributes? endOfLine*
108108 moduleDeclarations? endOfLine*
109109 moduleBody? endOfLine*
110110 WS ?
111111;
112112
113- errorWords : EW ;
114-
115- moduleHeader : errorWords? VERSION WS DOUBLELITERAL WS CLASS ;
113+ moduleHeader : VERSION WS DOUBLELITERAL WS CLASS ;
116114
117115moduleConfig :
118116 BEGIN endOfLine*
@@ -146,6 +144,7 @@ moduleDeclarationsElement :
146144 | moduleOption
147145 | typeStmt
148146 | macroStmt
147+ | unknownLine
149148;
150149
151150macroStmt :
@@ -162,7 +161,6 @@ moduleBodyElement :
162161 | propertyLetStmt
163162 | subStmt
164163 | macroStmt
165- | errorWords
166164;
167165
168166
@@ -241,7 +239,7 @@ blockStmt :
241239 | writeStmt
242240 | implicitCallStmt_InBlock
243241 | implicitCallStmt_InStmt
244- | errorWords
242+ | unknownLine
245243;
246244
247245
@@ -720,6 +718,13 @@ endOfLine : WS? (NEWLINE | comment | remComment) WS?;
720718
721719endOfStatement : (endOfLine | WS ? COLON WS ?)*;
722720
721+ unknownToken : (IDENTIFIER | NWS )+ ;
722+
723+ anyValidToken : (DIM | visibility | ambiguousIdentifier | AS | literal | baseType | complexType | ' !' | ' .' );
724+
725+ unknownLine : ((anyValidToken WS ?)* WS ? unknownToken WS ? (anyValidToken WS ?)*)+ ;
726+
727+
723728
724729// lexer rules --------------------------------------------------------------------------------
725730
@@ -957,10 +962,10 @@ WS : ([ \t] | LINE_CONTINUATION)+;
957962
958963// identifier
959964IDENTIFIER : ~[\]()\r\n\t.,' "|!@#$%^&*\- +:=; ]+ | L_SQUARE_BRACKET (~[!\]\r\n ])+ R_SQUARE_BRACKET;
960- EW : (.* LINE_CONTINUATION)*? WS;
961-
962965
963966// letters
964967fragment LETTER : [A-Z_\p {L}];
965968fragment DIGIT : [0-9];
966969fragment LETTERORDIGIT : [A-Z0-9_\p {L}];
970+
971+ NWS : . ;
0 commit comments