File tree Expand file tree Collapse file tree 3 files changed +16
-11
lines changed
java/com/alibaba/qlexpress4/aparser
test/java/com/alibaba/qlexpress4 Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ lexer grammar QLexer;
1515 }
1616
1717 protected void consumeSelectorVariable() { }
18+
19+ protected void throwScannerException(String lexeme, String reason) { }
1820}
1921
2022// lexer
@@ -372,7 +374,7 @@ SELECTOR_START: ('${' | '$[' | '#{' | '#[') {
372374 if (getSelectorStart().equals(getText())) {
373375 pushMode(SelectorVariable);
374376 } else {
375- setType(CATCH_ALL );
377+ throwScannerException(getText(), " invalid selector start, expect ' " + getSelectorStart() + " ' " );
376378 }
377379};
378380
Original file line number Diff line number Diff line change @@ -46,13 +46,7 @@ protected void consumeSelectorVariable() {
4646 int curChInt = _input .LA (1 );
4747 if (curChInt == Token .EOF || curChInt == '\n' ) {
4848 // mismatch
49- throw QLException .reportScannerErr (script ,
50- this ._tokenStartCharIndex ,
51- this ._tokenStartLine ,
52- this ._tokenStartCharPositionInLine ,
53- t .toString (),
54- QLErrorCodes .SYNTAX_ERROR .name (),
55- "unterminated selector" );
49+ throwScannerException (t .toString (), "unterminated selector" );
5650 }
5751 char curCh = (char )curChInt ;
5852 t .append (curCh );
@@ -70,6 +64,17 @@ protected void consumeSelectorVariable() {
7064 }
7165 }
7266
67+ @ Override
68+ protected void throwScannerException (String lexeme , String reason ) {
69+ throw QLException .reportScannerErr (script ,
70+ this ._tokenStartCharIndex ,
71+ this ._tokenStartLine ,
72+ this ._tokenStartCharPositionInLine ,
73+ lexeme ,
74+ QLErrorCodes .SYNTAX_ERROR .name (),
75+ reason );
76+ }
77+
7378 private boolean checkEndsWith (StringBuilder sb , String suffix ) {
7479 int suffixLength = suffix .length ();
7580 int sbLength = sb .length ();
Original file line number Diff line number Diff line change @@ -1140,10 +1140,8 @@ public void customSelectorWhenNoCloseTest() {
11401140 Express4Runner express4Runner =
11411141 new Express4Runner (InitOptions .builder ().selectorStart ("#[" ).selectorEnd ("]" ).build ());
11421142
1143- Map <String , Object > context = new HashMap <>();
1144- context .put ("0" , "World" );
1145-
11461143 assertErrorCode (express4Runner , "'Hello ' + #[0grg" , QLErrorCodes .SYNTAX_ERROR .name ());
1144+ assertErrorCode (express4Runner , "'Hello ' + ${pl}" , QLErrorCodes .SYNTAX_ERROR .name ());
11471145 }
11481146
11491147 private void assertResultEquals (Express4Runner express4Runner , String script , Object expect ) {
You can’t perform that action at this time.
0 commit comments