change to ts
This commit is contained in:
		
							
								
								
									
										1531
									
								
								core/astParser.js
									
									
									
									
									
								
							
							
						
						
									
										1531
									
								
								core/astParser.js
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -1,12 +0,0 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
class Cache extends Map {
 | 
					 | 
				
			||||||
    constructor(options){
 | 
					 | 
				
			||||||
        super(...arguments)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    set(key,value){
 | 
					 | 
				
			||||||
        super.set(key,value);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports=Cache;
 | 
					 | 
				
			||||||
@ -1,9 +0,0 @@
 | 
				
			|||||||
<html>
 | 
					 | 
				
			||||||
    <head>
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
    </head>
 | 
					 | 
				
			||||||
<body>
 | 
					 | 
				
			||||||
    1
 | 
					 | 
				
			||||||
</body>
 | 
					 | 
				
			||||||
<script src="./sqlSyntaxParser.js"></script>
 | 
					 | 
				
			||||||
</html>
 | 
					 | 
				
			||||||
							
								
								
									
										7
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								index.js
									
									
									
									
									
								
							@ -1,7 +0,0 @@
 | 
				
			|||||||
const parser = require("./lib/parser");
 | 
					 | 
				
			||||||
const filter = require("./lib/filter");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports={
 | 
					 | 
				
			||||||
    parser,
 | 
					 | 
				
			||||||
    filter
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										521
									
								
								lib/core/comment.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										521
									
								
								lib/core/comment.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,521 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Generated by PEG.js 0.10.0.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * http://pegjs.org/
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					(function (root, factory) {
 | 
				
			||||||
 | 
					    if (typeof define === "function" && define.amd) {
 | 
				
			||||||
 | 
					        define([], factory);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (typeof module === "object" && module.exports) {
 | 
				
			||||||
 | 
					        module.exports = factory();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					})(this, function () {
 | 
				
			||||||
 | 
					    "use strict";
 | 
				
			||||||
 | 
					    function peg$subclass(child, parent) {
 | 
				
			||||||
 | 
					        function ctor() { this.constructor = child; }
 | 
				
			||||||
 | 
					        ctor.prototype = parent.prototype;
 | 
				
			||||||
 | 
					        child.prototype = new ctor();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    function peg$SyntaxError(message, expected, found, location) {
 | 
				
			||||||
 | 
					        this.message = message;
 | 
				
			||||||
 | 
					        this.expected = expected;
 | 
				
			||||||
 | 
					        this.found = found;
 | 
				
			||||||
 | 
					        this.location = location;
 | 
				
			||||||
 | 
					        this.name = "SyntaxError";
 | 
				
			||||||
 | 
					        if (typeof Error.captureStackTrace === "function") {
 | 
				
			||||||
 | 
					            Error.captureStackTrace(this, peg$SyntaxError);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    peg$subclass(peg$SyntaxError, Error);
 | 
				
			||||||
 | 
					    peg$SyntaxError.buildMessage = function (expected, found) {
 | 
				
			||||||
 | 
					        var DESCRIBE_EXPECTATION_FNS = {
 | 
				
			||||||
 | 
					            literal: function (expectation) {
 | 
				
			||||||
 | 
					                return "\"" + literalEscape(expectation.text) + "\"";
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            "class": function (expectation) {
 | 
				
			||||||
 | 
					                var escapedParts = "", i;
 | 
				
			||||||
 | 
					                for (i = 0; i < expectation.parts.length; i++) {
 | 
				
			||||||
 | 
					                    escapedParts += expectation.parts[i] instanceof Array
 | 
				
			||||||
 | 
					                        ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])
 | 
				
			||||||
 | 
					                        : classEscape(expectation.parts[i]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            any: function (expectation) {
 | 
				
			||||||
 | 
					                return "any character";
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            end: function (expectation) {
 | 
				
			||||||
 | 
					                return "end of input";
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            other: function (expectation) {
 | 
				
			||||||
 | 
					                return expectation.description;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        function hex(ch) {
 | 
				
			||||||
 | 
					            return ch.charCodeAt(0).toString(16).toUpperCase();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function literalEscape(s) {
 | 
				
			||||||
 | 
					            return s
 | 
				
			||||||
 | 
					                .replace(/\\/g, '\\\\')
 | 
				
			||||||
 | 
					                .replace(/"/g, '\\"')
 | 
				
			||||||
 | 
					                .replace(/\0/g, '\\0')
 | 
				
			||||||
 | 
					                .replace(/\t/g, '\\t')
 | 
				
			||||||
 | 
					                .replace(/\n/g, '\\n')
 | 
				
			||||||
 | 
					                .replace(/\r/g, '\\r')
 | 
				
			||||||
 | 
					                .replace(/[\x00-\x0F]/g, function (ch) { return '\\x0' + hex(ch); })
 | 
				
			||||||
 | 
					                .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return '\\x' + hex(ch); });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function classEscape(s) {
 | 
				
			||||||
 | 
					            return s
 | 
				
			||||||
 | 
					                .replace(/\\/g, '\\\\')
 | 
				
			||||||
 | 
					                .replace(/\]/g, '\\]')
 | 
				
			||||||
 | 
					                .replace(/\^/g, '\\^')
 | 
				
			||||||
 | 
					                .replace(/-/g, '\\-')
 | 
				
			||||||
 | 
					                .replace(/\0/g, '\\0')
 | 
				
			||||||
 | 
					                .replace(/\t/g, '\\t')
 | 
				
			||||||
 | 
					                .replace(/\n/g, '\\n')
 | 
				
			||||||
 | 
					                .replace(/\r/g, '\\r')
 | 
				
			||||||
 | 
					                .replace(/[\x00-\x0F]/g, function (ch) { return '\\x0' + hex(ch); })
 | 
				
			||||||
 | 
					                .replace(/[\x10-\x1F\x7F-\x9F]/g, function (ch) { return '\\x' + hex(ch); });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function describeExpectation(expectation) {
 | 
				
			||||||
 | 
					            return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function describeExpected(expected) {
 | 
				
			||||||
 | 
					            var descriptions = new Array(expected.length), i, j;
 | 
				
			||||||
 | 
					            for (i = 0; i < expected.length; i++) {
 | 
				
			||||||
 | 
					                descriptions[i] = describeExpectation(expected[i]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            descriptions.sort();
 | 
				
			||||||
 | 
					            if (descriptions.length > 0) {
 | 
				
			||||||
 | 
					                for (i = 1, j = 1; i < descriptions.length; i++) {
 | 
				
			||||||
 | 
					                    if (descriptions[i - 1] !== descriptions[i]) {
 | 
				
			||||||
 | 
					                        descriptions[j] = descriptions[i];
 | 
				
			||||||
 | 
					                        j++;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                descriptions.length = j;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            switch (descriptions.length) {
 | 
				
			||||||
 | 
					                case 1:
 | 
				
			||||||
 | 
					                    return descriptions[0];
 | 
				
			||||||
 | 
					                case 2:
 | 
				
			||||||
 | 
					                    return descriptions[0] + " or " + descriptions[1];
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                    return descriptions.slice(0, -1).join(", ")
 | 
				
			||||||
 | 
					                        + ", or "
 | 
				
			||||||
 | 
					                        + descriptions[descriptions.length - 1];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function describeFound(found) {
 | 
				
			||||||
 | 
					            return found ? "\"" + literalEscape(found) + "\"" : "end of input";
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    function peg$parse(input, options) {
 | 
				
			||||||
 | 
					        options = options !== void 0 ? options : {};
 | 
				
			||||||
 | 
					        var peg$FAILED = {}, peg$startRuleIndices = { start: 0 }, peg$startRuleIndex = 0, peg$consts = [
 | 
				
			||||||
 | 
					            function (union_stmt) {
 | 
				
			||||||
 | 
					                return { lines, text: union_stmt };
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            peg$anyExpectation(),
 | 
				
			||||||
 | 
					            function (word) { return word; },
 | 
				
			||||||
 | 
					            function (words, comment) { return ''; },
 | 
				
			||||||
 | 
					            function (words, quote) { return quote; },
 | 
				
			||||||
 | 
					            ";",
 | 
				
			||||||
 | 
					            peg$literalExpectation(";", false),
 | 
				
			||||||
 | 
					            function (words) { isSplit = true; return ";"; },
 | 
				
			||||||
 | 
					            function (words, stmt) {
 | 
				
			||||||
 | 
					                const text = words.join("") + stmt;
 | 
				
			||||||
 | 
					                let index = Math.max(lines.length - 1, 0);
 | 
				
			||||||
 | 
					                lines[index] = (lines[index] || '') + text;
 | 
				
			||||||
 | 
					                if (isSplit) {
 | 
				
			||||||
 | 
					                    isSplit = false;
 | 
				
			||||||
 | 
					                    lines.push('');
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return text;
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            function (stmt, other) {
 | 
				
			||||||
 | 
					                const text = stmt.join("") + other.join("");
 | 
				
			||||||
 | 
					                let index = Math.max(lines.length - 1, 0);
 | 
				
			||||||
 | 
					                lines[index] = lines[index] + other.join("");
 | 
				
			||||||
 | 
					                return text;
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            function (comment) {
 | 
				
			||||||
 | 
					                return comment;
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            /^[^\r\n]/,
 | 
				
			||||||
 | 
					            peg$classExpectation(["\r", "\n"], true, false),
 | 
				
			||||||
 | 
					            function (start, words) {
 | 
				
			||||||
 | 
					                return start + words.join("");
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            "*/",
 | 
				
			||||||
 | 
					            peg$literalExpectation("*/", false),
 | 
				
			||||||
 | 
					            function (start, word) { return word; },
 | 
				
			||||||
 | 
					            function (start, words, end) { return start + words.join("") + end; },
 | 
				
			||||||
 | 
					            "\"",
 | 
				
			||||||
 | 
					            peg$literalExpectation("\"", false),
 | 
				
			||||||
 | 
					            /^[^"]/,
 | 
				
			||||||
 | 
					            peg$classExpectation(["\""], true, false),
 | 
				
			||||||
 | 
					            function (start, words, end) { return start + words.join("") + end; },
 | 
				
			||||||
 | 
					            "'",
 | 
				
			||||||
 | 
					            peg$literalExpectation("'", false),
 | 
				
			||||||
 | 
					            /^[^']/,
 | 
				
			||||||
 | 
					            peg$classExpectation(["'"], true, false),
 | 
				
			||||||
 | 
					            "--",
 | 
				
			||||||
 | 
					            peg$literalExpectation("--", false),
 | 
				
			||||||
 | 
					            /^[\r\n]/,
 | 
				
			||||||
 | 
					            peg$classExpectation(["\r", "\n"], false, false),
 | 
				
			||||||
 | 
					            "/*",
 | 
				
			||||||
 | 
					            peg$literalExpectation("/*", false),
 | 
				
			||||||
 | 
					            /^[ \t\r\n]/,
 | 
				
			||||||
 | 
					            peg$classExpectation([" ", "\t", "\r", "\n"], false, false)
 | 
				
			||||||
 | 
					        ], peg$bytecode = [
 | 
				
			||||||
 | 
					            peg$decode("%;!/' 8!: !! )"),
 | 
				
			||||||
 | 
					            peg$decode("%$%$%%<;&=.##&&!&'#/6#1\"\"5!7!/($8\":\"\"! )(\"'#&'#0L*%%<;&=.##&&!&'#/6#1\"\"5!7!/($8\":\"\"! )(\"'#&'#&/j#%;\"/( 8!:#!\"\" ).H &%;%/( 8!:$!\"\" ).5 &%2%\"\"6%7&/' 8!:'!!\")/)$8\":(\"\"! )(\"'#&'#0\xCD*%$%%<;&=.##&&!&'#/6#1\"\"5!7!/($8\":\"\"! )(\"'#&'#0L*%%<;&=.##&&!&'#/6#1\"\"5!7!/($8\":\"\"! )(\"'#&'#&/j#%;\"/( 8!:#!\"\" ).H &%;%/( 8!:$!\"\" ).5 &%2%\"\"6%7&/' 8!:'!!\")/)$8\":(\"\"! )(\"'#&'#&/C#$1\"\"5!7!0(*1\"\"5!7!&/)$8\":)\"\"! )(\"'#&'#"),
 | 
				
			||||||
 | 
					            peg$decode("%;$.# &;#/' 8!:*!! )"),
 | 
				
			||||||
 | 
					            peg$decode("%;'/E#$4+\"\"5!7,0)*4+\"\"5!7,&/)$8\":-\"\"! )(\"'#&'#"),
 | 
				
			||||||
 | 
					            peg$decode("%;)/\xA3#$%%<2.\"\"6.7/=.##&&!&'#/7#1\"\"5!7!/)$8\":0\"\"$ )(\"'#&'#0S*%%<2.\"\"6.7/=.##&&!&'#/7#1\"\"5!7!/)$8\":0\"\"$ )(\"'#&'#&/3$;*/*$8#:1##\"! )(#'#(\"'#&'#"),
 | 
				
			||||||
 | 
					            peg$decode("%22\"\"6273/U#$44\"\"5!750)*44\"\"5!75&/9$22\"\"6273/*$8#:6##\"! )(#'#(\"'#&'#.e &%27\"\"6778/U#$49\"\"5!7:0)*49\"\"5!7:&/9$27\"\"6778/*$8#:6##\"! )(#'#(\"'#&'#"),
 | 
				
			||||||
 | 
					            peg$decode(";'.G &;).A &22\"\"6273.5 &27\"\"6778.) &2%\"\"6%7&"),
 | 
				
			||||||
 | 
					            peg$decode("2;\"\"6;7<"),
 | 
				
			||||||
 | 
					            peg$decode("4=\"\"5!7>"),
 | 
				
			||||||
 | 
					            peg$decode("2?\"\"6?7@"),
 | 
				
			||||||
 | 
					            peg$decode("2.\"\"6.7/"),
 | 
				
			||||||
 | 
					            peg$decode("$;,0#*;,&"),
 | 
				
			||||||
 | 
					            peg$decode("4A\"\"5!7B")
 | 
				
			||||||
 | 
					        ], peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result;
 | 
				
			||||||
 | 
					        if ("startRule" in options) {
 | 
				
			||||||
 | 
					            if (!(options.startRule in peg$startRuleIndices)) {
 | 
				
			||||||
 | 
					                throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            peg$startRuleIndex = peg$startRuleIndices[options.startRule];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function text() {
 | 
				
			||||||
 | 
					            return input.substring(peg$savedPos, peg$currPos);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function location() {
 | 
				
			||||||
 | 
					            return peg$computeLocation(peg$savedPos, peg$currPos);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function expected(description, location) {
 | 
				
			||||||
 | 
					            location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
 | 
				
			||||||
 | 
					            throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function error(message, location) {
 | 
				
			||||||
 | 
					            location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos);
 | 
				
			||||||
 | 
					            throw peg$buildSimpleError(message, location);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$literalExpectation(text, ignoreCase) {
 | 
				
			||||||
 | 
					            return { type: "literal", text: text, ignoreCase: ignoreCase };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$classExpectation(parts, inverted, ignoreCase) {
 | 
				
			||||||
 | 
					            return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$anyExpectation() {
 | 
				
			||||||
 | 
					            return { type: "any" };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$endExpectation() {
 | 
				
			||||||
 | 
					            return { type: "end" };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$otherExpectation(description) {
 | 
				
			||||||
 | 
					            return { type: "other", description: description };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$computePosDetails(pos) {
 | 
				
			||||||
 | 
					            var details = peg$posDetailsCache[pos], p;
 | 
				
			||||||
 | 
					            if (details) {
 | 
				
			||||||
 | 
					                return details;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                p = pos - 1;
 | 
				
			||||||
 | 
					                while (!peg$posDetailsCache[p]) {
 | 
				
			||||||
 | 
					                    p--;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                details = peg$posDetailsCache[p];
 | 
				
			||||||
 | 
					                details = {
 | 
				
			||||||
 | 
					                    line: details.line,
 | 
				
			||||||
 | 
					                    column: details.column
 | 
				
			||||||
 | 
					                };
 | 
				
			||||||
 | 
					                while (p < pos) {
 | 
				
			||||||
 | 
					                    if (input.charCodeAt(p) === 10) {
 | 
				
			||||||
 | 
					                        details.line++;
 | 
				
			||||||
 | 
					                        details.column = 1;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else {
 | 
				
			||||||
 | 
					                        details.column++;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    p++;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                peg$posDetailsCache[pos] = details;
 | 
				
			||||||
 | 
					                return details;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$computeLocation(startPos, endPos) {
 | 
				
			||||||
 | 
					            var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos);
 | 
				
			||||||
 | 
					            return {
 | 
				
			||||||
 | 
					                start: {
 | 
				
			||||||
 | 
					                    offset: startPos,
 | 
				
			||||||
 | 
					                    line: startPosDetails.line,
 | 
				
			||||||
 | 
					                    column: startPosDetails.column
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                end: {
 | 
				
			||||||
 | 
					                    offset: endPos,
 | 
				
			||||||
 | 
					                    line: endPosDetails.line,
 | 
				
			||||||
 | 
					                    column: endPosDetails.column
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$fail(expected) {
 | 
				
			||||||
 | 
					            if (peg$currPos < peg$maxFailPos) {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (peg$currPos > peg$maxFailPos) {
 | 
				
			||||||
 | 
					                peg$maxFailPos = peg$currPos;
 | 
				
			||||||
 | 
					                peg$maxFailExpected = [];
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            peg$maxFailExpected.push(expected);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$buildSimpleError(message, location) {
 | 
				
			||||||
 | 
					            return new peg$SyntaxError(message, null, null, location);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$buildStructuredError(expected, found, location) {
 | 
				
			||||||
 | 
					            return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$decode(s) {
 | 
				
			||||||
 | 
					            var bc = new Array(s.length), i;
 | 
				
			||||||
 | 
					            for (i = 0; i < s.length; i++) {
 | 
				
			||||||
 | 
					                bc[i] = s.charCodeAt(i) - 32;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return bc;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        function peg$parseRule(index) {
 | 
				
			||||||
 | 
					            var bc = peg$bytecode[index], ip = 0, ips = [], end = bc.length, ends = [], stack = [], params, i;
 | 
				
			||||||
 | 
					            while (true) {
 | 
				
			||||||
 | 
					                while (ip < end) {
 | 
				
			||||||
 | 
					                    switch (bc[ip]) {
 | 
				
			||||||
 | 
					                        case 0:
 | 
				
			||||||
 | 
					                            stack.push(peg$consts[bc[ip + 1]]);
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 1:
 | 
				
			||||||
 | 
					                            stack.push(void 0);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 2:
 | 
				
			||||||
 | 
					                            stack.push(null);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 3:
 | 
				
			||||||
 | 
					                            stack.push(peg$FAILED);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 4:
 | 
				
			||||||
 | 
					                            stack.push([]);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 5:
 | 
				
			||||||
 | 
					                            stack.push(peg$currPos);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 6:
 | 
				
			||||||
 | 
					                            stack.pop();
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 7:
 | 
				
			||||||
 | 
					                            peg$currPos = stack.pop();
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 8:
 | 
				
			||||||
 | 
					                            stack.length -= bc[ip + 1];
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 9:
 | 
				
			||||||
 | 
					                            stack.splice(-2, 1);
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 10:
 | 
				
			||||||
 | 
					                            stack[stack.length - 2].push(stack.pop());
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 11:
 | 
				
			||||||
 | 
					                            stack.push(stack.splice(stack.length - bc[ip + 1], bc[ip + 1]));
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 12:
 | 
				
			||||||
 | 
					                            stack.push(input.substring(stack.pop(), peg$currPos));
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 13:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]);
 | 
				
			||||||
 | 
					                            if (stack[stack.length - 1]) {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                                ip += 3;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1] + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 14:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]);
 | 
				
			||||||
 | 
					                            if (stack[stack.length - 1] === peg$FAILED) {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                                ip += 3;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1] + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 15:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]);
 | 
				
			||||||
 | 
					                            if (stack[stack.length - 1] !== peg$FAILED) {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                                ip += 3;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1] + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 16:
 | 
				
			||||||
 | 
					                            if (stack[stack.length - 1] !== peg$FAILED) {
 | 
				
			||||||
 | 
					                                ends.push(end);
 | 
				
			||||||
 | 
					                                ips.push(ip);
 | 
				
			||||||
 | 
					                                end = ip + 2 + bc[ip + 1];
 | 
				
			||||||
 | 
					                                ip += 2;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                ip += 2 + bc[ip + 1];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 17:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 3 + bc[ip + 1] + bc[ip + 2]);
 | 
				
			||||||
 | 
					                            if (input.length > peg$currPos) {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                                ip += 3;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 3 + bc[ip + 1] + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 3 + bc[ip + 1];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 18:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]);
 | 
				
			||||||
 | 
					                            if (input.substr(peg$currPos, peg$consts[bc[ip + 1]].length) === peg$consts[bc[ip + 1]]) {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 4;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2] + bc[ip + 3];
 | 
				
			||||||
 | 
					                                ip += 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 19:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]);
 | 
				
			||||||
 | 
					                            if (input.substr(peg$currPos, peg$consts[bc[ip + 1]].length).toLowerCase() === peg$consts[bc[ip + 1]]) {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 4;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2] + bc[ip + 3];
 | 
				
			||||||
 | 
					                                ip += 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 20:
 | 
				
			||||||
 | 
					                            ends.push(end);
 | 
				
			||||||
 | 
					                            ips.push(ip + 4 + bc[ip + 2] + bc[ip + 3]);
 | 
				
			||||||
 | 
					                            if (peg$consts[bc[ip + 1]].test(input.charAt(peg$currPos))) {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                                ip += 4;
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            else {
 | 
				
			||||||
 | 
					                                end = ip + 4 + bc[ip + 2] + bc[ip + 3];
 | 
				
			||||||
 | 
					                                ip += 4 + bc[ip + 2];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 21:
 | 
				
			||||||
 | 
					                            stack.push(input.substr(peg$currPos, bc[ip + 1]));
 | 
				
			||||||
 | 
					                            peg$currPos += bc[ip + 1];
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 22:
 | 
				
			||||||
 | 
					                            stack.push(peg$consts[bc[ip + 1]]);
 | 
				
			||||||
 | 
					                            peg$currPos += peg$consts[bc[ip + 1]].length;
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 23:
 | 
				
			||||||
 | 
					                            stack.push(peg$FAILED);
 | 
				
			||||||
 | 
					                            if (peg$silentFails === 0) {
 | 
				
			||||||
 | 
					                                peg$fail(peg$consts[bc[ip + 1]]);
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 24:
 | 
				
			||||||
 | 
					                            peg$savedPos = stack[stack.length - 1 - bc[ip + 1]];
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 25:
 | 
				
			||||||
 | 
					                            peg$savedPos = peg$currPos;
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 26:
 | 
				
			||||||
 | 
					                            params = bc.slice(ip + 4, ip + 4 + bc[ip + 3]);
 | 
				
			||||||
 | 
					                            for (i = 0; i < bc[ip + 3]; i++) {
 | 
				
			||||||
 | 
					                                params[i] = stack[stack.length - 1 - params[i]];
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                            stack.splice(stack.length - bc[ip + 2], bc[ip + 2], peg$consts[bc[ip + 1]].apply(null, params));
 | 
				
			||||||
 | 
					                            ip += 4 + bc[ip + 3];
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 27:
 | 
				
			||||||
 | 
					                            stack.push(peg$parseRule(bc[ip + 1]));
 | 
				
			||||||
 | 
					                            ip += 2;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 28:
 | 
				
			||||||
 | 
					                            peg$silentFails++;
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        case 29:
 | 
				
			||||||
 | 
					                            peg$silentFails--;
 | 
				
			||||||
 | 
					                            ip++;
 | 
				
			||||||
 | 
					                            break;
 | 
				
			||||||
 | 
					                        default:
 | 
				
			||||||
 | 
					                            throw new Error("Invalid opcode: " + bc[ip] + ".");
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if (ends.length > 0) {
 | 
				
			||||||
 | 
					                    end = ends.pop();
 | 
				
			||||||
 | 
					                    ip = ips.pop();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else {
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return stack[0];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        let lines = [];
 | 
				
			||||||
 | 
					        let isSplit = false;
 | 
				
			||||||
 | 
					        peg$result = peg$parseRule(peg$startRuleIndex);
 | 
				
			||||||
 | 
					        if (peg$result !== peg$FAILED && peg$currPos === input.length) {
 | 
				
			||||||
 | 
					            return peg$result;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else {
 | 
				
			||||||
 | 
					            if (peg$result !== peg$FAILED && peg$currPos < input.length) {
 | 
				
			||||||
 | 
					                peg$fail(peg$endExpectation());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            throw peg$buildStructuredError(peg$maxFailExpected, peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null, peg$maxFailPos < input.length
 | 
				
			||||||
 | 
					                ? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
 | 
				
			||||||
 | 
					                : peg$computeLocation(peg$maxFailPos, peg$maxFailPos));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return {
 | 
				
			||||||
 | 
					        SyntaxError: peg$SyntaxError,
 | 
				
			||||||
 | 
					        parse: peg$parse
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										9123
									
								
								lib/core/sqlAutoCompleteParser.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9123
									
								
								lib/core/sqlAutoCompleteParser.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										9048
									
								
								lib/core/sqlSyntaxParser.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9048
									
								
								lib/core/sqlSyntaxParser.js
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										6
									
								
								lib/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								lib/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					const parser = require("./lib/parser");
 | 
				
			||||||
 | 
					exports.parser = parser;
 | 
				
			||||||
 | 
					const filter = require("./lib/filter");
 | 
				
			||||||
 | 
					exports.filter = filter;
 | 
				
			||||||
							
								
								
									
										27
									
								
								lib/lib/filter.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/lib/filter.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					const commentFilter = require("../core/comment");
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 过滤--注释
 | 
				
			||||||
 | 
					 * @param {String} sql
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function filterComments(sql) {
 | 
				
			||||||
 | 
					    return commentFilter.parse(sql).text;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.filterComments = filterComments;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 清除注释和前后空格
 | 
				
			||||||
 | 
					 * @param {String} sql
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function cleanSql(sql) {
 | 
				
			||||||
 | 
					    return filterComments(sql);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.cleanSql = cleanSql;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 分割sql
 | 
				
			||||||
 | 
					 * @param {String} sql
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function splitSql(sql) {
 | 
				
			||||||
 | 
					    return commentFilter.parse(sql).lines;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.splitSql = splitSql;
 | 
				
			||||||
							
								
								
									
										42
									
								
								lib/lib/parser.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								lib/lib/parser.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,42 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					// import * as sqlSyntaxParser from '../core/sqlSyntaxParser';
 | 
				
			||||||
 | 
					const sqlSyntaxParser = require("../core/sqlSyntaxParser");
 | 
				
			||||||
 | 
					const sqlAutoCompleteParser = require("../core/sqlAutoCompleteParser");
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 自动补全提示
 | 
				
			||||||
 | 
					 * @param {(string | Array<string>)} sql
 | 
				
			||||||
 | 
					 * @param {string} [type="hive"]
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function parseSyntax(sql, type) {
 | 
				
			||||||
 | 
					    if (typeof type == "undefined") {
 | 
				
			||||||
 | 
					        type = "hive";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let sql1 = sql;
 | 
				
			||||||
 | 
					    let sql2 = '';
 | 
				
			||||||
 | 
					    if (sql instanceof Array) {
 | 
				
			||||||
 | 
					        sql1 = sql[0];
 | 
				
			||||||
 | 
					        sql2 = sql[1];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // @ts-nocheck
 | 
				
			||||||
 | 
					    return sqlSyntaxParser.parser.parseSyntax(sql1, sql2, type, false);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.parseSyntax = parseSyntax;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 自动补全提示
 | 
				
			||||||
 | 
					 * @param {(string | Array<string>)} sql
 | 
				
			||||||
 | 
					 * @param {string} [type="hive"]
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function parserSql(sql, type) {
 | 
				
			||||||
 | 
					    if (typeof type == "undefined") {
 | 
				
			||||||
 | 
					        type = "hive";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    let sql1 = sql;
 | 
				
			||||||
 | 
					    let sql2 = '';
 | 
				
			||||||
 | 
					    if (sql instanceof Array) {
 | 
				
			||||||
 | 
					        sql1 = sql[0];
 | 
				
			||||||
 | 
					        sql2 = sql[1];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return sqlAutoCompleteParser.parser.parseSql(sql1, sql2, type, false);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.parserSql = parserSql;
 | 
				
			||||||
							
								
								
									
										21
									
								
								lib/utils/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								lib/utils/index.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					"use strict";
 | 
				
			||||||
 | 
					Object.defineProperty(exports, "__esModule", { value: true });
 | 
				
			||||||
 | 
					function replaceStrFormIndexArr(str, replaceStr, indexArr) {
 | 
				
			||||||
 | 
					    let arr = [];
 | 
				
			||||||
 | 
					    let result = "";
 | 
				
			||||||
 | 
					    let index = 0;
 | 
				
			||||||
 | 
					    if (!indexArr || indexArr.length < 1) {
 | 
				
			||||||
 | 
					        return str;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for (let i = 0; i < indexArr.length; i++) {
 | 
				
			||||||
 | 
					        let indexItem = indexArr[i];
 | 
				
			||||||
 | 
					        let begin = indexItem.begin;
 | 
				
			||||||
 | 
					        result = result + str.substring(index, begin) + replaceStr;
 | 
				
			||||||
 | 
					        index = indexItem.end + 1;
 | 
				
			||||||
 | 
					        if (i == indexArr.length - 1) {
 | 
				
			||||||
 | 
					            result = result + str.substring(index);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					exports.replaceStrFormIndexArr = replaceStrFormIndexArr;
 | 
				
			||||||
@ -7,7 +7,8 @@
 | 
				
			|||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
    "build:parse": "pegjs  -o core/astParser.js peg/nquery.pegjs ",
 | 
					    "build:parse": "pegjs  -o core/astParser.js peg/nquery.pegjs ",
 | 
				
			||||||
    "build:filter": "pegjs -o core/comment.js peg/comment.pegjs ",
 | 
					    "build:filter": "pegjs -o core/comment.js peg/comment.pegjs ",
 | 
				
			||||||
    "build:syntax": "sh ./jison/hue-sql-syntax.sh "
 | 
					    "build:syntax": "sh ./jison/hue-sql-syntax.sh ",
 | 
				
			||||||
 | 
					    "build": "rm -rf lib && tsc"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "author": "xiaokang",
 | 
					  "author": "xiaokang",
 | 
				
			||||||
  "license": "ISC",
 | 
					  "license": "ISC",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										4
									
								
								src/core/sqlAutoCompleteParser.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/core/sqlAutoCompleteParser.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					export const parser:{
 | 
				
			||||||
 | 
					    parseSql:Function
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								src/core/sqlSyntaxParser.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/core/sqlSyntaxParser.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					export const parser:{
 | 
				
			||||||
 | 
					    parseSyntax:Function
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										7
									
								
								src/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/index.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					import * as parser from "./lib/parser";
 | 
				
			||||||
 | 
					import * as filter from "./lib/filter";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export {
 | 
				
			||||||
 | 
					    parser,
 | 
				
			||||||
 | 
					    filter
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
const replaceStrFormIndexArr = require("../utils").replaceStrFormIndexArr;
 | 
					import * as commentFilter from '../core/comment';
 | 
				
			||||||
const commentFilter = require('../core/comment');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 过滤--注释
 | 
					 * 过滤--注释
 | 
				
			||||||
@ -25,6 +24,8 @@ function splitSql(sql) {
 | 
				
			|||||||
    return commentFilter.parse(sql).lines
 | 
					    return commentFilter.parse(sql).lines
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.filterComments = filterComments;
 | 
					export {
 | 
				
			||||||
exports.cleanSql = cleanSql;
 | 
					    filterComments,
 | 
				
			||||||
exports.splitSql = splitSql;
 | 
					    cleanSql,
 | 
				
			||||||
 | 
					    splitSql
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,28 +1,6 @@
 | 
				
			|||||||
const Parser = require('../core/astParser');
 | 
					// import * as sqlSyntaxParser from '../core/sqlSyntaxParser';
 | 
				
			||||||
const Cache = require("../core/cache");
 | 
					import * as sqlSyntaxParser from '../core/sqlSyntaxParser';
 | 
				
			||||||
const sqlSyntaxParser = require("../core/sqlSyntaxParser");
 | 
					import * as sqlAutoCompleteParser from '../core/sqlAutoCompleteParser';
 | 
				
			||||||
const sqlAutoCompleteParser = require("../core/sqlAutoCompleteParser");
 | 
					 | 
				
			||||||
const filter = require("./filter");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const astCache = new Cache();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * 生成ast
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function parse(sql) {
 | 
					 | 
				
			||||||
    const cleanSql = filter.cleanSql(sql);
 | 
					 | 
				
			||||||
    let ast = astCache.get(cleanSql);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (ast) {
 | 
					 | 
				
			||||||
        return ast
 | 
					 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        ast = Parser.parse(cleanSql).ast;
 | 
					 | 
				
			||||||
        astCache.set(cleanSql, ast);
 | 
					 | 
				
			||||||
        return ast;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 自动补全提示
 | 
					 * 自动补全提示
 | 
				
			||||||
 * @param {(string | Array<string>)} sql
 | 
					 * @param {(string | Array<string>)} sql
 | 
				
			||||||
@ -38,6 +16,7 @@ function parseSyntax(sql, type) {
 | 
				
			|||||||
        sql1=sql[0];
 | 
					        sql1=sql[0];
 | 
				
			||||||
        sql2=sql[1];
 | 
					        sql2=sql[1];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    // @ts-nocheck
 | 
				
			||||||
    return sqlSyntaxParser.parser.parseSyntax(sql1, sql2, type, false)
 | 
					    return sqlSyntaxParser.parser.parseSyntax(sql1, sql2, type, false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -59,6 +38,7 @@ function parserSql(sql, type) {
 | 
				
			|||||||
    return sqlAutoCompleteParser.parser.parseSql(sql1, sql2, type, false)
 | 
					    return sqlAutoCompleteParser.parser.parseSql(sql1, sql2, type, false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.parse = parse;
 | 
					export {
 | 
				
			||||||
exports.parseSyntax = parseSyntax;
 | 
					    parseSyntax,
 | 
				
			||||||
exports.parserSql = parserSql;
 | 
					    parserSql
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -21,4 +21,6 @@ function replaceStrFormIndexArr(str, replaceStr, indexArr) {
 | 
				
			|||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exports.replaceStrFormIndexArr=replaceStrFormIndexArr;
 | 
					export {
 | 
				
			||||||
 | 
					    replaceStrFormIndexArr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tsconfig.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "compilerOptions": {
 | 
				
			||||||
 | 
					        "outDir": "./lib/",
 | 
				
			||||||
 | 
					        "sourceMap": false,
 | 
				
			||||||
 | 
					        "allowJs":true,
 | 
				
			||||||
 | 
					        "target": "es6",
 | 
				
			||||||
 | 
					        "module": "commonjs"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "include": [
 | 
				
			||||||
 | 
					        "./src/**/*"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "exclude": [
 | 
				
			||||||
 | 
					        "./src/peg/*",
 | 
				
			||||||
 | 
					        "./src/jison/*"
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user