convert base to es5 - code clean
This commit is contained in:
		| @ -1,55 +0,0 @@ | |||||||
| import java.util.BitSet; |  | ||||||
| import org.antlr.v4.runtime.*; |  | ||||||
| import org.antlr.v4.runtime.atn.*; |  | ||||||
| import org.antlr.v4.runtime.dfa.*; |  | ||||||
| import org.antlr.v4.runtime.misc.*; |  | ||||||
|  |  | ||||||
| public class LexerDispatchingErrorListener implements ANTLRErrorListener |  | ||||||
| { |  | ||||||
|     Lexer _parent; |  | ||||||
|  |  | ||||||
|     public LexerDispatchingErrorListener(Lexer parent) |  | ||||||
|     { |  | ||||||
|         _parent = parent; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportAmbiguity(Parser recognizer, |  | ||||||
|                                 DFA dfa, |  | ||||||
|                                 int startIndex, |  | ||||||
|                                 int stopIndex, |  | ||||||
|                                 boolean exact, |  | ||||||
|                                 BitSet ambigAlts, |  | ||||||
|                                 ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportAttemptingFullContext(Parser recognizer, |  | ||||||
|                                             DFA dfa, |  | ||||||
|                                             int startIndex, |  | ||||||
|                                             int stopIndex, |  | ||||||
|                                             BitSet conflictingAlts, |  | ||||||
|                                             ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportContextSensitivity(Parser recognizer, |  | ||||||
|                                          DFA dfa, |  | ||||||
|                                          int startIndex, |  | ||||||
|                                          int stopIndex, |  | ||||||
|                                          int prediction, |  | ||||||
|                                          ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,55 +0,0 @@ | |||||||
| import java.util.BitSet; |  | ||||||
| import org.antlr.v4.runtime.*; |  | ||||||
| import org.antlr.v4.runtime.atn.*; |  | ||||||
| import org.antlr.v4.runtime.dfa.*; |  | ||||||
| import org.antlr.v4.runtime.misc.*; |  | ||||||
|  |  | ||||||
| public class ParserDispatchingErrorListener implements ANTLRErrorListener |  | ||||||
| { |  | ||||||
|     Parser _parent; |  | ||||||
|  |  | ||||||
|     public ParserDispatchingErrorListener(Parser parent) |  | ||||||
|     { |  | ||||||
|         _parent = parent; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportAmbiguity(Parser recognizer, |  | ||||||
|                                 DFA dfa, |  | ||||||
|                                 int startIndex, |  | ||||||
|                                 int stopIndex, |  | ||||||
|                                 boolean exact, |  | ||||||
|                                 BitSet ambigAlts, |  | ||||||
|                                 ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportAttemptingFullContext(Parser recognizer, |  | ||||||
|                                             DFA dfa, |  | ||||||
|                                             int startIndex, |  | ||||||
|                                             int stopIndex, |  | ||||||
|                                             BitSet conflictingAlts, |  | ||||||
|                                             ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void reportContextSensitivity(Parser recognizer, |  | ||||||
|                                          DFA dfa, |  | ||||||
|                                          int startIndex, |  | ||||||
|                                          int stopIndex, |  | ||||||
|                                          int prediction, |  | ||||||
|                                          ATNConfigSet configs) |  | ||||||
|     { |  | ||||||
|         var foo = new ProxyErrorListener(_parent.getErrorListeners()); |  | ||||||
|         foo.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,67 +0,0 @@ | |||||||
| const antlr4 = require('antlr4/index'); |  | ||||||
| const Lexer = antlr4.Lexer; |  | ||||||
| function isLetter(str) { |  | ||||||
|     return str.length === 1 && str.match(/[a-z]/i); |  | ||||||
| } |  | ||||||
| export class PostgreSQLLexerBase extends Lexer { |  | ||||||
|     tags = []; |  | ||||||
|  |  | ||||||
|     constructor(input) { |  | ||||||
|         super(input); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     pushTag() { |  | ||||||
|         this.tags.push(getText()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     isTag() { |  | ||||||
|         return this.getText().equals(this.tags.peek()); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     popTag() { |  | ||||||
|         tags.pop(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     getInputStream() { |  | ||||||
|         return this._input; |  | ||||||
|     } |  | ||||||
|     checkLA( c) { |  | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         return this.getInputStream().LA(1) !== c; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     charIsLetter() { |  | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         return isLetter(this.getInputStream().LA(-1)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     HandleNumericFail() { |  | ||||||
|         this.getInputStream().seek(this.getInputStream().index() - 2); |  | ||||||
|         const Integral = 535; |  | ||||||
|         this.setType(Integral); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     HandleLessLessGreaterGreater() { |  | ||||||
|         const LESS_LESS = 18; |  | ||||||
|         const GREATER_GREATER = 19; |  | ||||||
|         if (this.getText() === '<<') this.setType(LESS_LESS); |  | ||||||
|         if (this.getText() === '>>') this.setType(GREATER_GREATER); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     UnterminatedBlockCommentDebugAssert() { |  | ||||||
|         // Debug.Assert(InputStream.LA(1) == -1 /*EOF*/); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     CheckIfUtf32Letter() { |  | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         let codePoint = this.getInputStream().LA(-2) << 8 + this.getInputStream().LA(-1); |  | ||||||
|         let c; |  | ||||||
|         if (codePoint < 0x10000) { |  | ||||||
|             c = String.fromCharCode(codePoint); |  | ||||||
|         } else { |  | ||||||
|             codePoint -= 0x10000; |  | ||||||
|             c = String.fromCharCode(codePoint / 0x400 + 0xd800, codePoint % 0x400 + 0xdc00); |  | ||||||
|         } |  | ||||||
|         return isLetter(c[0]); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,114 +0,0 @@ | |||||||
| /* eslint-disable new-cap */ |  | ||||||
| import { PostgreSQLLexer } from '../PostgreSQLLexer'; |  | ||||||
| import { PostgreSQLParser } from '../PostgreSQLParser'; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| const antlr4 = require('antlr4/index'); |  | ||||||
| const CharStreams = antlr4.CharStreams; |  | ||||||
| const CommonTokenStream = antlr4.CommonTokenStream; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| // @ts-ignore |  | ||||||
| export class PostgreSQLParserBase extends antlr4.Parser { |  | ||||||
|     constructor( input) { |  | ||||||
|         super(input); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     GetParsedSqlTree( script, line) { |  | ||||||
|         const ph = this.getPostgreSQLParser(script); |  | ||||||
|         return ph.program(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     ParseRoutineBody( _localctx) { |  | ||||||
|         let lang = null; |  | ||||||
|         for (const coi of _localctx.createfunc_opt_item()) { |  | ||||||
|             // eslint-disable-next-line new-cap |  | ||||||
|             if (!coi.LANGUAGE()) { |  | ||||||
|                 if (!coi.nonreservedword_or_sconst()) { |  | ||||||
|                     if (!coi.nonreservedword_or_sconst().nonreservedword()) { |  | ||||||
|                         if (!coi.nonreservedword_or_sconst().nonreservedword().identifier()) { |  | ||||||
|                             // eslint-disable-next-line new-cap |  | ||||||
|                             if (!coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier()) { |  | ||||||
|                                 // eslint-disable-next-line new-cap |  | ||||||
|                                 lang = coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier().getText(); |  | ||||||
|                                 break; |  | ||||||
|                             } |  | ||||||
|                         } |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         if (!lang) return; |  | ||||||
|         // eslint-disable-next-line camelcase |  | ||||||
|         let func_as = null; |  | ||||||
|         for (const a of _localctx.createfunc_opt_item()) { |  | ||||||
|             if (!a.func_as()) { |  | ||||||
|                 // eslint-disable-next-line camelcase |  | ||||||
|                 func_as = a; |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         // eslint-disable-next-line camelcase |  | ||||||
|         if (!func_as) { |  | ||||||
|             const txt = this.GetRoutineBodyString(func_as.func_as().sconst(0)); |  | ||||||
|             const line = func_as.func_as().sconst(0).start.getLine(); |  | ||||||
|             const ph = this.getPostgreSQLParser(txt); |  | ||||||
|             switch (lang) { |  | ||||||
|             case 'plpgsql': |  | ||||||
|                 func_as.func_as().Definition = ph.plsqlroot(); |  | ||||||
|                 break; |  | ||||||
|             case 'sql': |  | ||||||
|                 func_as.func_as().Definition = ph.program(); |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     TrimQuotes( s) { |  | ||||||
|         return (!s) ? s : s.substring(1, s.length() - 1); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     unquote( s) { |  | ||||||
|         const slength = s.length(); |  | ||||||
|         const r = ''; |  | ||||||
|         let i = 0; |  | ||||||
|         while (i < slength) { |  | ||||||
|             const c = s.charAt(i); |  | ||||||
|             r.append(c); |  | ||||||
|             if (c === '\'' && i < slength - 1 && (s.charAt(i + 1) === '\'')) i++; |  | ||||||
|             i++; |  | ||||||
|         } |  | ||||||
|         return r.toString(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     GetRoutineBodyString( rule) { |  | ||||||
|         const anysconst = rule.anysconst(); |  | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         const StringConstant = anysconst.StringConstant(); |  | ||||||
|         if (null !== StringConstant) return this.unquote(this.TrimQuotes(StringConstant.getText())); |  | ||||||
|         const UnicodeEscapeStringConstant = anysconst.UnicodeEscapeStringConstant(); |  | ||||||
|         if (null !== UnicodeEscapeStringConstant) return this.TrimQuotes(UnicodeEscapeStringConstant.getText()); |  | ||||||
|         const EscapeStringConstant = anysconst.EscapeStringConstant(); |  | ||||||
|         if (null !== EscapeStringConstant) return this.TrimQuotes(EscapeStringConstant.getText()); |  | ||||||
|         let result = ''; |  | ||||||
|         const dollartext = anysconst.DollarText(); |  | ||||||
|         for (const s of dollartext) { |  | ||||||
|             result += s.getText(); |  | ||||||
|         } |  | ||||||
|         return result; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     static getPostgreSQLParser( script) { |  | ||||||
|         const charStream = CharStreams.fromString(script); |  | ||||||
|         const lexer = new PostgreSQLLexer(charStream); |  | ||||||
|         const tokens = new CommonTokenStream(lexer); |  | ||||||
|         const parser = new PostgreSQLParser(tokens); |  | ||||||
|         lexer.removeErrorListeners(); |  | ||||||
|         parser.removeErrorListeners(); |  | ||||||
|         //  LexerDispatchingErrorListener listener_lexer = new LexerDispatchingErrorListener((Lexer)(((CommonTokenStream)(this.getInputStream())).getTokenSource())); |  | ||||||
|         //   ParserDispatchingErrorListener listener_parser = new ParserDispatchingErrorListener(this); |  | ||||||
|         //   lexer.addErrorListener(listener_lexer); |  | ||||||
|         //  parser.addErrorListener(listener_parser); |  | ||||||
|         return parser; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,82 +1,101 @@ | |||||||
| "use strict"; | // https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/Java/PostgreSQLLexerBase.java | ||||||
| var __extends = (this && this.__extends) || (function () { |  | ||||||
|     var extendStatics = function (d, b) { | // eslint-disable-next-line no-invalid-this | ||||||
|  | const __extends = (this && this.__extends) || (function() { | ||||||
|  |     let extendStatics = function(d, b) { | ||||||
|         extendStatics = Object.setPrototypeOf || |         extendStatics = Object.setPrototypeOf || | ||||||
|             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |             ({ __proto__: [] } instanceof Array && function(d, b) { | ||||||
|             function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |                 d.__proto__ = b; | ||||||
|  |             }) || | ||||||
|  |             function(d, b) { | ||||||
|  |                 for (const p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; | ||||||
|  |             }; | ||||||
|         return extendStatics(d, b); |         return extendStatics(d, b); | ||||||
|     }; |     }; | ||||||
|     return function (d, b) { |     return function(d, b) { | ||||||
|         if (typeof b !== "function" && b !== null) |         if (typeof b !== 'function' && b !== null) { | ||||||
|             throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |             throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null'); | ||||||
|  |         } | ||||||
|         extendStatics(d, b); |         extendStatics(d, b); | ||||||
|         function __() { this.constructor = d; } |         function __() { | ||||||
|  |             this.constructor = d; | ||||||
|  |         } | ||||||
|         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||||||
|     }; |     }; | ||||||
| })(); | })(); | ||||||
| Object.defineProperty(exports, "__esModule", { value: true }); |  | ||||||
| exports.PostgreSQLLexerBase = void 0; | const Lexer = require('antlr4').Lexer; | ||||||
| var antlr4 = require('antlr4/index'); |  | ||||||
| var Lexer = antlr4.Lexer; |  | ||||||
| function isLetter(str) { | function isLetter(str) { | ||||||
|     return str.length === 1 && str.match(/[a-z]/i); |     return str.length === 1 && str.match(/[a-z]/i); | ||||||
| } | } | ||||||
| var PostgreSQLLexerBase = /** @class */ (function (_super) { |  | ||||||
|     __extends(PostgreSQLLexerBase, _super); | function PostgreSQLLexerBase(input) { | ||||||
|     function PostgreSQLLexerBase(input) { |     const _this = Lexer.call(this, input) || this; | ||||||
|         var _this = _super.call(this, input) || this; |     _this.tags = []; | ||||||
|         _this.tags = []; |     return _this; | ||||||
|         return _this; | } | ||||||
|  |  | ||||||
|  | __extends(PostgreSQLLexerBase, Lexer); | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.pushTag = function() { | ||||||
|  |     this.tags.push(getText()); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.isTag = function() { | ||||||
|  |     return this.getText().equals(this.tags.peek()); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.popTag = function() { | ||||||
|  |     this.tags.pop(); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.getInputStream = function() { | ||||||
|  |     return this._input; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.checkLA = function(c) { | ||||||
|  |     // eslint-disable-next-line new-cap | ||||||
|  |     return this.getInputStream().LA(1) !== c; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.charIsLetter = function() { | ||||||
|  |     // eslint-disable-next-line new-cap | ||||||
|  |     return isLetter(this.getInputStream().LA(-1)); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.HandleNumericFail = function() { | ||||||
|  |     this.getInputStream().seek(this.getInputStream().index() - 2); | ||||||
|  |     const Integral = 535; | ||||||
|  |     this.setType(Integral); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | PostgreSQLLexerBase.prototype.HandleLessLessGreaterGreater = function() { | ||||||
|  |     const LESS_LESS = 18; | ||||||
|  |     const GREATER_GREATER = 19; | ||||||
|  |     if (this.getText() === '<<') { | ||||||
|  |         this.setType(LESS_LESS); | ||||||
|     } |     } | ||||||
|     PostgreSQLLexerBase.prototype.pushTag = function () { |     if (this.getText() === '>>') { | ||||||
|         this.tags.push(getText()); |         this.setType(GREATER_GREATER); | ||||||
|     }; |     } | ||||||
|     PostgreSQLLexerBase.prototype.isTag = function () { | }; | ||||||
|         return this.getText().equals(this.tags.peek()); |  | ||||||
|     }; | PostgreSQLLexerBase.prototype.UnterminatedBlockCommentDebugAssert = function() { | ||||||
|     PostgreSQLLexerBase.prototype.popTag = function () { |     // Debug.Assert(InputStream.LA(1) == -1 /*EOF*/); | ||||||
|         tags.pop(); | }; | ||||||
|     }; |  | ||||||
|     PostgreSQLLexerBase.prototype.getInputStream = function () { | PostgreSQLLexerBase.prototype.CheckIfUtf32Letter = function() { | ||||||
|         return this._input; |     // eslint-disable-next-line new-cap | ||||||
|     }; |     let codePoint = this.getInputStream().LA(-2) << 8 + this.getInputStream().LA(-1); | ||||||
|     PostgreSQLLexerBase.prototype.checkLA = function (c) { |     let c; | ||||||
|         // eslint-disable-next-line new-cap |     if (codePoint < 0x10000) { | ||||||
|         return this.getInputStream().LA(1) !== c; |         c = String.fromCharCode(codePoint); | ||||||
|     }; |     } else { | ||||||
|     PostgreSQLLexerBase.prototype.charIsLetter = function () { |         codePoint -= 0x10000; | ||||||
|         // eslint-disable-next-line new-cap |         c = String.fromCharCode(codePoint / 0x400 + 0xd800, codePoint % 0x400 + 0xdc00); | ||||||
|         return isLetter(this.getInputStream().LA(-1)); |     } | ||||||
|     }; |     return isLetter(c[0]); | ||||||
|     PostgreSQLLexerBase.prototype.HandleNumericFail = function () { | }; | ||||||
|         this.getInputStream().seek(this.getInputStream().index() - 2); |  | ||||||
|         var Integral = 535; | exports.PostgreSQLLexerBase = PostgreSQLLexerBase; | ||||||
|         this.setType(Integral); |  | ||||||
|     }; |  | ||||||
|     PostgreSQLLexerBase.prototype.HandleLessLessGreaterGreater = function () { |  | ||||||
|         var LESS_LESS = 18; |  | ||||||
|         var GREATER_GREATER = 19; |  | ||||||
|         if (this.getText() === '<<') |  | ||||||
|             this.setType(LESS_LESS); |  | ||||||
|         if (this.getText() === '>>') |  | ||||||
|             this.setType(GREATER_GREATER); |  | ||||||
|     }; |  | ||||||
|     PostgreSQLLexerBase.prototype.UnterminatedBlockCommentDebugAssert = function () { |  | ||||||
|         // Debug.Assert(InputStream.LA(1) == -1 /*EOF*/); |  | ||||||
|     }; |  | ||||||
|     PostgreSQLLexerBase.prototype.CheckIfUtf32Letter = function () { |  | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         var codePoint = this.getInputStream().LA(-2) << 8 + this.getInputStream().LA(-1); |  | ||||||
|         var c; |  | ||||||
|         if (codePoint < 0x10000) { |  | ||||||
|             c = String.fromCharCode(codePoint); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             codePoint -= 0x10000; |  | ||||||
|             c = String.fromCharCode(codePoint / 0x400 + 0xd800, codePoint % 0x400 + 0xdc00); |  | ||||||
|         } |  | ||||||
|         return isLetter(c[0]); |  | ||||||
|     }; |  | ||||||
|     return PostgreSQLLexerBase; |  | ||||||
| }(Lexer)); |  | ||||||
| exports.PostgreSQLLexerBase = PostgreSQLLexerBase; |  | ||||||
|  | |||||||
| @ -1,133 +1,149 @@ | |||||||
| "use strict"; | /* eslint-disable new-cap,camelcase */ | ||||||
| var __extends = (this && this.__extends) || (function () { |  | ||||||
|     var extendStatics = function (d, b) { | // https://github.com/antlr/grammars-v4/blob/master/sql/postgresql/Java/PostgreSQLParserBase.java | ||||||
|  | // eslint-disable-next-line no-invalid-this | ||||||
|  | const __extends = (this && this.__extends) || (function() { | ||||||
|  |     let extendStatics = function(d, b) { | ||||||
|         extendStatics = Object.setPrototypeOf || |         extendStatics = Object.setPrototypeOf || | ||||||
|             ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |             ({ __proto__: [] } instanceof Array && function(d, b) { | ||||||
|             function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |                 d.__proto__ = b; | ||||||
|  |             }) || | ||||||
|  |             function(d, b) { | ||||||
|  |                 for (const p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; | ||||||
|  |             }; | ||||||
|         return extendStatics(d, b); |         return extendStatics(d, b); | ||||||
|     }; |     }; | ||||||
|     return function (d, b) { |     return function(d, b) { | ||||||
|         if (typeof b !== "function" && b !== null) |         if (typeof b !== 'function' && b !== null) { | ||||||
|             throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |             throw new TypeError('Class extends value ' + String(b) + ' is not a constructor or null'); | ||||||
|  |         } | ||||||
|         extendStatics(d, b); |         extendStatics(d, b); | ||||||
|         function __() { this.constructor = d; } |         function __() { | ||||||
|  |             this.constructor = d; | ||||||
|  |         } | ||||||
|         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |         d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||||||
|     }; |     }; | ||||||
| })(); | })(); | ||||||
| Object.defineProperty(exports, "__esModule", { value: true }); |  | ||||||
| exports.PostgreSQLParserBase = void 0; | const PostgreSQLLexer_1 = require('../PostgreSQLLexer'); | ||||||
| /* eslint-disable new-cap */ | const PostgreSQLParser_1 = require('../PostgreSQLParser'); | ||||||
| var PostgreSQLLexer_1 = require("../PostgreSQLLexer"); |  | ||||||
| var PostgreSQLParser_1 = require("../PostgreSQLParser"); | const antlr4 = require('antlr4/index'); | ||||||
| var antlr4 = require('antlr4/index'); | const CharStreams = antlr4.CharStreams; | ||||||
| var CharStreams = antlr4.CharStreams; | const CommonTokenStream = antlr4.CommonTokenStream; | ||||||
| var CommonTokenStream = antlr4.CommonTokenStream; | const Parser = antlr4.Parser; | ||||||
| // @ts-ignore |  | ||||||
| var PostgreSQLParserBase = /** @class */ (function (_super) { | __extends(PostgreSQLParserBase, Parser); | ||||||
|     __extends(PostgreSQLParserBase, _super); |  | ||||||
|     function PostgreSQLParserBase(input) { | function PostgreSQLParserBase(input) { | ||||||
|         return _super.call(this, input) || this; |     return Parser.call(this, input) || this; | ||||||
|     } | } | ||||||
|     PostgreSQLParserBase.prototype.GetParsedSqlTree = function (script, line) { |  | ||||||
|         var ph = this.getPostgreSQLParser(script); | PostgreSQLParserBase.prototype.GetParsedSqlTree = function(script, line) { | ||||||
|         return ph.program(); |     const ph = this.getPostgreSQLParser(script); | ||||||
|     }; |     return ph.program(); | ||||||
|     PostgreSQLParserBase.prototype.ParseRoutineBody = function (_localctx) { | }; | ||||||
|         var lang = null; |  | ||||||
|         for (var _i = 0, _a = _localctx.createfunc_opt_item(); _i < _a.length; _i++) { | PostgreSQLParserBase.prototype.ParseRoutineBody = function(_localctx) { | ||||||
|             var coi = _a[_i]; |     let lang = null; | ||||||
|             // eslint-disable-next-line new-cap |     for (let _i = 0, _a = _localctx.createfunc_opt_item(); _i < _a.length; _i++) { | ||||||
|             if (!coi.LANGUAGE()) { |         const coi = _a[_i]; | ||||||
|                 if (!coi.nonreservedword_or_sconst()) { |         if (!!coi.LANGUAGE()) { | ||||||
|                     if (!coi.nonreservedword_or_sconst().nonreservedword()) { |             if (!!coi.nonreservedword_or_sconst()) { | ||||||
|                         if (!coi.nonreservedword_or_sconst().nonreservedword().identifier()) { |                 if (!!coi.nonreservedword_or_sconst().nonreservedword()) { | ||||||
|                             // eslint-disable-next-line new-cap |                     if (!!coi.nonreservedword_or_sconst().nonreservedword().identifier()) { | ||||||
|                             if (!coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier()) { |                         if (!!coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier()) { | ||||||
|                                 // eslint-disable-next-line new-cap |                             lang = coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier().getText(); | ||||||
|                                 lang = coi.nonreservedword_or_sconst().nonreservedword().identifier().Identifier().getText(); |                             break; | ||||||
|                                 break; |  | ||||||
|                             } |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (!lang) |     } | ||||||
|             return; |     if (!lang) { | ||||||
|         // eslint-disable-next-line camelcase |         return; | ||||||
|         var func_as = null; |     } | ||||||
|         for (var _b = 0, _c = _localctx.createfunc_opt_item(); _b < _c.length; _b++) { |     // eslint-disable-next-line camelcase | ||||||
|             var a = _c[_b]; |     let func_as = null; | ||||||
|             if (!a.func_as()) { |     for (let _b = 0, _c = _localctx.createfunc_opt_item(); _b < _c.length; _b++) { | ||||||
|                 // eslint-disable-next-line camelcase |         const a = _c[_b]; | ||||||
|                 func_as = a; |         if (!a.func_as()) { | ||||||
|                 break; |             // eslint-disable-next-line camelcase | ||||||
|             } |             func_as = a; | ||||||
|  |             break; | ||||||
|         } |         } | ||||||
|         // eslint-disable-next-line camelcase |     } | ||||||
|         if (!func_as) { |     // eslint-disable-next-line camelcase | ||||||
|             var txt = this.GetRoutineBodyString(func_as.func_as().sconst(0)); |     if (!!func_as) { | ||||||
|             var line = func_as.func_as().sconst(0).start.getLine(); |         const txt = this.GetRoutineBodyString(func_as.func_as().sconst(0)); | ||||||
|             var ph = this.getPostgreSQLParser(txt); |         const line = func_as.func_as().sconst(0).start.getLine(); | ||||||
|             switch (lang) { |         const ph = this.getPostgreSQLParser(txt); | ||||||
|                 case 'plpgsql': |         switch (lang) { | ||||||
|                     func_as.func_as().Definition = ph.plsqlroot(); |         case 'plpgsql': | ||||||
|                     break; |             func_as.func_as().Definition = ph.plsqlroot(); | ||||||
|                 case 'sql': |             break; | ||||||
|                     func_as.func_as().Definition = ph.program(); |         case 'sql': | ||||||
|                     break; |             func_as.func_as().Definition = ph.program(); | ||||||
|             } |             break; | ||||||
|         } |         } | ||||||
|     }; |     } | ||||||
|     PostgreSQLParserBase.prototype.TrimQuotes = function (s) { | }; | ||||||
|         return (!s) ? s : s.substring(1, s.length() - 1); |  | ||||||
|     }; | PostgreSQLParserBase.prototype.TrimQuotes = function(s) { | ||||||
|     PostgreSQLParserBase.prototype.unquote = function (s) { |     return (!s) ? s : s.substring(1, s.length() - 1); | ||||||
|         var slength = s.length(); | }; | ||||||
|         var r = ''; |  | ||||||
|         var i = 0; | PostgreSQLParserBase.prototype.unquote = function(s) { | ||||||
|         while (i < slength) { |     const slength = s.length(); | ||||||
|             var c = s.charAt(i); |     const r = ''; | ||||||
|             r.append(c); |     let i = 0; | ||||||
|             if (c === '\'' && i < slength - 1 && (s.charAt(i + 1) === '\'')) |     while (i < slength) { | ||||||
|                 i++; |         const c = s.charAt(i); | ||||||
|  |         r.append(c); | ||||||
|  |         if (c === '\'' && i < slength - 1 && (s.charAt(i + 1) === '\'')) { | ||||||
|             i++; |             i++; | ||||||
|         } |         } | ||||||
|         return r.toString(); |         i++; | ||||||
|     }; |     } | ||||||
|     PostgreSQLParserBase.prototype.GetRoutineBodyString = function (rule) { |     return r.toString(); | ||||||
|         var anysconst = rule.anysconst(); | }; | ||||||
|         // eslint-disable-next-line new-cap |  | ||||||
|         var StringConstant = anysconst.StringConstant(); | PostgreSQLParserBase.prototype.GetRoutineBodyString = function(rule) { | ||||||
|         if (null !== StringConstant) |     const anysconst = rule.anysconst(); | ||||||
|             return this.unquote(this.TrimQuotes(StringConstant.getText())); |     const StringConstant = anysconst.StringConstant(); | ||||||
|         var UnicodeEscapeStringConstant = anysconst.UnicodeEscapeStringConstant(); |     if (!!StringConstant) { | ||||||
|         if (null !== UnicodeEscapeStringConstant) |         return this.unquote(this.TrimQuotes(StringConstant.getText())); | ||||||
|             return this.TrimQuotes(UnicodeEscapeStringConstant.getText()); |     } | ||||||
|         var EscapeStringConstant = anysconst.EscapeStringConstant(); |     const UnicodeEscapeStringConstant = anysconst.UnicodeEscapeStringConstant(); | ||||||
|         if (null !== EscapeStringConstant) |     if (!!UnicodeEscapeStringConstant) { | ||||||
|             return this.TrimQuotes(EscapeStringConstant.getText()); |         return this.TrimQuotes(UnicodeEscapeStringConstant.getText()); | ||||||
|         var result = ''; |     } | ||||||
|         var dollartext = anysconst.DollarText(); |     const EscapeStringConstant = anysconst.EscapeStringConstant(); | ||||||
|         for (var _i = 0, dollartext_1 = dollartext; _i < dollartext_1.length; _i++) { |     if (!!EscapeStringConstant) { | ||||||
|             var s = dollartext_1[_i]; |         return this.TrimQuotes(EscapeStringConstant.getText()); | ||||||
|             result += s.getText(); |     } | ||||||
|         } |     let result = ''; | ||||||
|         return result; |     const dollartext = anysconst.DollarText(); | ||||||
|     }; |     for (let _i = 0, dollartext_1 = dollartext; _i < dollartext_1.length; _i++) { | ||||||
|     PostgreSQLParserBase.getPostgreSQLParser = function (script) { |         const s = dollartext_1[_i]; | ||||||
|         var charStream = CharStreams.fromString(script); |         result += s.getText(); | ||||||
|         var lexer = new PostgreSQLLexer_1.PostgreSQLLexer(charStream); |     } | ||||||
|         var tokens = new CommonTokenStream(lexer); |     return result; | ||||||
|         var parser = new PostgreSQLParser_1.PostgreSQLParser(tokens); | }; | ||||||
|         lexer.removeErrorListeners(); |  | ||||||
|         parser.removeErrorListeners(); | PostgreSQLParserBase.getPostgreSQLParser = function(script) { | ||||||
|         //  LexerDispatchingErrorListener listener_lexer = new LexerDispatchingErrorListener((Lexer)(((CommonTokenStream)(this.getInputStream())).getTokenSource())); |     const charStream = CharStreams.fromString(script); | ||||||
|         //   ParserDispatchingErrorListener listener_parser = new ParserDispatchingErrorListener(this); |     const lexer = new PostgreSQLLexer_1.PostgreSQLLexer(charStream); | ||||||
|         //   lexer.addErrorListener(listener_lexer); |     const tokens = new CommonTokenStream(lexer); | ||||||
|         //  parser.addErrorListener(listener_parser); |     const parser = new PostgreSQLParser_1.PostgreSQLParser(tokens); | ||||||
|         return parser; |     lexer.removeErrorListeners(); | ||||||
|     }; |     parser.removeErrorListeners(); | ||||||
|     return PostgreSQLParserBase; |     //  LexerDispatchingErrorListener listener_lexer = new LexerDispatchingErrorListener((Lexer)(((CommonTokenStream)(this.getInputStream())).getTokenSource())); | ||||||
| }(antlr4.Parser)); |     //   ParserDispatchingErrorListener listener_parser = new ParserDispatchingErrorListener(this); | ||||||
| exports.PostgreSQLParserBase = PostgreSQLParserBase; |     //   lexer.addErrorListener(listener_lexer); | ||||||
|  |     //  parser.addErrorListener(listener_parser); | ||||||
|  |     return parser; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | exports.PostgreSQLParserBase = PostgreSQLParserBase; | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user