Improve syntax highlighting of XQuery comments.
This commit is contained in:
parent
9c61ac1127
commit
eebc086415
1 changed files with 73 additions and 44 deletions
|
|
@ -1,33 +1,3 @@
|
|||
/* ***** 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 SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
||||
|
|
@ -35,6 +5,7 @@ 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', 'window'];
|
||||
var states = ["cdata", "comment", "tag"];
|
||||
var info = { lines: [ [] ], states: [] };
|
||||
// var inName = false;
|
||||
|
||||
this.getTokens = function() {
|
||||
this.visit(tree);
|
||||
|
|
@ -123,6 +94,27 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
|||
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.children[0] && (child.name === "EQName" || child.name === "TOKEN")) {
|
||||
// var value = this.getNodeValue(child.children[0]);
|
||||
// this.addTokens(value, "support.function");
|
||||
// } else {
|
||||
// this.visit(child);
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
//};
|
||||
|
||||
this.StringConcatExpr = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
|
|
@ -238,17 +230,42 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
|||
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.NCName = function(node) {
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "support.function");
|
||||
return true;
|
||||
};
|
||||
|
||||
this.EQName = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "support.function");
|
||||
//inName = true;
|
||||
//for(var i in node.children)
|
||||
//{
|
||||
// var child = node.children[i];
|
||||
// this.visit(child);
|
||||
//}
|
||||
//inName = false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
this.TOKEN = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
if(keywords.indexOf(value) > -1 ) {
|
||||
if(keywords.indexOf(value) > -1 ) {//&& !inName) {
|
||||
this.addTokens(value, "keyword");
|
||||
} else if(value === "$") {
|
||||
|
||||
|
|
@ -257,22 +274,34 @@ var SyntaxHighlighter = exports.SyntaxHighlighter = function(source, tree)
|
|||
}
|
||||
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");
|
||||
};
|
||||
var remains = new String(value);
|
||||
var state = 1;
|
||||
var j = 0;
|
||||
for(var i = 0; i < value.length; i++) {
|
||||
var isOpen = value.substring(i, i + 2) == "(:";
|
||||
var isClose = value.substring(i, i + 2) == ":)";
|
||||
|
||||
if(isOpen) {
|
||||
state++;
|
||||
} else if(isClose) {
|
||||
state--;
|
||||
}
|
||||
|
||||
if(isOpen && !(state % 2)) {
|
||||
this.addTokens(remains.substring(0, i), "text");
|
||||
remains = remains.substring(i);
|
||||
j = i;
|
||||
} else if(isClose && (state % 2)) {
|
||||
this.addTokens(remains.substring(0, i - j + 2), "comment");
|
||||
remains = remains.substring(i - j + 2);
|
||||
}
|
||||
}
|
||||
this.addTokens(remains, "text");
|
||||
};
|
||||
|
||||
this.EverythingElse = function(node)
|
||||
{
|
||||
if(node.children.length === 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue