From f79202a5b75056eb22908a333e8679e5a2f12394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvatore=20Ravida=CC=80?= Date: Thu, 15 Dec 2022 19:58:20 +0100 Subject: [PATCH] Rename root to program --- src/grammar/pgsql/PostgreSQLParser.g4 | 2 +- src/lib/pgsql/PostgreSQLParser.interp | 2 +- src/lib/pgsql/PostgreSQLParser.js | 36 +++++++++++----------- src/lib/pgsql/PostgreSQLParserListener.js | 8 ++--- src/lib/pgsql/PostgreSQLParserVisitor.js | 4 +-- src/lib/pgsql/base/PostgreSQLParserBase.js | 4 +-- src/parser/common/basicParser.ts | 13 ++------ 7 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/grammar/pgsql/PostgreSQLParser.g4 b/src/grammar/pgsql/PostgreSQLParser.g4 index 3f62833..496d011 100644 --- a/src/grammar/pgsql/PostgreSQLParser.g4 +++ b/src/grammar/pgsql/PostgreSQLParser.g4 @@ -12,7 +12,7 @@ superClass = PostgreSQLParserBase; @members { } -root +program : stmtblock EOF ; diff --git a/src/lib/pgsql/PostgreSQLParser.interp b/src/lib/pgsql/PostgreSQLParser.interp index 927a331..a6f1451 100644 --- a/src/lib/pgsql/PostgreSQLParser.interp +++ b/src/lib/pgsql/PostgreSQLParser.interp @@ -1115,7 +1115,7 @@ EndDollarStringConstant AfterEscapeStringConstantWithNewlineMode_Continued rule names: -root +program plsqlroot stmtblock stmtmulti diff --git a/src/lib/pgsql/PostgreSQLParser.js b/src/lib/pgsql/PostgreSQLParser.js index 803c99b..e1352a5 100644 --- a/src/lib/pgsql/PostgreSQLParser.js +++ b/src/lib/pgsql/PostgreSQLParser.js @@ -7771,7 +7771,7 @@ var symbolicNames = [ null, "Dollar", "OPEN_PAREN", "CLOSE_PAREN", "OPEN_BRACKET "AfterEscapeStringConstantWithNewlineMode_NotContinued", "DollarText", "EndDollarStringConstant", "AfterEscapeStringConstantWithNewlineMode_Continued" ]; -var ruleNames = [ "root", "plsqlroot", "stmtblock", "stmtmulti", "stmt", +var ruleNames = [ "program", "plsqlroot", "stmtblock", "stmtmulti", "stmt", "plsqlconsolecommand", "callstmt", "createrolestmt", "opt_with", "optrolelist", "alteroptrolelist", "alteroptroleelem", "createoptroleelem", "createuserstmt", "alterrolestmt", @@ -8588,7 +8588,7 @@ PostgreSQLParser.DollarText = 553; PostgreSQLParser.EndDollarStringConstant = 554; PostgreSQLParser.AfterEscapeStringConstantWithNewlineMode_Continued = 555; -PostgreSQLParser.RULE_root = 0; +PostgreSQLParser.RULE_program = 0; PostgreSQLParser.RULE_plsqlroot = 1; PostgreSQLParser.RULE_stmtblock = 2; PostgreSQLParser.RULE_stmtmulti = 3; @@ -9394,7 +9394,7 @@ PostgreSQLParser.RULE_make_execsql_stmt = 802; PostgreSQLParser.RULE_opt_returning_clause_into = 803; -function RootContext(parser, parent, invokingState) { +function ProgramContext(parser, parent, invokingState) { if(parent===undefined) { parent = null; } @@ -9403,36 +9403,36 @@ function RootContext(parser, parent, invokingState) { } antlr4.ParserRuleContext.call(this, parent, invokingState); this.parser = parser; - this.ruleIndex = PostgreSQLParser.RULE_root; + this.ruleIndex = PostgreSQLParser.RULE_program; return this; } -RootContext.prototype = Object.create(antlr4.ParserRuleContext.prototype); -RootContext.prototype.constructor = RootContext; +ProgramContext.prototype = Object.create(antlr4.ParserRuleContext.prototype); +ProgramContext.prototype.constructor = ProgramContext; -RootContext.prototype.stmtblock = function() { +ProgramContext.prototype.stmtblock = function() { return this.getTypedRuleContext(StmtblockContext,0); }; -RootContext.prototype.EOF = function() { +ProgramContext.prototype.EOF = function() { return this.getToken(PostgreSQLParser.EOF, 0); }; -RootContext.prototype.enterRule = function(listener) { +ProgramContext.prototype.enterRule = function(listener) { if(listener instanceof PostgreSQLParserListener ) { - listener.enterRoot(this); + listener.enterProgram(this); } }; -RootContext.prototype.exitRule = function(listener) { +ProgramContext.prototype.exitRule = function(listener) { if(listener instanceof PostgreSQLParserListener ) { - listener.exitRoot(this); + listener.exitProgram(this); } }; -RootContext.prototype.accept = function(visitor) { +ProgramContext.prototype.accept = function(visitor) { if ( visitor instanceof PostgreSQLParserVisitor ) { - return visitor.visitRoot(this); + return visitor.visitProgram(this); } else { return visitor.visitChildren(this); } @@ -9441,12 +9441,12 @@ RootContext.prototype.accept = function(visitor) { -PostgreSQLParser.RootContext = RootContext; +PostgreSQLParser.ProgramContext = ProgramContext; -PostgreSQLParser.prototype.root = function() { +PostgreSQLParser.prototype.program = function() { - var localctx = new RootContext(this, this._ctx, this.state); - this.enterRule(localctx, 0, PostgreSQLParser.RULE_root); + var localctx = new ProgramContext(this, this._ctx, this.state); + this.enterRule(localctx, 0, PostgreSQLParser.RULE_program); try { this.enterOuterAlt(localctx, 1); this.state = 1608; diff --git a/src/lib/pgsql/PostgreSQLParserListener.js b/src/lib/pgsql/PostgreSQLParserListener.js index f290c2e..0d11884 100644 --- a/src/lib/pgsql/PostgreSQLParserListener.js +++ b/src/lib/pgsql/PostgreSQLParserListener.js @@ -11,12 +11,12 @@ function PostgreSQLParserListener() { PostgreSQLParserListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype); PostgreSQLParserListener.prototype.constructor = PostgreSQLParserListener; -// Enter a parse tree produced by PostgreSQLParser#root. -PostgreSQLParserListener.prototype.enterRoot = function(ctx) { +// Enter a parse tree produced by PostgreSQLParser#program. +PostgreSQLParserListener.prototype.enterProgram = function(ctx) { }; -// Exit a parse tree produced by PostgreSQLParser#root. -PostgreSQLParserListener.prototype.exitRoot = function(ctx) { +// Exit a parse tree produced by PostgreSQLParser#program. +PostgreSQLParserListener.prototype.exitProgram = function(ctx) { }; diff --git a/src/lib/pgsql/PostgreSQLParserVisitor.js b/src/lib/pgsql/PostgreSQLParserVisitor.js index 760777e..d13b0eb 100644 --- a/src/lib/pgsql/PostgreSQLParserVisitor.js +++ b/src/lib/pgsql/PostgreSQLParserVisitor.js @@ -12,8 +12,8 @@ function PostgreSQLParserVisitor() { PostgreSQLParserVisitor.prototype = Object.create(antlr4.tree.ParseTreeVisitor.prototype); PostgreSQLParserVisitor.prototype.constructor = PostgreSQLParserVisitor; -// Visit a parse tree produced by PostgreSQLParser#root. -PostgreSQLParserVisitor.prototype.visitRoot = function(ctx) { +// Visit a parse tree produced by PostgreSQLParser#program. +PostgreSQLParserVisitor.prototype.visitProgram = function(ctx) { return this.visitChildren(ctx); }; diff --git a/src/lib/pgsql/base/PostgreSQLParserBase.js b/src/lib/pgsql/base/PostgreSQLParserBase.js index adb489e..91b6263 100644 --- a/src/lib/pgsql/base/PostgreSQLParserBase.js +++ b/src/lib/pgsql/base/PostgreSQLParserBase.js @@ -16,7 +16,7 @@ export class PostgreSQLParserBase extends antlr4.Parser { GetParsedSqlTree( script, line) { const ph = this.getPostgreSQLParser(script); - return ph.root(); + return ph.program(); } ParseRoutineBody( _localctx) { @@ -58,7 +58,7 @@ export class PostgreSQLParserBase extends antlr4.Parser { func_as.func_as().Definition = ph.plsqlroot(); break; case 'sql': - func_as.func_as().Definition = ph.root(); + func_as.func_as().Definition = ph.program(); break; } } diff --git a/src/parser/common/basicParser.ts b/src/parser/common/basicParser.ts index 6158956..a105522 100644 --- a/src/parser/common/basicParser.ts +++ b/src/parser/common/basicParser.ts @@ -23,8 +23,7 @@ export default abstract class BasicParser { parser.removeErrorListeners(); parser.addErrorListener(new ParserErrorListener(errorListener)); - // Note : needed by pgsql - const parserTree = parser.program? parser.program() : parser.root(); + const parserTree = parser.program(); return parserTree; } @@ -38,12 +37,7 @@ export default abstract class BasicParser { parser.removeErrorListeners(); parser.addErrorListener(new ParserErrorCollector(syntaxErrors)); - // Note : needed by pgsql - if (parser.program) { - parser.program(); - } else { - parser.root(); - } + parser.program(); return lexerError.concat(syntaxErrors); } @@ -95,8 +89,7 @@ export default abstract class BasicParser { const parser = this.createParser(input); this._parser = parser; - // Note : needed by pgsql - const tree = parser.program? parser.program() : parser.root(); + const tree = parser.program(); return tree.toStringTree(parser.ruleNames); }