Skip to content

Commit eeb111b

Browse files
authored
fix: correct the grammar usage, especially in the parts targeting javascript (#109)
* build: ignore gen folder * fix: correct the grammar when targeting Typescript * fix: move base Lexer and fix javascript syntax * fix: correct the usage of Javascript in grammar
1 parent 9c82a5d commit eeb111b

23 files changed

Lines changed: 232 additions & 216 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ package-lock.json
66
dist/
77
src/**/.antlr
88
coverage
9-
.idea
9+
.idea
10+
gen/

src/grammar/pgsql/PostgreSQLLexer.g4

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ PARAM
178178

179179
Operator
180180
: ((OperatorCharacter | ('+' | '-'
181-
{checkLA('-')}?)+ (OperatorCharacter | '/'
182-
{checkLA('*')}?) | '/'
183-
{checkLA('*')}?)+ | // special handling for the single-character operators + and -
181+
{this.checkLA('-')}?)+ (OperatorCharacter | '/'
182+
{this.checkLA('*')}?) | '/'
183+
{this.checkLA('*')}?)+ | // special handling for the single-character operators + and -
184184
[+-])
185185
//TODO somehow rewrite this part without using Actions
186186

187187
{
188-
HandleLessLessGreaterGreater();
188+
this.HandleLessLessGreaterGreater();
189189
}
190190
;
191191
/* This rule handles operators which end with + or -, and sets the token type to Operator. It is comprised of four
@@ -202,9 +202,9 @@ Operator
202202

203203
OperatorEndingWithPlusMinus
204204
: (OperatorCharacterNotAllowPlusMinusAtEnd | '-'
205-
{checkLA('-')}? | '/'
206-
{checkLA('*')}?)* OperatorCharacterAllowPlusMinusAtEnd Operator? ('+' | '-'
207-
{checkLA('-')}?)+ -> type (Operator)
205+
{this.checkLA('-')}? | '/'
206+
{this.checkLA('*')}?)* OperatorCharacterAllowPlusMinusAtEnd Operator? ('+' | '-'
207+
{this.checkLA('-')}?)+ -> type (Operator)
208208
;
209209
// Each of the following fragment rules omits the +, -, and / characters, which must always be handled in a special way
210210

@@ -2200,11 +2200,11 @@ fragment IdentifierStartChar
22002200
[\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]
22012201
| // these are the letters above 0xFF which only need a single UTF-16 code unit
22022202
[\u0100-\uD7FF\uE000-\uFFFF]
2203-
{charIsLetter()}?
2203+
{this.charIsLetter()}?
22042204
| // letters which require multiple UTF-16 code units
22052205
[\uD800-\uDBFF] [\uDC00-\uDFFF]
22062206
{
2207-
CheckIfUtf32Letter()
2207+
this.CheckIfUtf32Letter()
22082208
}?
22092209

22102210
;
@@ -2315,7 +2315,7 @@ UnterminatedUnicodeEscapeStringConstant
23152315

23162316
BeginDollarStringConstant
23172317
: '$' Tag? '$'
2318-
{pushTag();} -> pushMode (DollarQuotedStringMode)
2318+
{this.pushTag();} -> pushMode (DollarQuotedStringMode)
23192319
;
23202320
/* "The tag, if any, of a dollar-quoted string follows the same rules as an
23212321
* unquoted identifier, except that it cannot contain a dollar sign."
@@ -2366,7 +2366,7 @@ Integral
23662366

23672367
NumericFail
23682368
: Digits '..'
2369-
{HandleNumericFail();}
2369+
{this.HandleNumericFail();}
23702370
;
23712371

23722372
Numeric
@@ -2424,7 +2424,7 @@ UnterminatedBlockComment
24242424
// Optional assertion to make sure this rule is working as intended
24252425
24262426
{
2427-
UnterminatedBlockCommentDebugAssert();
2427+
this.UnterminatedBlockCommentDebugAssert();
24282428
}
24292429
;
24302430
//
@@ -2538,7 +2538,6 @@ DollarText
25382538
25392539
EndDollarStringConstant
25402540
: ('$' Tag? '$')
2541-
{isTag()}?
2542-
{popTag();} -> popMode
2541+
{this.isTag()}?
2542+
{this.popTag();} -> popMode
25432543
;
2544-

src/grammar/pgsql/PostgreSQLParser.g4

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,10 +1957,8 @@ aggregate_with_argtypes_list
19571957
createfunc_opt_list
19581958
: createfunc_opt_item+
19591959
{
1960-
ParseRoutineBody(_localctx);
1961-
}
1962-
// | createfunc_opt_list createfunc_opt_item
1963-
1960+
this.ParseRoutineBody(localctx);
1961+
}
19641962
;
19651963

19661964
common_func_opt_item
@@ -4562,7 +4560,6 @@ from pl_gram.y, line ~2982
45624560
* at least we need not worry about it appearing as an identifier.
45634561
*/
45644562

