| | |
| | | }; |
| | | |
| | | Formatter.prototype.getFormattedQueryFromTokens = function getFormattedQueryFromTokens() { |
| | | var _this = this; |
| | | var that = this; |
| | | var formattedQuery = ""; |
| | | this.tokens.forEach(function (token, index) { |
| | | _this.index = index; |
| | | that.index = index; |
| | | if (token.type === _tokenTypes2["default"].WHITESPACE) { |
| | | // ignore (we do our own whitespace formatting) |
| | | } else if (token.type === _tokenTypes2["default"].LINE_COMMENT) { |
| | | formattedQuery = _this.formatLineComment(token, formattedQuery); |
| | | formattedQuery = that.formatLineComment(token, formattedQuery); |
| | | } else if (token.type === _tokenTypes2["default"].BLOCK_COMMENT) { |
| | | formattedQuery = _this.formatBlockComment(token, formattedQuery); |
| | | formattedQuery = that.formatBlockComment(token, formattedQuery); |
| | | } else if (token.type === _tokenTypes2["default"].RESERVED_TOPLEVEL) { |
| | | formattedQuery = _this.formatToplevelReservedWord(token, formattedQuery); |
| | | _this.previousReservedWord = token; |
| | | formattedQuery = that.formatToplevelReservedWord(token, formattedQuery); |
| | | that.previousReservedWord = token; |
| | | } else if (token.type === _tokenTypes2["default"].RESERVED_NEWLINE) { |
| | | formattedQuery = _this.formatNewlineReservedWord(token, formattedQuery); |
| | | _this.previousReservedWord = token; |
| | | formattedQuery = that.formatNewlineReservedWord(token, formattedQuery); |
| | | that.previousReservedWord = token; |
| | | }else if (token.type === _tokenTypes2["default"].RESERVED) { |
| | | formattedQuery = _this.formatWithSpaces(token, formattedQuery); |
| | | _this.previousReservedWord = token; |
| | | formattedQuery = that.formatWithSpaces(token, formattedQuery); |
| | | that.previousReservedWord = token; |
| | | } else if (token.type === _tokenTypes2["default"].OPEN_PAREN) { |
| | | formattedQuery = _this.formatOpeningParentheses(token, formattedQuery); |
| | | formattedQuery = that.formatOpeningParentheses(token, formattedQuery); |
| | | } else if (token.type === _tokenTypes2["default"].CLOSE_PAREN) { |
| | | formattedQuery = _this.formatClosingParentheses(token, formattedQuery); |
| | | formattedQuery = that.formatClosingParentheses(token, formattedQuery); |
| | | } else if (token.type === _tokenTypes2["default"].PLACEHOLDER) { |
| | | formattedQuery = _this.formatPlaceholder(token, formattedQuery); |
| | | formattedQuery = that.formatPlaceholder(token, formattedQuery); |
| | | } else if (token.value === '$') { |
| | | formattedQuery = _this.formatNewWithSpaces(token, formattedQuery); |
| | | formattedQuery = that.formatNewWithSpaces(token, formattedQuery); |
| | | } else if (token.value === ",") { |
| | | formattedQuery = _this.formatComma(token, formattedQuery); |
| | | formattedQuery = that.formatComma(token, formattedQuery); |
| | | } else if (token.value === ":") { |
| | | formattedQuery = _this.formatWithSpaceAfter(token, formattedQuery); |
| | | formattedQuery = that.formatWithSpaceAfter(token, formattedQuery); |
| | | } else if (token.value === ".") { |
| | | formattedQuery = _this.formatWithoutSpaces(token, formattedQuery); |
| | | formattedQuery = that.formatWithoutSpaces(token, formattedQuery); |
| | | } else if (token.value === ";") { |
| | | formattedQuery = _this.formatQuerySeparator(token, formattedQuery); |
| | | formattedQuery = that.formatQuerySeparator(token, formattedQuery); |
| | | } else { |
| | | formattedQuery = _this.formatWithSpaces(token, formattedQuery); |
| | | formattedQuery = that.formatWithSpaces(token, formattedQuery); |
| | | } |
| | | }); |
| | | return formattedQuery; |
| | |
| | | }; |
| | | |
| | | Tokenizer.prototype.createParenRegex = function createParenRegex(parens) { |
| | | var _this = this; |
| | | var that = this; |
| | | |
| | | return new RegExp("^(" + parens.map(function (p) { |
| | | return _this.escapeParen(p); |
| | | return that.escapeParen(p); |
| | | }).join("|") + ")", "i"); |
| | | }; |
| | | |
| | |
| | | }; |
| | | |
| | | Tokenizer.prototype.getStringNamedPlaceholderToken = function getStringNamedPlaceholderToken(input) { |
| | | var _this2 = this; |
| | | var that2 = this; |
| | | |
| | | return this.getPlaceholderTokenWithKey({ |
| | | input: input, |
| | | regex: this.STRING_NAMED_PLACEHOLDER_REGEX, |
| | | parseKey: function parseKey(v) { |
| | | return _this2.getEscapedPlaceholderKey({ key: v.slice(2, -1), quoteChar: v.slice(-1) }); |
| | | return that2.getEscapedPlaceholderKey({ key: v.slice(2, -1), quoteChar: v.slice(-1) }); |
| | | } |
| | | }); |
| | | }; |