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
This commit is contained in:
Ziv
2023-05-24 15:07:53 +08:00
committed by GitHub
parent 9c82a5d248
commit eeb111b5c5
23 changed files with 231 additions and 215 deletions

View File

@ -1,10 +1,11 @@
// dt-sql-parser/src/grammar/pgsql/PostgreSQLLexer.g4 by ANTLR 4.12.0
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/pgsql/PostgreSQLLexer.g4 by ANTLR 4.12.0
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
import {
ATN,
ATNDeserializer,
CharStream,
DecisionState, DFA,
Lexer,
LexerATNSimulator,
RuleContext,
PredictionContextCache,
@ -12,7 +13,7 @@ import {
} from "antlr4";
import PostgreSQLLexerBase from './base/PostgreSQLLexerBase';
import PostgreSQLLexerBase from './PostgreSQLLexerBase';
export default class PostgreSQLLexer extends PostgreSQLLexerBase {
public static readonly Dollar = 1;
@ -1195,9 +1196,11 @@ export default class PostgreSQLLexer extends PostgreSQLLexerBase {
"EndDollarStringConstant",
];
/* This field stores the tags which are used to detect the end of a dollar-quoted string literal.
*/
constructor(input: CharStream) {
super(input);
this._interp = new LexerATNSimulator(this, PostgreSQLLexer._ATN, PostgreSQLLexer.DecisionsToDFA, new PredictionContextCache());
@ -1244,7 +1247,9 @@ export default class PostgreSQLLexer extends PostgreSQLLexerBase {
private Operator_action(localctx: RuleContext, actionIndex: number): void {
switch (actionIndex) {
case 0:
this.HandleLessLessGreaterGreater();
break;
}
}
@ -1266,7 +1271,7 @@ export default class PostgreSQLLexer extends PostgreSQLLexerBase {
switch (actionIndex) {
case 3:
this.UnterminatedBlockCommentDebugAssert();
this.UnterminatedBlockCommentDebugAssert();
break;
}

View File

@ -1,19 +1,26 @@
// dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
// noinspection ES6UnusedImports,JSUnusedGlobalSymbols,JSUnusedLocalSymbols
import {
ATN,
ATNDeserializer, DecisionState, DFA, FailedPredicateException,
RecognitionException, NoViableAltException,
ParserATNSimulator,
RuleContext, ParserRuleContext, PredictionContextCache,
TerminalNode,
RecognitionException, NoViableAltException, BailErrorStrategy,
Parser, ParserATNSimulator,
RuleContext, ParserRuleContext, PredictionMode, PredictionContextCache,
TerminalNode, RuleNode,
Token, TokenStream,
Interval, IntervalSet
} from 'antlr4';
import PostgreSQLParserListener from "./PostgreSQLParserListener.js";
import PostgreSQLParserVisitor from "./PostgreSQLParserVisitor.js";
import PostgreSQLParserBase from './base/PostgreSQLParserBase';
// for running tests with parameters, TODO: discuss strategy for typed parameters in CI
// eslint-disable-next-line no-unused-vars
type int = number;
import PostgreSQLParserBase from './PostgreSQLParserBase';
export default class PostgreSQLParser extends PostgreSQLParserBase {
public static readonly Dollar = 1;
@ -30836,7 +30843,9 @@ export default class PostgreSQLParser extends PostgreSQLParserBase {
this._errHandler.sync(this);
_alt = this._interp.adaptivePredict(this._input, 283, this._ctx);
} while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER);
this.ParseRoutineBody(localctx);
this.ParseRoutineBody(localctx);
}
}
catch (re) {
@ -55874,7 +55883,6 @@ export default class PostgreSQLParser extends PostgreSQLParserBase {
let _parentctx: ParserRuleContext = this._ctx;
let _parentState: number = this.state;
let localctx: B_exprContext = new B_exprContext(this, this._ctx, _parentState);
// @ts-ignore
let _prevctx: B_exprContext = localctx;
let _startState: number = 1192;
this.enterRecursionRule(localctx, 1192, PostgreSQLParser.RULE_b_expr, _p);
@ -97208,10 +97216,6 @@ export class AltertsconfigurationstmtContext extends ParserRuleContext {
public CONFIGURATION(): TerminalNode {
return this.getToken(PostgreSQLParser.CONFIGURATION, 0);
}
// @ts-ignore
public any_name_list(): Any_nameContext[] {
return this.getTypedRuleContexts(Any_nameContext) as Any_nameContext[];
}
public any_name(i: number): Any_nameContext {
return this.getTypedRuleContext(Any_nameContext, i) as Any_nameContext;
}
@ -97230,7 +97234,6 @@ export class AltertsconfigurationstmtContext extends ParserRuleContext {
public any_with(): Any_withContext {
return this.getTypedRuleContext(Any_withContext, 0) as Any_withContext;
}
// @ts-ignore
public any_name_list(): Any_name_listContext {
return this.getTypedRuleContext(Any_name_listContext, 0) as Any_name_listContext;
}

View File

@ -1,7 +1,7 @@
/* eslint-disable new-cap,camelcase */
import { Parser, CharStreams, CommonTokenStream } from 'antlr4';
import PostgreSQLLexer from '../PostgreSQLLexer';
import PostgreSQLParser from '../PostgreSQLParser';
import PostgreSQLLexer from './PostgreSQLLexer';
import PostgreSQLParser from './PostgreSQLParser';
export default class PostgreSQLParserBase extends Parser {

View File

@ -1,4 +1,4 @@
// dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
import {ParseTreeListener} from "antlr4";

View File

@ -1,4 +1,4 @@
// dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
// Generated from /Users/ziv/github.com/dt-sql-parser/src/grammar/pgsql/PostgreSQLParser.g4 by ANTLR 4.12.0
import {ParseTreeVisitor} from 'antlr4';