From dcf38946a9c9c0bbfe0f32ff3b3509ef4aeccb09 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Fri, 19 Oct 2012 15:27:50 +0200 Subject: [PATCH 1/4] Fix bug in error message line number. --- lib/ace/mode/xquery/XQueryParser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ace/mode/xquery/XQueryParser.js b/lib/ace/mode/xquery/XQueryParser.js index 22975c4e334..a306d54cfd3 100644 --- a/lib/ace/mode/xquery/XQueryParser.js +++ b/lib/ace/mode/xquery/XQueryParser.js @@ -102,7 +102,7 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) var tokenSet = this.getExpectedTokenSet(e); var found = this.getOffendingToken(e); var prefix = input.substring(0, e.getBegin()); - var line = prefix.split("\n").length - 1; + var line = prefix.split("\n").length; var column = e.getBegin() - prefix.lastIndexOf("\n"); var size = e.getEnd() - e.getBegin(); return e.getMessage() From 036b31ac3fe8dbbededb46a05758702aa45e6d01 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sat, 20 Oct 2012 12:29:00 +0200 Subject: [PATCH 2/4] Add C style behavior to XQuery mode. --- lib/ace/mode/xquery.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ace/mode/xquery.js b/lib/ace/mode/xquery.js index 0bf786e1687..e1a7b4f83fe 100644 --- a/lib/ace/mode/xquery.js +++ b/lib/ace/mode/xquery.js @@ -35,13 +35,16 @@ var oop = require("../lib/oop"); var TextMode = require("./text").Mode; var Tokenizer = require("../tokenizer").Tokenizer; var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules; -var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour; -//var XQueryBackgroundHighlighter = require("./xquery_background_highlighter").XQueryBackgroundHighlighter; +//var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour; var Range = require("../range").Range; +var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; +var CStyleFoldMode = require("./folding/cstyle").FoldMode; + var Mode = function(parent) { this.$tokenizer = new Tokenizer(new XQueryHighlightRules().getRules()); - this.$behaviour = new XQueryBehaviour(parent); + this.$behaviour = new CstyleBehaviour(parent); + this.foldingRules = new CStyleFoldMode(); }; oop.inherits(Mode, TextMode); From 1ac2874ecf1f5b8329bec39deb01dc92082cfc49 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Thu, 1 Nov 2012 12:15:08 +0100 Subject: [PATCH 3/4] Improvements in the XQuery highlighter. --- lib/ace/mode/xquery/JSONParseTreeHandler.js | 92 + lib/ace/mode/xquery/XQueryParser.js | 18836 ++++++++++------ .../mode/xquery/visitors/SyntaxHighlighter.js | 155 +- lib/ace/mode/xquery_worker.js | 6 +- 4 files changed, 11764 insertions(+), 7325 deletions(-) create mode 100644 lib/ace/mode/xquery/JSONParseTreeHandler.js diff --git a/lib/ace/mode/xquery/JSONParseTreeHandler.js b/lib/ace/mode/xquery/JSONParseTreeHandler.js new file mode 100644 index 00000000000..77f493bee8f --- /dev/null +++ b/lib/ace/mode/xquery/JSONParseTreeHandler.js @@ -0,0 +1,92 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2010, Ajax.org B.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Ajax.org B.V. nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module){ + var JSONParseTreeHandler = exports.JSONParseTreeHandler = function() { + + var ast = null; + var ptr = null; + + function createNode(name){ + return { name: name, children: [], getParent: null }; + } + + function pushNode(name, begin){ + var node = createNode(name); + node.begin = begin; + if(ast === null) { + ast = node; + ptr = node; + } else { + node.getParent = ptr; + ptr.children.push(node); + ptr = ptr.children[ptr.children.length - 1]; + } + } + + function popNode(name, end){ + ptr.end = end; + if(ptr.getParent !== null) { + ptr = ptr.getParent; + for(var i in ptr.children) { + delete ptr.children[i].getParent; + } + } else { + delete ptr.getParent; + } + } + + this.getParseTree = function() { + return ast; + }; + + this.reset = function(input) {}; + + this.startNonterminal = function(name, begin) { + pushNode(name, begin); + }; + + this.endNonterminal = function(name, end) { + popNode(name, end); + }; + + this.terminal = function(name, begin, end) { + var name = (name.substring(0, 1) === "'" && name.substring(name.length - 1) === "'") ? "TOKEN" : name; + pushNode(name, begin); + popNode(name, end); + }; + + this.whitespace = function(begin, end) { + var name = "WS"; + pushNode(name, begin); + popNode(name, end); + }; + }; +}); diff --git a/lib/ace/mode/xquery/XQueryParser.js b/lib/ace/mode/xquery/XQueryParser.js index a306d54cfd3..af38b6b99f6 100644 --- a/lib/ace/mode/xquery/XQueryParser.js +++ b/lib/ace/mode/xquery/XQueryParser.js @@ -30,9 +30,9 @@ define(function(require, exports, module){ -var XQueryParser = exports.XQueryParser = function XQueryParser(string) +var XQueryParser = exports.XQueryParser = function XQueryParser(string, parsingEventHandler) { - init(string); + init(string, parsingEventHandler); function ParseException(b, e, s, o, x) { @@ -55,12 +55,12 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) }; } - function init(string) + function init(string, parsingEventHandler) { + eventHandler = parsingEventHandler; input = string; size = string.length; reset(0, 0, 0); - delayedTag = null; } this.getInput = function() @@ -76,13 +76,14 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) end = e; ex = -1; memo = new Object; + eventHandler.reset(input); } this.getOffendingToken = function(e) { var o = e.getOffending(); - return o >= 0 ? TOKEN[o] : null; - } + return o >= 0 ? XQueryParser.TOKEN[o] : null; + }; this.getExpectedTokenSet = function(e) { @@ -93,45 +94,35 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) } else { - expected = [TOKEN[e.getExpected()]]; + expected = [XQueryParser.TOKEN[e.getExpected()]]; } return expected; - } + }; - this.getErrorMessage = function(e){ + this.getErrorMessage = function(e) + { var tokenSet = this.getExpectedTokenSet(e); var found = this.getOffendingToken(e); var prefix = input.substring(0, e.getBegin()); - var line = prefix.split("\n").length; - var column = e.getBegin() - prefix.lastIndexOf("\n"); + var lines = prefix.split("\n"); + var line = lines.length; + var column = e.getBegin() - lines[line - 1].length + 1; var size = e.getEnd() - e.getBegin(); - return e.getMessage() + return e.getMessage() + (found == null ? "" : ", found " + found) - + " while expecting " - + (tokenSet.length == 1 ? tokenSet[0] : tokenSet.splice(0 , 5)) - + (tokenSet.splice > 5? "..." : "") - //+ "\n" - //+ (size == 0 ? "" : "after successfully scanning " + size + " characters beginning ") - + " at line " + line + ", column " + column + ":\n..." + + "\nwhile expecting " + + (tokenSet.length == 1 ? tokenSet[0] : ("[" + tokenSet.join(", ") + "]")) + + "\n" + + (size == 0 ? "" : "after successfully scanning " + size + " characters beginning ") + + "at line " + line + ", column " + column + ":\n..." + input.substring(e.getBegin(), Math.min(input.length, e.getBegin() + 64)) + "..."; - } + }; this.parse_XQuery = function() { - startNonterminal("XQuery"); - lookahead1W(37); // EPSILON | S^WS | '(:' - parse_Module(); - lookahead1W(43); // S^WS | EOF | '(:' - shift(25); // EOF - endNonterminal("XQuery"); - flushOutput(); - } - - function parse_Module() - { - startNonterminal("Module"); - lookahead1W(323); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | + eventHandler.startNonterminal("XQuery", e0); + lookahead1W(267); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | // StringLiteral | S^WS | EOF | '$' | '%' | '(' | '(#' | '(:' | '+' | '-' | '.' | // '..' | '/' | '//' | '<' | '' + lookahead1(6); // '-->' shift(43); // '-->' - endNonterminal("DirCommentConstructor"); + eventHandler.endNonterminal("DirCommentConstructor", e0); } function try_DirCommentConstructor() @@ -9900,26 +11862,26 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) shiftT(55); // '' + lookahead1(6); // '-->' shiftT(43); // '-->' } function parse_DirPIConstructor() { - startNonterminal("DirPIConstructor"); + eventHandler.startNonterminal("DirPIConstructor", e0); shift(59); // '' + lookahead1(13); // S | '?>' if (l1 == 21) // S { shift(21); // S lookahead1(2); // DirPIContents shift(3); // DirPIContents } - lookahead1(12); // '?>' + lookahead1(9); // '?>' shift(65); // '?>' - endNonterminal("DirPIConstructor"); + eventHandler.endNonterminal("DirPIConstructor", e0); } function try_DirPIConstructor() @@ -9927,20 +11889,20 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) shiftT(59); // '' + lookahead1(13); // S | '?>' if (l1 == 21) // S { shiftT(21); // S lookahead1(2); // DirPIContents shiftT(3); // DirPIContents } - lookahead1(12); // '?>' + lookahead1(9); // '?>' shiftT(65); // '?>' } function parse_ComputedConstructor() { - startNonterminal("ComputedConstructor"); + eventHandler.startNonterminal("ComputedConstructor", e0); switch (l1) { case 119: // 'document' @@ -9964,7 +11926,7 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) default: parse_CompPIConstructor(); } - endNonterminal("ComputedConstructor"); + eventHandler.endNonterminal("ComputedConstructor", e0); } function try_ComputedConstructor() @@ -9996,9 +11958,9 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) function parse_CompElemConstructor() { - startNonterminal("CompElemConstructor"); + eventHandler.startNonterminal("CompElemConstructor", e0); shift(121); // 'element' - lookahead1W(308); // EQName^Token | S^WS | '(:' | 'after' | 'allowing' | 'ancestor' | + lookahead1W(252); // EQName^Token | S^WS | '(:' | 'after' | 'allowing' | 'ancestor' | // 'ancestor-or-self' | 'and' | 'as' | 'ascending' | 'at' | 'attribute' | // 'base-uri' | 'before' | 'boundary-space' | 'break' | 'case' | 'cast' | // 'castable' | 'catch' | 'child' | 'collation' | 'comment' | 'constraint' | @@ -10023,17 +11985,41 @@ var XQueryParser = exports.XQueryParser = function XQueryParser(string) { case 276: // '{' shift(276); // '{' - lookahead1W(37); // EPSILON | S^WS | '(:' + lookahead1W(266); // Wildcard | EQName^Token | IntegerLiteral | DecimalLiteral | DoubleLiteral | + // StringLiteral | S^WS | '$' | '%' | '(' | '(#' | '(:' | '+' | '-' | '.' | '..' | + // '/' | '//' | '<' | ''", - "'.'", - "'..'", - "'/'", - "'//'", - "'/>'", - "':'", - "':)'", - "'::'", - "':='", - "';'", - "'<'", - "''", + "'.'", + "'..'", + "'/'", + "'//'", + "'/>'", + "':'", + "':)'", + "'::'", + "':='", + "';'", + "'<'", + "'