Skip to content

Commit 586e294

Browse files
committed
Made the grammar error tolerant
1 parent c85fdcf commit 586e294

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

server/src/antlr/vba.g4

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,24 @@
9393

9494
grammar vba;
9595

96-
options { caseInsensitive = true; }
96+
// options { caseInsensitive = true; }
9797

9898
// module ----------------------------------
9999

100100
startRule : module EOF;
101101

102102
module :
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

117115
moduleConfig :
118116
BEGIN endOfLine*
@@ -146,6 +144,7 @@ moduleDeclarationsElement :
146144
| moduleOption
147145
| typeStmt
148146
| macroStmt
147+
| unknownLine
149148
;
150149

151150
macroStmt :
@@ -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

721719
endOfStatement : (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
959964
IDENTIFIER : ~[\]()\r\n\t.,'"|!@#$%^&*\-+:=; ]+ | L_SQUARE_BRACKET (~[!\]\r\n])+ R_SQUARE_BRACKET;
960-
EW : (.* LINE_CONTINUATION)*? WS;
961-
962965
963966
// letters
964967
fragment LETTER : [A-Z_\p{L}];
965968
fragment DIGIT : [0-9];
966969
fragment LETTERORDIGIT : [A-Z0-9_\p{L}];
970+
971+
NWS : . ;

0 commit comments

Comments
 (0)