Merge pull request #1075 from wcandillon/master
Improvements in the XQuery mode
This commit is contained in:
commit
3f8aa00d23
5 changed files with 12504 additions and 8074 deletions
|
|
@ -35,13 +35,16 @@ var oop = require("../lib/oop");
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||||
var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules;
|
var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules;
|
||||||
var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
|
//var XQueryBehaviour = require("./behaviour/xquery").XQueryBehaviour;
|
||||||
//var XQueryBackgroundHighlighter = require("./xquery_background_highlighter").XQueryBackgroundHighlighter;
|
|
||||||
var Range = require("../range").Range;
|
var Range = require("../range").Range;
|
||||||
|
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
|
||||||
|
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
|
||||||
|
|
||||||
|
|
||||||
var Mode = function(parent) {
|
var Mode = function(parent) {
|
||||||
this.$tokenizer = new Tokenizer(new XQueryHighlightRules().getRules());
|
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);
|
oop.inherits(Mode, TextMode);
|
||||||
|
|
|
||||||
92
lib/ace/mode/xquery/JSONParseTreeHandler.js
Normal file
92
lib/ace/mode/xquery/JSONParseTreeHandler.js
Normal file
|
|
@ -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);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
});
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -27,15 +27,14 @@
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* ***** END LICENSE BLOCK ***** */
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
define(function(require, exports, module){
|
define(function(require, exports, module){
|
||||||
|
|
||||||
var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
||||||
{
|
{
|
||||||
var keywords = ['after', 'ancestor', 'ancestor-or-self', 'and', 'as', 'ascending', 'attribute', 'before', 'case', 'cast', 'castable', 'child', 'collation', 'comment', 'copy', 'count', 'declare', 'default', 'delete', 'descendant', 'descendant-or-self', 'descending', 'div', 'document', 'document-node', 'element', 'else', 'empty', 'empty-sequence', 'end', 'eq', 'every', 'except', 'first', 'following', 'following-sibling', 'for', 'function', 'ge', 'group', 'gt', 'idiv', 'if', 'then', 'import', 'insert', 'instance', 'intersect', 'into', 'is', 'item', 'last', 'le', 'let', 'lt', 'mod', 'modify', 'module', 'namespace', 'namespace-node', 'ne', 'node', 'only', 'or', 'order', 'ordered', 'parent', 'preceding', 'preceding-sibling', 'processing-instruction', 'rename', 'replace', 'return', 'satisfies', 'schema-attribute', 'schema-element', 'self', 'some', 'stable', 'start', 'switch', 'text', 'to', 'treat', 'try', 'typeswitch', 'union', 'unordered', 'validate', 'where', 'with', 'xquery', 'contains', 'paragraphs', 'sentences', 'times', 'words', 'by', 'collection', 'allowing', 'at', 'base-uri', 'boundary-space', 'break', 'catch', 'construction', 'context', 'continue', 'copy-namespaces', 'decimal-format', 'encoding', 'exit', 'external', 'ft-option', 'in', 'index', 'integrity', 'lax', 'nodes', 'option', 'ordering', 'revalidation', 'schema', 'score', 'sliding', 'strict', 'tumbling', 'type', 'updating', 'value', 'variable', 'version', 'while', 'constraint', 'loop', 'returning', 'append', 'array', 'json-item', 'object', 'structured-item', 'when', 'next', 'previous'];
|
var keywords = ['after', 'ancestor', 'ancestor-or-self', 'and', 'as', 'ascending', 'attribute', 'before', 'case', 'cast', 'castable', 'child', 'collation', 'comment', 'copy', 'count', 'declare', 'default', 'delete', 'descendant', 'descendant-or-self', 'descending', 'div', 'document', 'document-node', 'element', 'else', 'empty', 'empty-sequence', 'end', 'eq', 'every', 'except', 'first', 'following', 'following-sibling', 'for', 'function', 'ge', 'group', 'gt', 'idiv', 'if', 'then', 'import', 'insert', 'instance', 'intersect', 'into', 'is', 'item', 'last', 'le', 'let', 'lt', 'mod', 'modify', 'module', 'namespace', 'namespace-node', 'ne', 'node', 'only', 'or', 'order', 'ordered', 'parent', 'preceding', 'preceding-sibling', 'processing-instruction', 'rename', 'replace', 'return', 'satisfies', 'schema-attribute', 'schema-element', 'self', 'some', 'stable', 'start', 'switch', 'text', 'to', 'treat', 'try', 'typeswitch', 'union', 'unordered', 'validate', 'where', 'with', 'xquery', 'contains', 'paragraphs', 'sentences', 'times', 'words', 'by', 'collection', 'allowing', 'at', 'base-uri', 'boundary-space', 'break', 'catch', 'construction', 'context', 'continue', 'copy-namespaces', 'decimal-format', 'encoding', 'exit', 'external', 'ft-option', 'in', 'index', 'integrity', 'lax', 'nodes', 'option', 'ordering', 'revalidation', 'schema', 'score', 'sliding', 'strict', 'tumbling', 'type', 'updating', 'value', 'variable', 'version', 'while', 'constraint', 'loop', 'returning', 'append', 'array', 'json-item', 'object', 'structured-item', 'when', 'next', 'previous', 'window'];
|
||||||
var states = ["cdata", "comment", "tag"];
|
var states = ["cdata", "comment", "tag"];
|
||||||
var info = { lines: [ [] ], states: [] };
|
var info = { lines: [ [] ], states: [] };
|
||||||
var inName = false;
|
|
||||||
|
|
||||||
this.getTokens = function() {
|
this.getTokens = function() {
|
||||||
this.visit(tree);
|
this.visit(tree);
|
||||||
|
|
@ -124,27 +123,6 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
//this.EQName = function(node)
|
|
||||||
//{
|
|
||||||
// var value = source.substring(node.begin, node.end);
|
|
||||||
// this.addTokens(value, "support.function");
|
|
||||||
// return true;
|
|
||||||
//};
|
|
||||||
|
|
||||||
this.FunctionName = function(node)
|
|
||||||
{
|
|
||||||
for(var i in node.children) {
|
|
||||||
var child = node.children[i];
|
|
||||||
if(child.name === "EQName" || child.name === "TOKEN") {
|
|
||||||
var value = child.children[0].value;
|
|
||||||
this.addTokens(value, "support.function");
|
|
||||||
} else {
|
|
||||||
this.visit(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.StringConcatExpr = function(node)
|
this.StringConcatExpr = function(node)
|
||||||
{
|
{
|
||||||
for(var i in node.children) {
|
for(var i in node.children) {
|
||||||
|
|
@ -260,57 +238,47 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.NCName = function(node)
|
|
||||||
{
|
|
||||||
inName = true;
|
|
||||||
for(var i in node.children)
|
|
||||||
{
|
|
||||||
var child = node.children[i];
|
|
||||||
this.visit(child);
|
|
||||||
}
|
|
||||||
inName = false;
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.EQName = function(node)
|
this.EQName = function(node)
|
||||||
{
|
{
|
||||||
inName = true;
|
var value = this.getNodeValue(node);
|
||||||
for(var i in node.children)
|
this.addTokens(value, "support.function");
|
||||||
{
|
|
||||||
var child = node.children[i];
|
|
||||||
this.visit(child);
|
|
||||||
}
|
|
||||||
inName = false;
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.TOKEN = function(node)
|
this.TOKEN = function(node)
|
||||||
{
|
{
|
||||||
value = node.children[0].value;
|
var value = this.getNodeValue(node);
|
||||||
if(keywords.indexOf(value) > -1 && !inName) {
|
if(keywords.indexOf(value) > -1 ) {
|
||||||
this.addTokens(value, "keyword");
|
this.addTokens(value, "keyword");
|
||||||
return true;
|
} else if(value === "$") {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
this.addTokens(value, "text");
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.WS = function(node) {
|
||||||
|
var value = this.getNodeValue(node);
|
||||||
|
var openingIdx = value.indexOf("(:");
|
||||||
|
while(openingIdx > -1) {
|
||||||
|
var text = value.substring(0, openingIdx);
|
||||||
|
this.addTokens(text, "text");
|
||||||
|
var closingIdx = value.substring(openingIdx).indexOf(":)") + 3;
|
||||||
|
var comment = value.substring(openingIdx, closingIdx);
|
||||||
|
this.addTokens(comment, "comment");
|
||||||
|
value = value.substring(closingIdx);
|
||||||
|
openingIdx = value.indexOf("(:");
|
||||||
|
}
|
||||||
|
this.addTokens(value, "text");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.EverythingElse = function(node)
|
this.EverythingElse = function(node)
|
||||||
{
|
{
|
||||||
if(typeof node["pos"] === "object")
|
if(node.children.length === 0) {
|
||||||
{
|
var value = this.getNodeValue(node);
|
||||||
var value = node.value;
|
|
||||||
var openingIdx = value.indexOf("(:");
|
|
||||||
while(openingIdx > -1) {
|
|
||||||
var text = value.substring(0, openingIdx);
|
|
||||||
this.addTokens(text, "text");
|
|
||||||
var closingIdx = value.substring(openingIdx).indexOf(":)") + 3;
|
|
||||||
var comment = value.substring(openingIdx, closingIdx);
|
|
||||||
this.addTokens(comment, "comment");
|
|
||||||
value = value.substring(closingIdx);
|
|
||||||
openingIdx = value.indexOf("(:");
|
|
||||||
}
|
|
||||||
this.addTokens(value, "text");
|
this.addTokens(value, "text");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
@ -323,17 +291,20 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
||||||
skip = this[name](node) === true ? true : false ;
|
skip = this[name](node) === true ? true : false ;
|
||||||
else
|
else
|
||||||
skip = this.EverythingElse(node) === true ? true : false;
|
skip = this.EverythingElse(node) === true ? true : false;
|
||||||
|
|
||||||
if(!skip && typeof node.children === "object")
|
if(!skip && typeof node.children === "object")
|
||||||
{
|
{
|
||||||
|
var isVarEQName = false;
|
||||||
for(var i = 0; i < node.children.length; i++)
|
for(var i = 0; i < node.children.length; i++)
|
||||||
{
|
{
|
||||||
var child = node.children[i];
|
var child = node.children[i];
|
||||||
if(child.name === "TOKEN" && child.children[0].value === "$") {
|
var value = this.getNodeValue(child);
|
||||||
i++;
|
if(child.name === "TOKEN" && value === "$")
|
||||||
var next = node.children[i];
|
{
|
||||||
var value = source.substring(child.children[0].pos.begin, next.end);
|
isVarEQName = true;
|
||||||
this.addTokens(value, "variable");
|
} else if(isVarEQName) {
|
||||||
|
this.addTokens("$" + value, "variable");
|
||||||
|
isVarEQName = false;
|
||||||
} else {
|
} else {
|
||||||
this.visit(child);
|
this.visit(child);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
var oop = require("../lib/oop");
|
var oop = require("../lib/oop");
|
||||||
var Mirror = require("../worker/mirror").Mirror;
|
var Mirror = require("../worker/mirror").Mirror;
|
||||||
|
var JSONParseTreeHandler = require("./xquery/JSONParseTreeHandler").JSONParseTreeHandler;
|
||||||
var XQueryParser = require("./xquery/XQueryParser").XQueryParser;
|
var XQueryParser = require("./xquery/XQueryParser").XQueryParser;
|
||||||
var SyntaxHighlighter = require("../mode/xquery/visitors/SyntaxHighlighter").SyntaxHighlighter;
|
var SyntaxHighlighter = require("../mode/xquery/visitors/SyntaxHighlighter").SyntaxHighlighter;
|
||||||
window.addEventListener = function() {};
|
window.addEventListener = function() {};
|
||||||
|
|
@ -50,10 +51,11 @@ oop.inherits(XQueryWorker, Mirror);
|
||||||
this.onUpdate = function() {
|
this.onUpdate = function() {
|
||||||
this.sender.emit("start");
|
this.sender.emit("start");
|
||||||
var value = this.doc.getValue();
|
var value = this.doc.getValue();
|
||||||
var parser = new XQueryParser(value);
|
var h = new JSONParseTreeHandler();
|
||||||
|
var parser = new XQueryParser(value, h);
|
||||||
try {
|
try {
|
||||||
parser.parse_XQuery();
|
parser.parse_XQuery();
|
||||||
var ast = parser.getAST();
|
var ast = h.getParseTree();
|
||||||
this.sender.emit("ok");
|
this.sender.emit("ok");
|
||||||
var highlighter = new SyntaxHighlighter(value, ast);
|
var highlighter = new SyntaxHighlighter(value, ast);
|
||||||
var tokens = highlighter.getTokens();
|
var tokens = highlighter.getTokens();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue