Add new version of XQuery semantic highlighting.

This commit is contained in:
William Candillon 2013-01-15 08:47:58 +01:00 committed by nightwing
commit 0c79c5dded
7 changed files with 5091 additions and 17 deletions

View file

@ -230,7 +230,7 @@ var BackgroundTokenizer = function(tokenizer, editor) {
var overflow = {value: line.substr(MAX_LINE_LENGTH), type: "text"};
line = line.slice(0, MAX_LINE_LENGTH);
}
var data = this.tokenizer.getLineTokens(line, state);
var data = this.tokenizer.getLineTokens(line, state, row);
if (overflow) {
data.tokens.push(overflow);
data.state = "start";

View file

@ -33,16 +33,14 @@ define(function(require, exports, module) {
var WorkerClient = require("../worker/worker_client").WorkerClient;
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 XQueryLexer = require("./xquery/XQueryLexer").XQueryLexer;
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.$tokenizer = new XQueryLexer();
this.$behaviour = new CstyleBehaviour(parent);
this.foldingRules = new CStyleFoldMode();
};
@ -138,16 +136,8 @@ oop.inherits(Mode, TextMode);
worker.on("highlight", function(tokens) {
if(that.$deltas.length > 0) return;
var firstRow = 0;
var lastRow = session.getLength() - 1;
var lines = tokens.data.lines;
var states = tokens.data.states;
session.bgTokenizer.lines = lines;
session.bgTokenizer.states = states;
session.bgTokenizer.fireUpdateEvent(firstRow, lastRow);
that.$tokenizer.tokens = tokens.data;
session.bgTokenizer.fireUpdateEvent(0, session.getLength() - 1);
});
return worker;

View file

@ -0,0 +1,302 @@
/* ***** 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 XQueryTokenizer = require("./XQueryTokenizer").XQueryTokenizer;
var TokenHandler = function(code) {
var input = code;
this.tokens = [];
this.reset = function(code) {
input = input;
this.tokens = [];
};
this.startNonterminal = function(name, begin) {};
this.endNonterminal = function(name, end) {};
this.terminal = function(name, begin, end) {
this.tokens.push({
name: name,
value: input.substring(begin, end)
});
};
this.whitespace = function(begin, end) {
this.tokens.push({
name: "WS",
value: input.substring(begin, end)
});
};
};
var keys = "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|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|collectionreturn|variable|version|option|when|encoding|toswitch|catch|tumbling|sliding|window|at|using|stemming|collection|schema|while|on|nodes|index|external|then|in|updating|value|of|containsbreak|loop|continue|exit|returning|append|json|position".split("|");
var keywords = keys.map(
function(val) { return { name: "'" + val + "'", token: "keyword" }; }
);
var ncnames = keys.map(
function(val) { return { name: "'" + val + "'", token: "text", next: function(stack){ stack.pop(); } }; }
);
var cdata = "constant.language";
var number = "constant";
var xmlcomment = "comment";
var pi = "xml-pe";
var pragma = "constant.buildin";
var Rules = {
start: [
{ name: "'(#'", token: pragma, next: function(stack){ stack.push("Pragma"); } },
{ name: "'(:'", token: "comment", next: function(stack){ stack.push("Comment"); } },
{ name: "'(:~'", token: "comment.doc", next: function(stack){ stack.push("CommentDoc"); } },
{ name: "'<!--'", token: xmlcomment, next: function(stack){ stack.push("XMLComment"); } },
{ name: "'<?'", token: pi, next: function(stack) { stack.push("PI"); } },
{ name: "''''", token: "string", next: function(stack){ stack.push("AposString"); } },
{ name: "'\"'", token: "string", next: function(stack){ stack.push("QuotString"); } },
{ name: "Annotation", token: "support.function" },
{ name: "ModuleDecl", token: "keyword", next: function(stack){ stack.push("Prefix"); } },
{ name: "OptionDecl", token: "keyword", next: function(stack){ stack.push("_EQName"); } },
{ name: "AttrTest", token: "support.type" },
{ name: "Variable", token: "variable" },
{ name: "'<![CDATA['", token: cdata, next: function(stack){ stack.push("CData"); } },
{ name: "IntegerLiteral", token: number },
{ name: "DecimalLiteral", token: number },
{ name: "DoubleLiteral", token: number },
{ name: "Operator", token: "keyword.operator" },
{ name: "EQName", token: function(val) { return keys.indexOf(val) !== -1 ? "keyword" : "support.function"; } },
{ name: "'('", token:"lparen" },
{ name: "')'", token:"rparen" },
{ name: "Tag", token: "meta.tag", next: function(stack){ stack.push("StartTag"); } },
{ name: "'}'", token: "text", next: function(stack){ if(stack.length > 1) { stack.pop(); } } },
{ name: "'{'", token: "text" } //, next: function(stack){ if(stack.length > 1) { stack.pop(); } } }
].concat(keywords),
_EQName: [
{ name: "EQName", token: "text", next: function(stack) { stack.pop(); } }
].concat(ncnames),
Prefix: [
{ name: "NCName", token: "text", next: function(stack) { stack.pop(); } }
].concat(ncnames),
StartTag: [
{ name: "'>'", token: "meta.tag", next: function(stack){ stack.push("TagContent"); } },
{ name: "QName", token: "meta.tag" },
{ name: "'='", token: "text" },
{ name: "''''", token: "string", next: function(stack){ stack.push("AposAttr"); } },
{ name: "'\"'", token: "string", next: function(stack){ stack.push("QuotAttr"); } },
{ name: "'/>'", token: "meta.tag", next: function(stack){ stack.pop(); } }
],
TagContent: [
{ name: "ElementContentChar", token: "text" },
{ name: "'<![CDATA['", token: cdata, next: function(stack){ stack.push("CData"); } },
{ name: "'<!--'", token: xmlcomment, next: function(stack){ stack.push("XMLComment"); } },
{ name: "Tag", token: "meta.tag", next: function(stack){ stack.push("StartTag"); } },
{ name: "PredefinedEntityRef", token: "constant.language.escape" },
{ name: "CharRef", token: "constant.language.escape" },
{ name: "'{{'", token: "text" },
{ name: "'}}'", token: "text" },
{ name: "'{'", token: "text", next: function(stack){ stack.push("start"); } },
{ name: "EndTag", token: "meta.tag", next: function(stack){ stack.pop(); stack.pop(); } }
],
AposAttr: [
{ name: "''''", token: "string", next: function(stack){ stack.pop(); } },
{ name: "EscapeApos", token: "constant.language.escape" },
{ name: "AposAttrContentChar", token: "string" },
{ name: "PredefinedEntityRef", token: "constant.language.escape" },
{ name: "CharRef", token: "constant.language.escape" },
{ name: "'{{'", token: "string" },
{ name: "'}}'", token: "string" },
{ name: "'{'", token: "text", next: function(stack){ stack.push("start"); } }
],
QuotAttr: [
{ name: "'\"'", token: "string", next: function(stack){ stack.pop(); } },
{ name: "EscapeQuot", token: "constant.language.escape" },
{ name: "QuotAttrContentChar", token: "string" },
{ name: "PredefinedEntityRef", token: "constant.language.escape" },
{ name: "CharRef", token: "constant.language.escape" },
{ name: "'{{'", token: "string" },
{ name: "'}}'", token: "string" },
{ name: "'{'", token: "text", next: function(stack){ stack.push("start"); } }
],
Pragma: [
{ name: "PragmaContents", token: pragma },
{ name: "'#)'", token: pragma, next: function(stack){ stack.pop(); } }
],
Comment: [
{ name: "CommentContents", token: "comment" },
{ name: "'(:'", token: "comment", next: function(stack){ stack.push("Comment"); } },
{ name: "':)'", token: "comment", next: function(stack){ stack.pop(); } }
],
CommentDoc: [
{ name: "DocCommentContents", token: "comment.doc" },
{ name: "DocTag", token: "comment.doc.tag" },
{ name: "'(:'", token: "comment.doc", next: function(stack){ stack.push("CommentDoc"); } },
{ name: "':)'", token: "comment.doc", next: function(stack){ stack.pop(); } }
],
XMLComment: [
{ name: "DirCommentContents", token: xmlcomment },
{ name: "'-->'", token: xmlcomment, next: function(stack){ stack.pop(); } }
],
CData: [
{ name: "CDataSectionContents", token: cdata },
{ name: "']]>'", token: cdata, next: function(stack){ stack.pop(); } }
],
PI: [
{ name: "DirPIContents", token: pi },
{ name: "PITarget", token: pi },
{ name: "S", token: pi },
{ name: "'?>'", token: pi, next: function(stack){ stack.pop(); } }
],
AposString: [
{ name: "''''", token: "string", next: function(stack){ stack.pop(); } },
{ name: "PredefinedEntityRef", token: "constant.language.escape" },
{ name: "CharRef", token: "constant.language.escape" },
{ name: "EscapeApos", token: "constant.language.escape" },
{ name: "AposChar", token: "string" }
],
QuotString: [
{ name: "'\"'", token: "string", next: function(stack){ stack.pop(); } },
{ name: "PredefinedEntityRef", token: "constant.language.escape" },
{ name: "CharRef", token: "constant.language.escape" },
{ name: "EscapeQuot", token: "constant.language.escape" },
{ name: "QuotChar", token: "string" }
]
};
exports.XQueryLexer = function() {
this.tokens = [];
this.getLineTokens = function(line, state, row) {
var stack = JSON.parse(state || '["start"]');
var h = new TokenHandler(line);
var tokenizer = new XQueryTokenizer(line, h);
var tokens = [];
while(true) {
var currentState = stack[stack.length - 1];
try {
h.tokens = [];
tokenizer["parse_" + currentState]();
var info = null;
if(h.tokens.length > 1 && h.tokens[0].name === "WS") {
tokens.push({
type: "text",
value: h.tokens[0].value
});
h.tokens.splice(0, 1);
}
var token = h.tokens[0];
for(var k in Rules[currentState]) {
var rule = Rules[currentState][k];
if((typeof(rule.name) === "function" && rule.name(token)) || rule.name === token.name) {
info = rule;
break;
}
}
if(token.name === "EOF") { break; }
tokens.push({
type: info === null ? "text" : (typeof(info.token) === "function" ? info.token(token.value) : info.token),
value: token.value
});
if(info && info.next) {
info.next(stack);
}
} catch(e) {
if(e instanceof tokenizer.ParseException) {
var message = tokenizer.getErrorMessage(e);
//console.log(stack[stack.length - 1]);
//console.log(line);
//console.log(line.substring(e.getBegin(), e.getEnd()));
//console.log(message);
var index = 0;
for(var i in tokens) {
index += tokens[i].value.length;
}
//console.log("Index: " + index);
//console.log("Begin: " + e.getBegin());
tokens.push({ type: "text", value: line.substring(index) });
return {
tokens: tokens,
state: JSON.stringify(["start"])
};
} else {
throw e;
}
}
}
if(this.tokens[row] !== undefined) {
var idx = 0;
var col = 0;
for(var i in tokens) {
var token = tokens[i];
if(token.type === "keyword") {
for(var j in this.tokens[row]) {
var semanticToken = this.tokens[row][j];
if(semanticToken.sc === col) {
idx = i;
tokens[i].type = "support.function";
}
}
}
col += token.value.length;
}
//for(var i = tokens.length - 1; i > idx; i--) {
// var token = tokens[i];
// if(token.type === "keyword") {
// for(var j in this.tokens[row]) {
// var semanticToken = this.tokens[row][j];
// if(semanticToken.ec === endCol) {
// tokens[i].type = "support.function";
// }
// }
// }
//}
}
return {
tokens: tokens,
state: JSON.stringify(stack)
};
};
};
});

View file

@ -0,0 +1,515 @@
<?xqlint
/* ***** 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 XQueryTokenizer = exports.XQueryTokenizer = function XQueryTokenizer(string, parsingEventHandler)
{
init(string, parsingEventHandler);
?>
start ::= '<![CDATA['
| '<!--'
| '<?'
| '(#'
| '(:~'
| '(:'
| '"'
| "'"
| "}"
| "{"
| "("
| ")"
| Wildcard
| IntegerLiteral
| DecimalLiteral
| DoubleLiteral
| Variable
| EQName
| Tag
| Operator
| EOF
StartTag ::= '>' | '/>' | QName | "=" | '"' | "'" | EOF
TagContent
::= ElementContentChar | Tag | EndTag | '<![CDATA[' | '<!--' | PredefinedEntityRef | CharRef | '{{' | '}}' | '{' | EOF
/* ws: explicit */
AposAttr
::= EscapeApos | AposAttrContentChar | PredefinedEntityRef | CharRef | '{{' | '}}' | '{' | "'" | EOF
/* ws: explicit */
QuotAttr
::= EscapeQuot | QuotAttrContentChar | PredefinedEntityRef | CharRef | '{{' | '}}' | '{' | '"' | EOF
/* ws: explicit */
CData ::= CDataSectionContents | ']]>' | EOF
/* ws: explicit */
XMLComment
::= DirCommentContents | '-->' | EOF
/* ws: explicit */
PI ::= DirPIContents | '?>' | EOF
/* ws: explicit */
Pragma ::= PragmaContents | '#)' | EOF
/* ws: explicit */
Comment ::= CommentContents | ':)' | '(:' | EOF
CommentDoc
::= DocTag | DocCommentContents | ':)' | '(:' | EOF
/* ws: explicit */
QuotString
::= PredefinedEntityRef | CharRef | EscapeQuot | QuotChar | '"' | EOF
/* ws: explicit */
AposString
::= PredefinedEntityRef | CharRef | EscapeApos | AposChar | "'" | EOF
/* ws: explicit */
Whitespace
::= S^WS
/* ws: definition */
EQName ::= FunctionName
| 'attribute'
| 'comment'
| 'document-node'
| 'element'
| 'empty-sequence'
| 'function'
| 'if'
| 'item'
| 'namespace-node'
| 'node'
| 'processing-instruction'
| 'schema-attribute'
| 'schema-element'
| 'switch'
| 'text'
| 'typeswitch'
FunctionName
::= EQName^Token
| 'after'
| 'ancestor'
| 'ancestor-or-self'
| 'and'
| 'as'
| 'ascending'
| 'before'
| 'case'
| 'cast'
| 'castable'
| 'child'
| 'collation'
| 'copy'
| 'count'
| 'declare'
| 'default'
| 'delete'
| 'descendant'
| 'descendant-or-self'
| 'descending'
| 'div'
| 'document'
| 'else'
| 'empty'
| 'end'
| 'eq'
| 'every'
| 'except'
| 'first'
| 'following'
| 'following-sibling'
| 'for'
| 'ge'
| 'group'
| 'gt'
| 'idiv'
| 'import'
| 'insert'
| 'instance'
| 'intersect'
| 'into'
| 'is'
| 'last'
| 'le'
| 'let'
| 'lt'
| 'mod'
| 'modify'
| 'module'
| 'namespace'
| 'ne'
| 'only'
| 'or'
| 'order'
| 'ordered'
| 'parent'
| 'preceding'
| 'preceding-sibling'
| 'rename'
| 'replace'
| 'return'
| 'satisfies'
| 'self'
| 'some'
| 'stable'
| 'start'
| 'to'
| 'treat'
| 'try'
| 'union'
| 'unordered'
| 'validate'
| 'where'
| 'with'
| 'xquery'
| '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'
NCName ::= NCName^Token
| 'after'
| 'and'
| 'as'
| 'ascending'
| 'before'
| 'case'
| 'cast'
| 'castable'
| 'collation'
| 'count'
| 'default'
| 'descending'
| 'div'
| 'else'
| 'empty'
| 'end'
| 'eq'
| 'except'
| 'for'
| 'ge'
| 'group'
| 'gt'
| 'idiv'
| 'instance'
| 'intersect'
| 'into'
| 'is'
| 'le'
| 'let'
| 'lt'
| 'mod'
| 'modify'
| 'ne'
| 'only'
| 'or'
| 'order'
| 'return'
| 'satisfies'
| 'stable'
| 'start'
| 'to'
| 'treat'
| 'union'
| 'where'
| 'with'
| 'ancestor'
| 'ancestor-or-self'
| 'attribute'
| 'child'
| 'comment'
| 'copy'
| 'declare'
| 'delete'
| 'descendant'
| 'descendant-or-self'
| 'document'
| 'document-node'
| 'element'
| 'empty-sequence'
| 'every'
| 'first'
| 'following'
| 'following-sibling'
| 'function'
| 'if'
| 'import'
| 'insert'
| 'item'
| 'last'
| 'module'
| 'namespace'
| 'namespace-node'
| 'node'
| 'ordered'
| 'parent'
| 'preceding'
| 'preceding-sibling'
| 'processing-instruction'
| 'rename'
| 'replace'
| 'schema-attribute'
| 'schema-element'
| 'self'
| 'some'
| 'switch'
| 'text'
| 'try'
| 'typeswitch'
| 'unordered'
| 'validate'
| 'variable'
| 'xquery'
| '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'
| 'version'
| 'while'
| 'constraint'
| 'loop'
| 'returning'
<?TOKENS?>
Operator ::= ':=' | '=' | '<' | '>' | '-' | '+' | 'div'
Variable ::= '$' EQName
Tag ::= '<' QName
EndTag ::= '</' QName S? '>'
PragmaContents
::= ( Char* - ( Char* '#' Char* ) )+
DirCommentContents
::= ( ( Char - '-' ) | '-' ( Char - '-' ) )+
DirPIContents
::= ( Char* - ( Char* '?' Char* ) )
/*
CDataSection
::= '<![CDATA[' CDataSectionContents ']]>'
*/
CDataSectionContents
::= Char* - ( Char* ']]>' Char* )
Wildcard ::= "*"
| (NCName ":" "*")
| ("*" ":" NCName)
| (BracedURILiteral "*")
EQName ::= QName
| URIQualifiedName
URIQualifiedName
::= BracedURILiteral NCName
BracedURILiteral
::= 'Q' '{' (PredefinedEntityRef | CharRef | [^&{}] )* '}'
URILiteral
::= StringLiteral
IntegerLiteral
::= Digits
DecimalLiteral
::= '.' Digits
| Digits '.' [0-9]*
/* ws: explicit */
DoubleLiteral
::= ( '.' Digits | Digits ( '.' [0-9]* )? ) [Ee] [+#x002D]? Digits
/* ws: explicit */
PredefinedEntityRef
::= '&' ( 'lt' | 'gt' | 'amp' | 'quot' | 'apos' ) ';'
/* ws: explicit */
EscapeQuot
::= '""'
EscapeApos
::= "''"
QuotChar ::= (Char - ["&])+
AposChar ::= (Char - [&'])+
ElementContentChar
::= (Char - [&<{}])+
QuotAttrContentChar
::= (Char - ["&<{}])+
AposAttrContentChar
::= (Char - [&'<{}])+
PITarget ::= NCName - ( ( 'X' | 'x' ) ( 'M' | 'm' ) ( 'L' | 'l' ) )
Name ::= NameStartChar NameChar*
NameStartChar
::= [:A-Z_a-z#x00C0-#x00D6#x00D8-#x00F6#x00F8-#x02FF#x0370-#x037D#x037F-#x1FFF#x200C-#x200D#x2070-#x218F#x2C00-#x2FEF#x3001-#xD7FF#xF900-#xFDCF#xFDF0-#xFFFD#x10000-#xEFFFF]
NameChar ::= NameStartChar
| [-.0-9#x00B7#x0300-#x036F#x203F-#x2040]
NCName ::= Name - ( Char* ':' Char* )
Char ::= [#x0009#x000A#x000D#x0020-#xD7FF#xE000-#xFFFD#x10000-#x10FFFF]
QName ::= PrefixedName
| UnprefixedName
PrefixedName
::= Prefix ':' LocalPart
UnprefixedName
::= LocalPart
Prefix ::= NCName
LocalPart
::= NCName
S ::= [#x0009#x000A#x000D#x0020]+
CharRef ::= '&#' [0-9]+ ';'
| '&#x' [0-9A-Fa-f]+ ';'
Digits ::= [0-9]+
CommentContents
::= ( ( Char+ - ( Char* ( '(:' | ':)' ) Char* ) ) - ( Char* '(' ) ) &':'
| ( Char+ - ( Char* ( '(:' | ':)' ) Char* ) ) &'('
DocTag ::= ' @' NCName
DocCommentContents
::= ( ( Char+ - ( Char* ( '(:' | ':)' | ' @' ) Char* ) ) - ( Char* '(' ) ) &':'
| ( Char+ - ( Char* ( '(:' | ':)' | ' @' ) Char* ) ) &'('
| ( Char+ - ( Char* ( '(:' | ':)' | ' @' ) Char* ) ) & ' @'
| ( Char+ - ( Char* ( '(:' | ':)' | ' @' ) Char* ) )
EOF ::= $
NonNCNameChar
::= $
| ':'
| ( Char - NameChar )
DelimitingChar
::= NonNCNameChar
| '-'
| '.'
DelimitingChar
\\ IntegerLiteral DecimalLiteral DoubleLiteral
NonNCNameChar
\\ EQName^Token QName NCName^Token 'NaN' 'after' 'all'
'allowing' 'ancestor' 'ancestor-or-self' 'and' 'any'
'append' 'array' 'as' 'ascending' 'at' 'attribute'
'base-uri' 'before' 'boundary-space' 'break' 'by' 'case'
'cast' 'castable' 'catch' 'check' 'child' 'collation'
'collection' 'comment' 'constraint' 'construction'
'contains' 'content' 'context' 'continue' 'copy'
'copy-namespaces' 'count' 'decimal-format'
'decimal-separator' 'declare' 'default' 'delete'
'descendant' 'descendant-or-self' 'descending'
'diacritics' 'different' 'digit' 'distance' 'div'
'document' 'document-node' 'element' 'else' 'empty'
'empty-sequence' 'encoding' 'end' 'entire' 'eq' 'every'
'exactly' 'except' 'exit' 'external' 'first' 'following'
'following-sibling' 'for' 'foreach' 'foreign' 'from'
'ft-option' 'ftand' 'ftnot' 'ftor' 'function' 'ge'
'greatest' 'group' 'grouping-separator' 'gt' 'idiv' 'if'
'import' 'in' 'index' 'infinity' 'inherit' 'insensitive'
'insert' 'instance' 'integrity' 'intersect' 'into' 'is'
'item' 'json' 'json-item' 'key' 'language' 'last' 'lax'
'le' 'least' 'let' 'levels' 'loop' 'lowercase' 'lt'
'minus-sign' 'mod' 'modify' 'module' 'most' 'namespace'
'namespace-node' 'ne' 'next' 'no' 'no-inherit'
'no-preserve' 'node' 'nodes' 'not' 'object' 'occurs'
'of' 'on' 'only' 'option' 'or' 'order' 'ordered'
'ordering' 'paragraph' 'paragraphs' 'parent'
'pattern-separator' 'per-mille' 'percent' 'phrase'
'position' 'preceding' 'preceding-sibling' 'preserve'
'previous' 'processing-instruction' 'relationship'
'rename' 'replace' 'return' 'returning' 'revalidation'
'same' 'satisfies' 'schema' 'schema-attribute'
'schema-element' 'score' 'self' 'sensitive' 'sentence'
'sentences' 'skip' 'sliding' 'some' 'stable' 'start'
'stemming' 'stop' 'strict' 'strip' 'structured-item'
'switch' 'text' 'then' 'thesaurus' 'times' 'to'
'treat' 'try' 'tumbling' 'type' 'typeswitch' 'union'
'unique' 'unordered' 'updating' 'uppercase' 'using'
'validate' 'value' 'variable' 'version' 'weight'
'when' 'where' 'while' 'wildcards' 'window' 'with'
'without' 'word' 'words' 'xquery' 'zero-digit'
'*' << Wildcard '*'^OccurrenceIndicator
EQName^Token
<< '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' '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'
NCName^Token
<< 'after' 'and' 'as' 'ascending' 'before' 'case' 'cast' 'castable' 'collation' 'count' 'default' 'descending' 'div' 'else' 'empty' 'end' 'eq' 'except' 'for' 'ge' 'group' 'gt' 'idiv' 'instance' 'intersect' 'into' 'is' 'le' 'let' 'lt' 'mod' 'modify' 'ne' 'only' 'or' 'order' 'return' 'satisfies' 'stable' 'start' 'to' 'treat' 'union' 'where' 'with' 'contains' 'paragraphs' 'sentences' 'times' 'words' 'by' 'ancestor' 'ancestor-or-self' 'attribute' 'child' 'comment' 'copy' 'declare' 'delete' 'descendant' 'descendant-or-self' 'document' 'document-node' 'element' 'empty-sequence' 'every' 'first' 'following' 'following-sibling' 'function' 'if' 'import' 'insert' 'item' 'last' 'module' 'namespace' 'namespace-node' 'node' 'ordered' 'parent' 'preceding' 'preceding-sibling' 'processing-instruction' 'rename' 'replace' 'schema-attribute' 'schema-element' 'self' 'some' 'switch' 'text' 'try' 'typeswitch' 'unordered' 'validate' 'variable' 'xquery' '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' 'version' 'while' 'constraint' 'loop' 'returning'
<?ENCORE?>
<?xqlint
});
?>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,75 @@
/* ***** 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 SemanticHighlighter = exports.SemanticHighlighter = function(ast) {
this.tokens = new Array(ast.pos.el + 1);
this.getTokens = function() {
this.visit(ast);
return this.tokens;
};
this.EQName = function(node)
{
var row = node.pos.sl;
this.tokens[row] = this.tokens[row] === undefined ? [] : this.tokens[row] ;
this.tokens[row].push(node.pos);
return true;
};
this.visit = function(node) {
var name = node.name;
var skip = false;
if (typeof this[name] === "function") skip = this[name](node) === true ? true : false;
if (!skip) {
this.visitChildren(node);
}
};
this.visitChildren = function(node, handler) {
for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
if (handler !== undefined && typeof handler[child.name] === "function") {
handler[child.name](child);
}
else {
this.visit(child);
}
}
};
};
});

View file

@ -35,7 +35,7 @@ var oop = require("../lib/oop");
var Mirror = require("../worker/mirror").Mirror;
var JSONParseTreeHandler = require("./xquery/JSONParseTreeHandler").JSONParseTreeHandler;
var XQueryParser = require("./xquery/XQueryParser").XQueryParser;
var SyntaxHighlighter = require("./xquery/visitors/SyntaxHighlighter").SyntaxHighlighter;
var SemanticHighlighter = require("./xquery/visitors/SemanticHighlighter").SemanticHighlighter;
var XQueryWorker = exports.XQueryWorker = function(sender) {
Mirror.call(this, sender);
@ -55,7 +55,7 @@ oop.inherits(XQueryWorker, Mirror);
parser.parse_XQuery();
this.sender.emit("ok");
var ast = h.getParseTree();
var highlighter = new SyntaxHighlighter(ast);
var highlighter = new SemanticHighlighter(ast);
var tokens = highlighter.getTokens();
this.sender.emit("highlight", tokens);
} catch(e) {