UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

42 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const antlr4ts_1 = require("antlr4ts"); const SqlBaseLexer_1 = require("./SqlBaseLexer"); const SqlBaseParser_1 = require("./SqlBaseParser"); const UppercaseCharStream_1 = require("./UppercaseCharStream"); const Cursor_1 = require("./Cursor"); const SqlCompletionParseTree_1 = require("./SqlCompletionParseTree"); const SqlLineageParseTree_1 = require("./SqlLineageParseTree"); const defaultCursor = new Cursor_1.Cursor("_CURSOR_"); function parse(sql, options) { var _a; const doubleQuotedIdentifier = (_a = options === null || options === void 0 ? void 0 : options.doubleQuotedIdentifier) !== null && _a !== void 0 ? _a : false; if (options !== undefined && SqlCompletionParseTree_1.isCompletionOptions(options)) { sql = defaultCursor.insertAt(sql, options.cursorPosition); } const inputStream = new UppercaseCharStream_1.UppercaseCharStream(antlr4ts_1.CharStreams.fromString(sql)); const lexer = new SqlBaseLexer_1.SqlBaseLexer(inputStream); lexer.doublequoted_identifier = doubleQuotedIdentifier; const tokens = new antlr4ts_1.CommonTokenStream(lexer); const parser = new SqlBaseParser_1.SqlBaseParser(tokens); parser.doublequoted_identifier = doubleQuotedIdentifier; parser.buildParseTree = true; parser.removeErrorListeners(); if (options !== undefined && SqlCompletionParseTree_1.isCompletionOptions(options)) { return new SqlCompletionParseTree_1.SqlCompletionParseTree(parser.statement(), defaultCursor); } else { return new SqlLineageParseTree_1.SqlLineageParseTree(parser.statement()); } } const antlr = { /** * Parses SQL text and builds parse tree suitable for further analysis and operations. * @param sql SQL text * @param options Options affecting parsing * @returns Parsed SQL tree object with the number of possible operations */ parse }; exports.default = antlr; //# sourceMappingURL=index.js.map