4565-
45664563
// | INTO
45674564
| LATERAL_P
45684565
| LEADING
@@ -4606,7 +4603,8 @@ from pl_gram.y, line ~2982
46064603

46074604
/*PLSQL grammar */
46084605

4609-
/************************************************************************************************************************************************************/ pl_function
4606+
/************************************************************************************************************************************************************/
4607+
pl_function
46104608
: comp_options pl_block opt_semi
46114609
;
46124610

@@ -4925,7 +4923,6 @@ exit_type
49254923
: EXIT
49264924
| CONTINUE_P
49274925
;
4928-
//todo implement RETURN statement according to initial grammar line 1754
49294926

49304927
stmt_return
49314928
: RETURN (NEXT sql_expression | QUERY (EXECUTE a_expr opt_for_using_expression | selectstmt) | opt_return_result) SEMI
@@ -5324,4 +5321,3 @@ opt_returning_clause_into
53245321
: INTO opt_strict into_target
53255322
|
53265323
;
5327-

src/grammar/plsql/PlSqlLexer.g4

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ options {
2424
superClass=PlSqlBaseLexer;
2525
}
2626

27-
@lexer::postinclude {
28-
#include <PlSqlBaseLexer.h>
29-
}
30-
3127
ABORT: 'ABORT';
3228
ABS: 'ABS';
3329
ACCESS: 'ACCESS';
@@ -2342,17 +2338,17 @@ INTRODUCER: '_';
23422338
SINGLE_LINE_COMMENT: '--' ~('\r' | '\n')* NEWLINE_EOF -> channel(HIDDEN);
23432339
MULTI_LINE_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
23442340
// https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve034.htm#SQPUG054
2345-
REMARK_COMMENT: 'REM' {IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);
2341+
REMARK_COMMENT: 'REM' {this.IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);
23462342

23472343
// https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve032.htm#SQPUG052
2348-
PROMPT_MESSAGE: 'PRO' {IsNewlineAtPos(-4)}? 'MPT'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF;
2344+
PROMPT_MESSAGE: 'PRO' {this.IsNewlineAtPos(-4)}? 'MPT'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF;
23492345

23502346
// TODO: should starts with newline
23512347
START_CMD
23522348
//: 'STA' 'RT'? SPACE ~('\r' | '\n')* NEWLINE_EOF
23532349
// https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12002.htm
23542350
// https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12003.htm
2355-
: '@' {IsNewlineAtPos(-2)}? '@'? ~('\r' | '\n')* NEWLINE_EOF
2351+
: '@' {this.IsNewlineAtPos(-2)}? '@'? ~('\r' | '\n')* NEWLINE_EOF
23562352
;
23572353

23582354
REGULAR_ID: SIMPLE_LETTER (SIMPLE_LETTER | '$' | '_' | '#' | [0-9])*;
@@ -2366,4 +2362,4 @@ fragment QUESTION_MARK : '?';
23662362
fragment SIMPLE_LETTER : [A-Z];
23672363
fragment FLOAT_FRAGMENT : UNSIGNED_INTEGER* '.'? UNSIGNED_INTEGER+;
23682364
fragment NEWLINE : '\r'? '\n';
2369-
fragment SPACE : [ \t];
2365+
fragment SPACE : [ \t];

src/grammar/plsql/PlSqlParser.g4

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ options {
2525
superClass=PlSqlBaseParser;
2626
}
2727

28-
@parser::postinclude {
29-
#include <PlSqlBaseParser.h>
30-
}
31-
3228
program: sql_script EOF;
3329

3430
sql_script
@@ -2254,7 +2250,7 @@ partial_database_recovery
22542250
;
22552251

22562252
partial_database_recovery_10g
2257-
: {isVersion10()}? STANDBY
2253+
: {this.isVersion10()}? STANDBY
22582254
( TABLESPACE tablespace (',' tablespace)*
22592255
| DATAFILE CHAR_STRING | filenumber (',' CHAR_STRING | filenumber)*
22602256
)
@@ -6760,4 +6756,4 @@ numeric_function_name
67606756
| NVL
67616757
| ROUND
67626758
| SUM
6763-
;
6759+
;

0 commit comments

Comments
 (0)