From cdfadfba855df446bb2d35a2642e152454e1eb33 Mon Sep 17 00:00:00 2001 From: Adel Salakh Date: Thu, 28 Sep 2023 00:03:59 +0200 Subject: [PATCH] fix: stop pg ranges from being parsed as params --- .../sql/__snapshots__/index.test.ts.snap | 22 + .../src/loader/sql/grammar/SQLParser.g4 | 5 +- packages/parser/src/loader/sql/index.test.ts | 8 + .../parser/src/loader/sql/parser/SQLParser.ts | 391 +++++++++++------- .../loader/sql/parser/SQLParserListener.ts | 13 +- .../src/loader/sql/parser/SQLParserVisitor.ts | 9 +- 6 files changed, 288 insertions(+), 160 deletions(-) diff --git a/packages/parser/src/loader/sql/__snapshots__/index.test.ts.snap b/packages/parser/src/loader/sql/__snapshots__/index.test.ts.snap index e93bea19..0ec594f0 100644 --- a/packages/parser/src/loader/sql/__snapshots__/index.test.ts.snap +++ b/packages/parser/src/loader/sql/__snapshots__/index.test.ts.snap @@ -706,6 +706,28 @@ Object { } `; +exports[`Query with a PG range 1`] = ` +Object { + "events": Array [], + "queries": Array [ + Object { + "name": "TestRange", + "params": Array [], + "statement": Object { + "body": "select (ARRAY[1,2,3,4])[2:3] as arr", + "loc": Object { + "a": 27, + "b": 61, + "col": 2, + "line": 3, + }, + }, + "usedParamSet": Object {}, + }, + ], +} +`; + exports[`Unused parameters produce warnings 1`] = ` Object { "events": Array [ diff --git a/packages/parser/src/loader/sql/grammar/SQLParser.g4 b/packages/parser/src/loader/sql/grammar/SQLParser.g4 index ce94f6aa..57e0bcc9 100644 --- a/packages/parser/src/loader/sql/grammar/SQLParser.g4 +++ b/packages/parser/src/loader/sql/grammar/SQLParser.g4 @@ -19,10 +19,13 @@ statement : statementBody EOF_STATEMENT; statementBody - : (LINE_COMMENT | ignoredComment | param | word)*; + : (LINE_COMMENT | ignoredComment | param | word | range)*; word: WORD | ID | STRING | S_REQUIRED_MARK | DOLLAR_STRING; +// required to avoid errors when matching strings like "[1:2]" as params +range: PARAM_MARK word; + param: PARAM_MARK paramId; paramId: ID S_REQUIRED_MARK?; diff --git a/packages/parser/src/loader/sql/index.test.ts b/packages/parser/src/loader/sql/index.test.ts index a0b9e6c7..92e81626 100644 --- a/packages/parser/src/loader/sql/index.test.ts +++ b/packages/parser/src/loader/sql/index.test.ts @@ -154,3 +154,11 @@ test('Dollar quoted strings are supported', () => { const parseTree = parse(text); expect(parseTree).toMatchSnapshot(); }); + +test('Query with a PG range', () => { + const text = ` + /* @name TestRange */ + select (ARRAY[1,2,3,4])[2:3] as arr;`; + const parseTree = parse(text); + expect(parseTree).toMatchSnapshot(); +}); diff --git a/packages/parser/src/loader/sql/parser/SQLParser.ts b/packages/parser/src/loader/sql/parser/SQLParser.ts index 61352fae..d787e22d 100644 --- a/packages/parser/src/loader/sql/parser/SQLParser.ts +++ b/packages/parser/src/loader/sql/parser/SQLParser.ts @@ -58,24 +58,25 @@ export class SQLParser extends Parser { public static readonly RULE_statement = 4; public static readonly RULE_statementBody = 5; public static readonly RULE_word = 6; - public static readonly RULE_param = 7; - public static readonly RULE_paramId = 8; - public static readonly RULE_nameTag = 9; - public static readonly RULE_paramTag = 10; - public static readonly RULE_paramTransform = 11; - public static readonly RULE_transformRule = 12; - public static readonly RULE_spreadTransform = 13; - public static readonly RULE_pickTransform = 14; - public static readonly RULE_spreadPickTransform = 15; - public static readonly RULE_key = 16; - public static readonly RULE_queryName = 17; - public static readonly RULE_paramName = 18; + public static readonly RULE_range = 7; + public static readonly RULE_param = 8; + public static readonly RULE_paramId = 9; + public static readonly RULE_nameTag = 10; + public static readonly RULE_paramTag = 11; + public static readonly RULE_paramTransform = 12; + public static readonly RULE_transformRule = 13; + public static readonly RULE_spreadTransform = 14; + public static readonly RULE_pickTransform = 15; + public static readonly RULE_spreadPickTransform = 16; + public static readonly RULE_key = 17; + public static readonly RULE_queryName = 18; + public static readonly RULE_paramName = 19; // tslint:disable:no-trailing-whitespace public static readonly ruleNames: string[] = [ "input", "query", "queryDef", "ignoredComment", "statement", "statementBody", - "word", "param", "paramId", "nameTag", "paramTag", "paramTransform", "transformRule", - "spreadTransform", "pickTransform", "spreadPickTransform", "key", "queryName", - "paramName", + "word", "range", "param", "paramId", "nameTag", "paramTag", "paramTransform", + "transformRule", "spreadTransform", "pickTransform", "spreadPickTransform", + "key", "queryName", "paramName", ]; private static readonly _LITERAL_NAMES: Array = [ @@ -125,37 +126,37 @@ export class SQLParser extends Parser { let _alt: number; this.enterOuterAlt(_localctx, 1); { - this.state = 45; + this.state = 47; this._errHandler.sync(this); _la = this._input.LA(1); do { { { - this.state = 41; + this.state = 43; this._errHandler.sync(this); _alt = this.interpreter.adaptivePredict(this._input, 0, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { if (_alt === 1) { { { - this.state = 38; + this.state = 40; this.ignoredComment(); } } } - this.state = 43; + this.state = 45; this._errHandler.sync(this); _alt = this.interpreter.adaptivePredict(this._input, 0, this._ctx); } - this.state = 44; + this.state = 46; this.query(); } } - this.state = 47; + this.state = 49; this._errHandler.sync(this); _la = this._input.LA(1); } while (_la === SQLParser.OPEN_COMMENT); - this.state = 49; + this.state = 51; this.match(SQLParser.EOF); } } @@ -180,9 +181,9 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 51; + this.state = 53; this.queryDef(); - this.state = 52; + this.state = 54; this.statement(); } } @@ -208,25 +209,25 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 54; + this.state = 56; this.match(SQLParser.OPEN_COMMENT); - this.state = 55; + this.state = 57; this.nameTag(); - this.state = 59; + this.state = 61; this._errHandler.sync(this); _la = this._input.LA(1); while (_la === SQLParser.TYPE_TAG) { { { - this.state = 56; + this.state = 58; this.paramTag(); } } - this.state = 61; + this.state = 63; this._errHandler.sync(this); _la = this._input.LA(1); } - this.state = 62; + this.state = 64; this.match(SQLParser.CLOSE_COMMENT); } } @@ -252,15 +253,15 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 64; + this.state = 66; this.match(SQLParser.OPEN_COMMENT); - this.state = 68; + this.state = 70; this._errHandler.sync(this); _la = this._input.LA(1); while ((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << SQLParser.ID) | (1 << SQLParser.LINE_COMMENT) | (1 << SQLParser.OPEN_COMMENT) | (1 << SQLParser.S_REQUIRED_MARK) | (1 << SQLParser.WORD) | (1 << SQLParser.EOF_STATEMENT) | (1 << SQLParser.WSL) | (1 << SQLParser.STRING) | (1 << SQLParser.DOLLAR_STRING) | (1 << SQLParser.PARAM_MARK) | (1 << SQLParser.WS) | (1 << SQLParser.TRANSFORM_ARROW) | (1 << SQLParser.SPREAD) | (1 << SQLParser.NAME_TAG) | (1 << SQLParser.TYPE_TAG) | (1 << SQLParser.OB) | (1 << SQLParser.CB) | (1 << SQLParser.COMMA) | (1 << SQLParser.C_REQUIRED_MARK) | (1 << SQLParser.ANY) | (1 << SQLParser.DOLLAR) | (1 << SQLParser.CAST))) !== 0)) { { { - this.state = 65; + this.state = 67; _la = this._input.LA(1); if (_la <= 0 || (_la === SQLParser.CLOSE_COMMENT)) { this._errHandler.recoverInline(this); @@ -274,11 +275,11 @@ export class SQLParser extends Parser { } } } - this.state = 70; + this.state = 72; this._errHandler.sync(this); _la = this._input.LA(1); } - this.state = 71; + this.state = 73; this.match(SQLParser.CLOSE_COMMENT); } } @@ -303,9 +304,9 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 73; + this.state = 75; this.statementBody(); - this.state = 74; + this.state = 76; this.match(SQLParser.EOF_STATEMENT); } } @@ -331,47 +332,51 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 82; + this.state = 85; this._errHandler.sync(this); _la = this._input.LA(1); while ((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << SQLParser.ID) | (1 << SQLParser.LINE_COMMENT) | (1 << SQLParser.OPEN_COMMENT) | (1 << SQLParser.S_REQUIRED_MARK) | (1 << SQLParser.WORD) | (1 << SQLParser.STRING) | (1 << SQLParser.DOLLAR_STRING) | (1 << SQLParser.PARAM_MARK))) !== 0)) { { - this.state = 80; + this.state = 83; this._errHandler.sync(this); - switch (this._input.LA(1)) { - case SQLParser.LINE_COMMENT: + switch ( this.interpreter.adaptivePredict(this._input, 4, this._ctx) ) { + case 1: { - this.state = 76; + this.state = 78; this.match(SQLParser.LINE_COMMENT); } break; - case SQLParser.OPEN_COMMENT: + + case 2: { - this.state = 77; + this.state = 79; this.ignoredComment(); } break; - case SQLParser.PARAM_MARK: + + case 3: { - this.state = 78; + this.state = 80; this.param(); } break; - case SQLParser.ID: - case SQLParser.S_REQUIRED_MARK: - case SQLParser.WORD: - case SQLParser.STRING: - case SQLParser.DOLLAR_STRING: + + case 4: { - this.state = 79; + this.state = 81; this.word(); } break; - default: - throw new NoViableAltException(this); + + case 5: + { + this.state = 82; + this.range(); + } + break; } } - this.state = 84; + this.state = 87; this._errHandler.sync(this); _la = this._input.LA(1); } @@ -399,7 +404,7 @@ export class SQLParser extends Parser { try { this.enterOuterAlt(_localctx, 1); { - this.state = 85; + this.state = 88; _la = this._input.LA(1); if (!((((_la) & ~0x1F) === 0 && ((1 << _la) & ((1 << SQLParser.ID) | (1 << SQLParser.S_REQUIRED_MARK) | (1 << SQLParser.WORD) | (1 << SQLParser.STRING) | (1 << SQLParser.DOLLAR_STRING))) !== 0))) { this._errHandler.recoverInline(this); @@ -428,15 +433,42 @@ export class SQLParser extends Parser { return _localctx; } // @RuleVersion(0) + public range(): RangeContext { + let _localctx: RangeContext = new RangeContext(this._ctx, this.state); + this.enterRule(_localctx, 14, SQLParser.RULE_range); + try { + this.enterOuterAlt(_localctx, 1); + { + this.state = 90; + this.match(SQLParser.PARAM_MARK); + this.state = 91; + this.word(); + } + } + catch (re) { + if (re instanceof RecognitionException) { + _localctx.exception = re; + this._errHandler.reportError(this, re); + this._errHandler.recover(this, re); + } else { + throw re; + } + } + finally { + this.exitRule(); + } + return _localctx; + } + // @RuleVersion(0) public param(): ParamContext { let _localctx: ParamContext = new ParamContext(this._ctx, this.state); - this.enterRule(_localctx, 14, SQLParser.RULE_param); + this.enterRule(_localctx, 16, SQLParser.RULE_param); try { this.enterOuterAlt(_localctx, 1); { - this.state = 87; + this.state = 93; this.match(SQLParser.PARAM_MARK); - this.state = 88; + this.state = 94; this.paramId(); } } @@ -457,18 +489,18 @@ export class SQLParser extends Parser { // @RuleVersion(0) public paramId(): ParamIdContext { let _localctx: ParamIdContext = new ParamIdContext(this._ctx, this.state); - this.enterRule(_localctx, 16, SQLParser.RULE_paramId); + this.enterRule(_localctx, 18, SQLParser.RULE_paramId); try { this.enterOuterAlt(_localctx, 1); { - this.state = 90; + this.state = 96; this.match(SQLParser.ID); - this.state = 92; + this.state = 98; this._errHandler.sync(this); switch ( this.interpreter.adaptivePredict(this._input, 6, this._ctx) ) { case 1: { - this.state = 91; + this.state = 97; this.match(SQLParser.S_REQUIRED_MARK); } break; @@ -492,13 +524,13 @@ export class SQLParser extends Parser { // @RuleVersion(0) public nameTag(): NameTagContext { let _localctx: NameTagContext = new NameTagContext(this._ctx, this.state); - this.enterRule(_localctx, 18, SQLParser.RULE_nameTag); + this.enterRule(_localctx, 20, SQLParser.RULE_nameTag); try { this.enterOuterAlt(_localctx, 1); { - this.state = 94; + this.state = 100; this.match(SQLParser.NAME_TAG); - this.state = 95; + this.state = 101; this.queryName(); } } @@ -519,15 +551,15 @@ export class SQLParser extends Parser { // @RuleVersion(0) public paramTag(): ParamTagContext { let _localctx: ParamTagContext = new ParamTagContext(this._ctx, this.state); - this.enterRule(_localctx, 20, SQLParser.RULE_paramTag); + this.enterRule(_localctx, 22, SQLParser.RULE_paramTag); try { this.enterOuterAlt(_localctx, 1); { - this.state = 97; + this.state = 103; this.match(SQLParser.TYPE_TAG); - this.state = 98; + this.state = 104; this.paramName(); - this.state = 99; + this.state = 105; this.paramTransform(); } } @@ -548,13 +580,13 @@ export class SQLParser extends Parser { // @RuleVersion(0) public paramTransform(): ParamTransformContext { let _localctx: ParamTransformContext = new ParamTransformContext(this._ctx, this.state); - this.enterRule(_localctx, 22, SQLParser.RULE_paramTransform); + this.enterRule(_localctx, 24, SQLParser.RULE_paramTransform); try { this.enterOuterAlt(_localctx, 1); { - this.state = 101; + this.state = 107; this.match(SQLParser.TRANSFORM_ARROW); - this.state = 102; + this.state = 108; this.transformRule(); } } @@ -575,15 +607,15 @@ export class SQLParser extends Parser { // @RuleVersion(0) public transformRule(): TransformRuleContext { let _localctx: TransformRuleContext = new TransformRuleContext(this._ctx, this.state); - this.enterRule(_localctx, 24, SQLParser.RULE_transformRule); + this.enterRule(_localctx, 26, SQLParser.RULE_transformRule); try { - this.state = 107; + this.state = 113; this._errHandler.sync(this); switch ( this.interpreter.adaptivePredict(this._input, 7, this._ctx) ) { case 1: this.enterOuterAlt(_localctx, 1); { - this.state = 104; + this.state = 110; this.spreadTransform(); } break; @@ -591,7 +623,7 @@ export class SQLParser extends Parser { case 2: this.enterOuterAlt(_localctx, 2); { - this.state = 105; + this.state = 111; this.pickTransform(); } break; @@ -599,7 +631,7 @@ export class SQLParser extends Parser { case 3: this.enterOuterAlt(_localctx, 3); { - this.state = 106; + this.state = 112; this.spreadPickTransform(); } break; @@ -622,15 +654,15 @@ export class SQLParser extends Parser { // @RuleVersion(0) public spreadTransform(): SpreadTransformContext { let _localctx: SpreadTransformContext = new SpreadTransformContext(this._ctx, this.state); - this.enterRule(_localctx, 26, SQLParser.RULE_spreadTransform); + this.enterRule(_localctx, 28, SQLParser.RULE_spreadTransform); try { this.enterOuterAlt(_localctx, 1); { - this.state = 109; + this.state = 115; this.match(SQLParser.OB); - this.state = 110; + this.state = 116; this.match(SQLParser.SPREAD); - this.state = 111; + this.state = 117; this.match(SQLParser.CB); } } @@ -651,45 +683,45 @@ export class SQLParser extends Parser { // @RuleVersion(0) public pickTransform(): PickTransformContext { let _localctx: PickTransformContext = new PickTransformContext(this._ctx, this.state); - this.enterRule(_localctx, 28, SQLParser.RULE_pickTransform); + this.enterRule(_localctx, 30, SQLParser.RULE_pickTransform); let _la: number; try { let _alt: number; this.enterOuterAlt(_localctx, 1); { - this.state = 113; + this.state = 119; this.match(SQLParser.OB); - this.state = 114; + this.state = 120; this.key(); - this.state = 119; + this.state = 125; this._errHandler.sync(this); _alt = this.interpreter.adaptivePredict(this._input, 8, this._ctx); while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER) { if (_alt === 1) { { { - this.state = 115; + this.state = 121; this.match(SQLParser.COMMA); - this.state = 116; + this.state = 122; this.key(); } } } - this.state = 121; + this.state = 127; this._errHandler.sync(this); _alt = this.interpreter.adaptivePredict(this._input, 8, this._ctx); } - this.state = 123; + this.state = 129; this._errHandler.sync(this); _la = this._input.LA(1); if (_la === SQLParser.COMMA) { { - this.state = 122; + this.state = 128; this.match(SQLParser.COMMA); } } - this.state = 125; + this.state = 131; this.match(SQLParser.CB); } } @@ -710,17 +742,17 @@ export class SQLParser extends Parser { // @RuleVersion(0) public spreadPickTransform(): SpreadPickTransformContext { let _localctx: SpreadPickTransformContext = new SpreadPickTransformContext(this._ctx, this.state); - this.enterRule(_localctx, 30, SQLParser.RULE_spreadPickTransform); + this.enterRule(_localctx, 32, SQLParser.RULE_spreadPickTransform); try { this.enterOuterAlt(_localctx, 1); { - this.state = 127; + this.state = 133; this.match(SQLParser.OB); - this.state = 128; + this.state = 134; this.pickTransform(); - this.state = 129; + this.state = 135; this.match(SQLParser.SPREAD); - this.state = 130; + this.state = 136; this.match(SQLParser.CB); } } @@ -741,19 +773,19 @@ export class SQLParser extends Parser { // @RuleVersion(0) public key(): KeyContext { let _localctx: KeyContext = new KeyContext(this._ctx, this.state); - this.enterRule(_localctx, 32, SQLParser.RULE_key); + this.enterRule(_localctx, 34, SQLParser.RULE_key); let _la: number; try { this.enterOuterAlt(_localctx, 1); { - this.state = 132; + this.state = 138; this.match(SQLParser.ID); - this.state = 134; + this.state = 140; this._errHandler.sync(this); _la = this._input.LA(1); if (_la === SQLParser.C_REQUIRED_MARK) { { - this.state = 133; + this.state = 139; this.match(SQLParser.C_REQUIRED_MARK); } } @@ -777,11 +809,11 @@ export class SQLParser extends Parser { // @RuleVersion(0) public queryName(): QueryNameContext { let _localctx: QueryNameContext = new QueryNameContext(this._ctx, this.state); - this.enterRule(_localctx, 34, SQLParser.RULE_queryName); + this.enterRule(_localctx, 36, SQLParser.RULE_queryName); try { this.enterOuterAlt(_localctx, 1); { - this.state = 136; + this.state = 142; this.match(SQLParser.ID); } } @@ -802,11 +834,11 @@ export class SQLParser extends Parser { // @RuleVersion(0) public paramName(): ParamNameContext { let _localctx: ParamNameContext = new ParamNameContext(this._ctx, this.state); - this.enterRule(_localctx, 36, SQLParser.RULE_paramName); + this.enterRule(_localctx, 38, SQLParser.RULE_paramName); try { this.enterOuterAlt(_localctx, 1); { - this.state = 138; + this.state = 144; this.match(SQLParser.ID); } } @@ -826,61 +858,64 @@ export class SQLParser extends Parser { } public static readonly _serializedATN: string = - "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x03\x19\x8F\x04\x02" + + "\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x03\x19\x95\x04\x02" + "\t\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06\x04\x07" + "\t\x07\x04\b\t\b\x04\t\t\t\x04\n\t\n\x04\v\t\v\x04\f\t\f\x04\r\t\r\x04" + "\x0E\t\x0E\x04\x0F\t\x0F\x04\x10\t\x10\x04\x11\t\x11\x04\x12\t\x12\x04" + - "\x13\t\x13\x04\x14\t\x14\x03\x02\x07\x02*\n\x02\f\x02\x0E\x02-\v\x02\x03" + - "\x02\x06\x020\n\x02\r\x02\x0E\x021\x03\x02\x03\x02\x03\x03\x03\x03\x03" + - "\x03\x03\x04\x03\x04\x03\x04\x07\x04<\n\x04\f\x04\x0E\x04?\v\x04\x03\x04" + - "\x03\x04\x03\x05\x03\x05\x07\x05E\n\x05\f\x05\x0E\x05H\v\x05\x03\x05\x03" + - "\x05\x03\x06\x03\x06\x03\x06\x03\x07\x03\x07\x03\x07\x03\x07\x07\x07S" + - "\n\x07\f\x07\x0E\x07V\v\x07\x03\b\x03\b\x03\t\x03\t\x03\t\x03\n\x03\n" + - "\x05\n_\n\n\x03\v\x03\v\x03\v\x03\f\x03\f\x03\f\x03\f\x03\r\x03\r\x03" + - "\r\x03\x0E\x03\x0E\x03\x0E\x05\x0En\n\x0E\x03\x0F\x03\x0F\x03\x0F\x03" + - "\x0F\x03\x10\x03\x10\x03\x10\x03\x10\x07\x10x\n\x10\f\x10\x0E\x10{\v\x10" + - "\x03\x10\x05\x10~\n\x10\x03\x10\x03\x10\x03\x11\x03\x11\x03\x11\x03\x11" + - "\x03\x11\x03\x12\x03\x12\x05\x12\x89\n\x12\x03\x13\x03\x13\x03\x14\x03" + - "\x14\x03\x14\x02\x02\x02\x15\x02\x02\x04\x02\x06\x02\b\x02\n\x02\f\x02" + - "\x0E\x02\x10\x02\x12\x02\x14\x02\x16\x02\x18\x02\x1A\x02\x1C\x02\x1E\x02" + - " \x02\"\x02$\x02&\x02\x02\x04\x03\x02\x17\x17\x05\x02\x03\x03\x06\x07" + - "\n\v\x02\x89\x02/\x03\x02\x02\x02\x045\x03\x02\x02\x02\x068\x03\x02\x02" + - "\x02\bB\x03\x02\x02\x02\nK\x03\x02\x02\x02\fT\x03\x02\x02\x02\x0EW\x03" + - "\x02\x02\x02\x10Y\x03\x02\x02\x02\x12\\\x03\x02\x02\x02\x14`\x03\x02\x02" + - "\x02\x16c\x03\x02\x02\x02\x18g\x03\x02\x02\x02\x1Am\x03\x02\x02\x02\x1C" + - "o\x03\x02\x02\x02\x1Es\x03\x02\x02\x02 \x81\x03\x02\x02\x02\"\x86\x03" + - "\x02\x02\x02$\x8A\x03\x02\x02\x02&\x8C\x03\x02\x02\x02(*\x05\b\x05\x02" + - ")(\x03\x02\x02\x02*-\x03\x02\x02\x02+)\x03\x02\x02\x02+,\x03\x02\x02\x02" + - ",.\x03\x02\x02\x02-+\x03\x02\x02\x02.0\x05\x04\x03\x02/+\x03\x02\x02\x02" + - "01\x03\x02\x02\x021/\x03\x02\x02\x0212\x03\x02\x02\x0223\x03\x02\x02\x02" + - "34\x07\x02\x02\x034\x03\x03\x02\x02\x0256\x05\x06\x04\x0267\x05\n\x06" + - "\x027\x05\x03\x02\x02\x0289\x07\x05\x02\x029=\x05\x14\v\x02:<\x05\x16" + - "\f\x02;:\x03\x02\x02\x02\x03\x02" + - "\x02\x02>@\x03\x02\x02\x02?=\x03\x02\x02\x02@A\x07\x17\x02\x02A\x07\x03" + - "\x02\x02\x02BF\x07\x05\x02\x02CE\n\x02\x02\x02DC\x03\x02\x02\x02EH\x03" + - "\x02\x02\x02FD\x03\x02\x02\x02FG\x03\x02\x02\x02GI\x03\x02\x02\x02HF\x03" + - "\x02\x02\x02IJ\x07\x17\x02\x02J\t\x03\x02\x02\x02KL\x05\f\x07\x02LM\x07" + - "\b\x02\x02M\v\x03\x02\x02\x02NS\x07\x04\x02\x02OS\x05\b\x05\x02PS\x05" + - "\x10\t\x02QS\x05\x0E\b\x02RN\x03\x02\x02\x02RO\x03\x02\x02\x02RP\x03\x02" + - "\x02\x02RQ\x03\x02\x02\x02SV\x03\x02\x02\x02TR\x03\x02\x02\x02TU\x03\x02" + - "\x02\x02U\r\x03\x02\x02\x02VT\x03\x02\x02\x02WX\t\x03\x02\x02X\x0F\x03" + - "\x02\x02\x02YZ\x07\f\x02\x02Z[\x05\x12\n\x02[\x11\x03\x02\x02\x02\\^\x07" + - "\x03\x02\x02]_\x07\x06\x02\x02^]\x03\x02\x02\x02^_\x03\x02\x02\x02_\x13" + - "\x03\x02\x02\x02`a\x07\x10\x02\x02ab\x05$\x13\x02b\x15\x03\x02\x02\x02" + - "cd\x07\x11\x02\x02de\x05&\x14\x02ef\x05\x18\r\x02f\x17\x03\x02\x02\x02" + - "gh\x07\x0E\x02\x02hi\x05\x1A\x0E\x02i\x19\x03\x02\x02\x02jn\x05\x1C\x0F" + - "\x02kn\x05\x1E\x10\x02ln\x05 \x11\x02mj\x03\x02\x02\x02mk\x03\x02\x02" + - "\x02ml\x03\x02\x02\x02n\x1B\x03\x02\x02\x02op\x07\x12\x02\x02pq\x07\x0F" + - "\x02\x02qr\x07\x13\x02\x02r\x1D\x03\x02\x02\x02st\x07\x12\x02\x02ty\x05" + - "\"\x12\x02uv\x07\x14\x02\x02vx\x05\"\x12\x02wu\x03\x02\x02\x02x{\x03\x02" + - "\x02\x02yw\x03\x02\x02\x02yz\x03\x02\x02\x02z}\x03\x02\x02\x02{y\x03\x02" + - "\x02\x02|~\x07\x14\x02\x02}|\x03\x02\x02\x02}~\x03\x02\x02\x02~\x7F\x03" + - "\x02\x02\x02\x7F\x80\x07\x13\x02\x02\x80\x1F\x03\x02\x02\x02\x81\x82\x07" + - "\x12\x02\x02\x82\x83\x05\x1E\x10\x02\x83\x84\x07\x0F\x02\x02\x84\x85\x07" + - "\x13\x02\x02\x85!\x03\x02\x02\x02\x86\x88\x07\x03\x02\x02\x87\x89\x07" + - "\x15\x02\x02\x88\x87\x03\x02\x02\x02\x88\x89\x03\x02\x02\x02\x89#\x03" + - "\x02\x02\x02\x8A\x8B\x07\x03\x02\x02\x8B%\x03\x02\x02\x02\x8C\x8D\x07" + - "\x03\x02\x02\x8D\'\x03\x02\x02\x02\r+1=FRT^my}\x88"; + "\x13\t\x13\x04\x14\t\x14\x04\x15\t\x15\x03\x02\x07\x02,\n\x02\f\x02\x0E" + + "\x02/\v\x02\x03\x02\x06\x022\n\x02\r\x02\x0E\x023\x03\x02\x03\x02\x03" + + "\x03\x03\x03\x03\x03\x03\x04\x03\x04\x03\x04\x07\x04>\n\x04\f\x04\x0E" + + "\x04A\v\x04\x03\x04\x03\x04\x03\x05\x03\x05\x07\x05G\n\x05\f\x05\x0E\x05" + + "J\v\x05\x03\x05\x03\x05\x03\x06\x03\x06\x03\x06\x03\x07\x03\x07\x03\x07" + + "\x03\x07\x03\x07\x07\x07V\n\x07\f\x07\x0E\x07Y\v\x07\x03\b\x03\b\x03\t" + + "\x03\t\x03\t\x03\n\x03\n\x03\n\x03\v\x03\v\x05\ve\n\v\x03\f\x03\f\x03" + + "\f\x03\r\x03\r\x03\r\x03\r\x03\x0E\x03\x0E\x03\x0E\x03\x0F\x03\x0F\x03" + + "\x0F\x05\x0Ft\n\x0F\x03\x10\x03\x10\x03\x10\x03\x10\x03\x11\x03\x11\x03" + + "\x11\x03\x11\x07\x11~\n\x11\f\x11\x0E\x11\x81\v\x11\x03\x11\x05\x11\x84" + + "\n\x11\x03\x11\x03\x11\x03\x12\x03\x12\x03\x12\x03\x12\x03\x12\x03\x13" + + "\x03\x13\x05\x13\x8F\n\x13\x03\x14\x03\x14\x03\x15\x03\x15\x03\x15\x02" + + "\x02\x02\x16\x02\x02\x04\x02\x06\x02\b\x02\n\x02\f\x02\x0E\x02\x10\x02" + + "\x12\x02\x14\x02\x16\x02\x18\x02\x1A\x02\x1C\x02\x1E\x02 \x02\"\x02$\x02" + + "&\x02(\x02\x02\x04\x03\x02\x17\x17\x05\x02\x03\x03\x06\x07\n\v\x02\x8F" + + "\x021\x03\x02\x02\x02\x047\x03\x02\x02\x02\x06:\x03\x02\x02\x02\bD\x03" + + "\x02\x02\x02\nM\x03\x02\x02\x02\fW\x03\x02\x02\x02\x0EZ\x03\x02\x02\x02" + + "\x10\\\x03\x02\x02\x02\x12_\x03\x02\x02\x02\x14b\x03\x02\x02\x02\x16f" + + "\x03\x02\x02\x02\x18i\x03\x02\x02\x02\x1Am\x03\x02\x02\x02\x1Cs\x03\x02" + + "\x02\x02\x1Eu\x03\x02\x02\x02 y\x03\x02\x02\x02\"\x87\x03\x02\x02\x02" + + "$\x8C\x03\x02\x02\x02&\x90\x03\x02\x02\x02(\x92\x03\x02\x02\x02*,\x05" + + "\b\x05\x02+*\x03\x02\x02\x02,/\x03\x02\x02\x02-+\x03\x02\x02\x02-.\x03" + + "\x02\x02\x02.0\x03\x02\x02\x02/-\x03\x02\x02\x0202\x05\x04\x03\x021-\x03" + + "\x02\x02\x0223\x03\x02\x02\x0231\x03\x02\x02\x0234\x03\x02\x02\x0245\x03" + + "\x02\x02\x0256\x07\x02\x02\x036\x03\x03\x02\x02\x0278\x05\x06\x04\x02" + + "89\x05\n\x06\x029\x05\x03\x02\x02\x02:;\x07\x05\x02\x02;?\x05\x16\f\x02" + + "<>\x05\x18\r\x02=<\x03\x02\x02\x02>A\x03\x02\x02\x02?=\x03\x02\x02\x02" + + "?@\x03\x02\x02\x02@B\x03\x02\x02\x02A?\x03\x02\x02\x02BC\x07\x17\x02\x02" + + "C\x07\x03\x02\x02\x02DH\x07\x05\x02\x02EG\n\x02\x02\x02FE\x03\x02\x02" + + "\x02GJ\x03\x02\x02\x02HF\x03\x02\x02\x02HI\x03\x02\x02\x02IK\x03\x02\x02" + + "\x02JH\x03\x02\x02\x02KL\x07\x17\x02\x02L\t\x03\x02\x02\x02MN\x05\f\x07" + + "\x02NO\x07\b\x02\x02O\v\x03\x02\x02\x02PV\x07\x04\x02\x02QV\x05\b\x05" + + "\x02RV\x05\x12\n\x02SV\x05\x0E\b\x02TV\x05\x10\t\x02UP\x03\x02\x02\x02" + + "UQ\x03\x02\x02\x02UR\x03\x02\x02\x02US\x03\x02\x02\x02UT\x03\x02\x02\x02" + + "VY\x03\x02\x02\x02WU\x03\x02\x02\x02WX\x03\x02\x02\x02X\r\x03\x02\x02" + + "\x02YW\x03\x02\x02\x02Z[\t\x03\x02\x02[\x0F\x03\x02\x02\x02\\]\x07\f\x02" + + "\x02]^\x05\x0E\b\x02^\x11\x03\x02\x02\x02_`\x07\f\x02\x02`a\x05\x14\v" + + "\x02a\x13\x03\x02\x02\x02bd\x07\x03\x02\x02ce\x07\x06\x02\x02dc\x03\x02" + + "\x02\x02de\x03\x02\x02\x02e\x15\x03\x02\x02\x02fg\x07\x10\x02\x02gh\x05" + + "&\x14\x02h\x17\x03\x02\x02\x02ij\x07\x11\x02\x02jk\x05(\x15\x02kl\x05" + + "\x1A\x0E\x02l\x19\x03\x02\x02\x02mn\x07\x0E\x02\x02no\x05\x1C\x0F\x02" + + "o\x1B\x03\x02\x02\x02pt\x05\x1E\x10\x02qt\x05 \x11\x02rt\x05\"\x12\x02" + + "sp\x03\x02\x02\x02sq\x03\x02\x02\x02sr\x03\x02\x02\x02t\x1D\x03\x02\x02" + + "\x02uv\x07\x12\x02\x02vw\x07\x0F\x02\x02wx\x07\x13\x02\x02x\x1F\x03\x02" + + "\x02\x02yz\x07\x12\x02\x02z\x7F\x05$\x13\x02{|\x07\x14\x02\x02|~\x05$" + + "\x13\x02}{\x03\x02\x02\x02~\x81\x03\x02\x02\x02\x7F}\x03\x02\x02\x02\x7F" + + "\x80\x03\x02\x02\x02\x80\x83\x03\x02\x02\x02\x81\x7F\x03\x02\x02\x02\x82" + + "\x84\x07\x14\x02\x02\x83\x82\x03\x02\x02\x02\x83\x84\x03\x02\x02\x02\x84" + + "\x85\x03\x02\x02\x02\x85\x86\x07\x13\x02\x02\x86!\x03\x02\x02\x02\x87" + + "\x88\x07\x12\x02\x02\x88\x89\x05 \x11\x02\x89\x8A\x07\x0F\x02\x02\x8A" + + "\x8B\x07\x13\x02\x02\x8B#\x03\x02\x02\x02\x8C\x8E\x07\x03\x02\x02\x8D" + + "\x8F\x07\x15\x02\x02\x8E\x8D\x03\x02\x02\x02\x8E\x8F\x03\x02\x02\x02\x8F" + + "%\x03\x02\x02\x02\x90\x91\x07\x03\x02\x02\x91\'\x03\x02\x02\x02\x92\x93" + + "\x07\x03\x02\x02\x93)\x03\x02\x02\x02\r-3?HUWds\x7F\x83\x8E"; public static __ATN: ATN; public static get _ATN(): ATN { if (!SQLParser.__ATN) { @@ -1127,6 +1162,15 @@ export class StatementBodyContext extends ParserRuleContext { return this.getRuleContext(i, WordContext); } } + public range(): RangeContext[]; + public range(i: number): RangeContext; + public range(i?: number): RangeContext | RangeContext[] { + if (i === undefined) { + return this.getRuleContexts(RangeContext); + } else { + return this.getRuleContext(i, RangeContext); + } + } constructor(parent: ParserRuleContext | undefined, invokingState: number) { super(parent, invokingState); } @@ -1189,6 +1233,39 @@ export class WordContext extends ParserRuleContext { } +export class RangeContext extends ParserRuleContext { + public PARAM_MARK(): TerminalNode { return this.getToken(SQLParser.PARAM_MARK, 0); } + public word(): WordContext { + return this.getRuleContext(0, WordContext); + } + constructor(parent: ParserRuleContext | undefined, invokingState: number) { + super(parent, invokingState); + } + // @Override + public get ruleIndex(): number { return SQLParser.RULE_range; } + // @Override + public enterRule(listener: SQLParserListener): void { + if (listener.enterRange) { + listener.enterRange(this); + } + } + // @Override + public exitRule(listener: SQLParserListener): void { + if (listener.exitRange) { + listener.exitRange(this); + } + } + // @Override + public accept(visitor: SQLParserVisitor): Result { + if (visitor.visitRange) { + return visitor.visitRange(this); + } else { + return visitor.visitChildren(this); + } + } +} + + export class ParamContext extends ParserRuleContext { public PARAM_MARK(): TerminalNode { return this.getToken(SQLParser.PARAM_MARK, 0); } public paramId(): ParamIdContext { diff --git a/packages/parser/src/loader/sql/parser/SQLParserListener.ts b/packages/parser/src/loader/sql/parser/SQLParserListener.ts index a998316c..73adee92 100644 --- a/packages/parser/src/loader/sql/parser/SQLParserListener.ts +++ b/packages/parser/src/loader/sql/parser/SQLParserListener.ts @@ -3,7 +3,7 @@ import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener.js"; -import { InputContext } from "./SQLParser.js"; +import {InputContext, RangeContext} from "./SQLParser.js"; import { QueryContext } from "./SQLParser.js"; import { QueryDefContext } from "./SQLParser.js"; import { IgnoredCommentContext } from "./SQLParser.js"; @@ -106,6 +106,17 @@ export interface SQLParserListener extends ParseTreeListener { */ exitWord?: (ctx: WordContext) => void; + /** + * Enter a parse tree produced by `SQLParser.range`. + * @param ctx the parse tree + */ + enterRange?: (ctx: RangeContext) => void; + /** + * Exit a parse tree produced by `SQLParser.range`. + * @param ctx the parse tree + */ + exitRange?: (ctx: RangeContext) => void; + /** * Enter a parse tree produced by `SQLParser.param`. * @param ctx the parse tree diff --git a/packages/parser/src/loader/sql/parser/SQLParserVisitor.ts b/packages/parser/src/loader/sql/parser/SQLParserVisitor.ts index 170d463d..1ad6ef76 100644 --- a/packages/parser/src/loader/sql/parser/SQLParserVisitor.ts +++ b/packages/parser/src/loader/sql/parser/SQLParserVisitor.ts @@ -3,7 +3,7 @@ import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor.js"; -import { InputContext } from "./SQLParser.js"; +import {InputContext, RangeContext} from "./SQLParser.js"; import { QueryContext } from "./SQLParser.js"; import { QueryDefContext } from "./SQLParser.js"; import { IgnoredCommentContext } from "./SQLParser.js"; @@ -81,6 +81,13 @@ export interface SQLParserVisitor extends ParseTreeVisitor { */ visitWord?: (ctx: WordContext) => Result; + /** + * Visit a parse tree produced by `SQLParser.range`. + * @param ctx the parse tree + * @return the visitor result + */ + visitRange?: (ctx: RangeContext) => Result; + /** * Visit a parse tree produced by `SQLParser.param`. * @param ctx the parse tree