Update XQuery Parser.
This commit is contained in:
parent
34b2e292c7
commit
f2a9bd1b02
12 changed files with 28956 additions and 66662 deletions
|
|
@ -1,53 +0,0 @@
|
|||
/* ***** 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 Position = exports.Position = function(line, offset, length)
|
||||
{
|
||||
this.line = line;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
|
||||
this.getLine = function()
|
||||
{
|
||||
return this.line;
|
||||
};
|
||||
|
||||
this.getOffset = function()
|
||||
{
|
||||
return this.offset;
|
||||
};
|
||||
|
||||
this.getLength = function()
|
||||
{
|
||||
return this.length;
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,63 +0,0 @@
|
|||
/* ***** 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 org = require("./antlr3-all").org;
|
||||
|
||||
var XQDTLexer = exports.XQDTLexer = function(input, state)
|
||||
{
|
||||
XQDTLexer.superclass.constructor.call(this, input, state);
|
||||
};
|
||||
|
||||
org.antlr.lang.extend(XQDTLexer, org.antlr.runtime.Lexer, {
|
||||
|
||||
comments: [],
|
||||
|
||||
addComment: function(start, stop){ this.comments.push({ start: start, stop: stop }); },
|
||||
|
||||
isWsExplicit: false,
|
||||
|
||||
setIsWsExplicit: function (wsExplicit) {
|
||||
//console.log("A WS: " + wsExplicit);
|
||||
this.isWsExplicit = wsExplicit;
|
||||
//console.log("B WS: " + wsExplicit);
|
||||
},
|
||||
|
||||
addToStack: function (stack) {
|
||||
stack.push(this);
|
||||
},
|
||||
|
||||
rewindToIndex: function(index) {
|
||||
var stream = this.input;
|
||||
stream.seek(index);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
/* ***** 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 org = require("./antlr3-all").org;
|
||||
var XQuerySemanticHighlighter = require("./XQuerySemanticHighlighter").XQuerySemanticHighlighter;
|
||||
|
||||
var XQDTParser = exports.XQDTParser = function(input, state)
|
||||
{
|
||||
this.highlighter = new XQuerySemanticHighlighter();
|
||||
var that = this;
|
||||
|
||||
input.getTokenSource().addComment = function(start, stop) {
|
||||
var comments = input.getTokenSource().comments;
|
||||
for(var i in comments)
|
||||
{
|
||||
var c = comments[i];
|
||||
that.highlighter.addToken(c.start, c.stop, "comment");
|
||||
}
|
||||
input.getTokenSource().comments = [];
|
||||
that.highlighter.addToken(start, stop, "comment")
|
||||
};
|
||||
XQDTParser.superclass.constructor.call(this, input, state);
|
||||
};
|
||||
|
||||
org.antlr.lang.extend(XQDTParser, org.antlr.runtime.Parser, {
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,161 +0,0 @@
|
|||
/* ***** 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 Position = require("./Position").Position;
|
||||
var XQuerySemanticHighlighter = exports.XQuerySemanticHighlighter = function() {
|
||||
this.tokenizer = null;
|
||||
this.plain = null;
|
||||
this.source = [];
|
||||
this.lines = [];
|
||||
|
||||
this.getTokens = function() {
|
||||
var resultLines = new Array(this.source.length);
|
||||
var resultStates = new Array(this.source.length);
|
||||
var previousState = "start";
|
||||
var i = 0;
|
||||
for(i in this.source){
|
||||
var lineTokens = [];
|
||||
var tokens = [];
|
||||
if(this.lines[i]) {
|
||||
tokens = this.lines[i].sort(function(a, b){ return a.position.getOffset() - b.position.getOffset(); });
|
||||
}
|
||||
var sourceLine = this.source[i];
|
||||
var tokenizedLine = "";
|
||||
var cursor = 0;
|
||||
var j = 0;
|
||||
for(j in tokens)
|
||||
{
|
||||
var token = tokens[j];
|
||||
var position = token.position;
|
||||
if(position.getOffset() > cursor) {
|
||||
var value = sourceLine.substring(cursor, position.getOffset());
|
||||
tokenizedLine += value;
|
||||
lineTokens.push({
|
||||
type: "text",
|
||||
value: value
|
||||
});
|
||||
}
|
||||
cursor = position.getOffset() + position.getLength();
|
||||
value = sourceLine.substring(position.getOffset(), cursor);
|
||||
tokenizedLine += value;
|
||||
lineTokens.push({
|
||||
type: token.type,
|
||||
value: value
|
||||
});
|
||||
}
|
||||
|
||||
var nextState = "start";
|
||||
if(lineTokens.length > 0) {
|
||||
lineTokens[lineTokens.length - 1].type;
|
||||
}
|
||||
nextState = (nextState != "comment" && nextState != "string" && nextState != "cdata" && nextState != "tag") ? "start" : nextState;
|
||||
|
||||
if(cursor < (sourceLine.length )) {
|
||||
value = sourceLine.substring(cursor);
|
||||
lineTokens.push({
|
||||
type: "text",
|
||||
value: value
|
||||
});
|
||||
tokenizedLine += value;
|
||||
}
|
||||
//Check if the tokenized line is equal to the original one:
|
||||
if(sourceLine == tokenizedLine) {
|
||||
resultLines[i] = lineTokens;
|
||||
resultStates[i] = nextState;
|
||||
//result[i] = { line: sourceLine, startState: previousState, tokens: { tokens: lineTokens, state: nextState } };
|
||||
} else {
|
||||
//console.log("sourceLine: " + sourceLine);
|
||||
//console.log("tokenizedLine: " + tokenizedLine);
|
||||
resultLines[i] = [{ type: "text", value: sourceLine }];
|
||||
resultStates[i] = nextState;
|
||||
//result[i] = { tokens: [ { type: "text", value: sourceLine } ], state: nextState };
|
||||
}
|
||||
|
||||
if(resultLines[i].length === 1 && resultLines[i][0].type === "text" && this.tokenizer instanceof Object) {
|
||||
var prev = resultStates[i - 1] ? resultStates[i - 1] : "start";
|
||||
var result = this.tokenizer.getLineTokens(resultLines[i][0].value, prev);
|
||||
resultLines[i] = result.tokens;
|
||||
resultStates[i] = result.state;
|
||||
}
|
||||
}
|
||||
return {states: resultStates, lines: resultLines};
|
||||
};
|
||||
|
||||
this.addToken = function(start, stop, type) {
|
||||
var before = this.plain.substring(0, start);
|
||||
var startLine = this.plain.substring(0, start).split("\n").length;
|
||||
startLine = startLine == 0 ? 0 : startLine - 1;
|
||||
|
||||
var offset = before.lastIndexOf("\n");
|
||||
offset = offset == -1 ? start : start - before.lastIndexOf("\n") - 1;
|
||||
|
||||
var cursor = start;
|
||||
|
||||
var text = this.plain.substring(start, stop);
|
||||
|
||||
var currentLine = startLine;
|
||||
for(var i in text)
|
||||
{
|
||||
var c = text[i];
|
||||
if(c == "\n") {
|
||||
var s = i;
|
||||
s = s < stop ? s : stop;
|
||||
this.addPosition(new Position(currentLine, offset, s), type);
|
||||
currentLine++;
|
||||
offset = 0;
|
||||
cursor = i;
|
||||
}
|
||||
};
|
||||
this.addPosition(new Position(currentLine, offset, stop - cursor + 1), type);
|
||||
};
|
||||
|
||||
this.addPosition = function(position, type)
|
||||
{
|
||||
var line = position.getLine();
|
||||
if(!this.lines[line]) {
|
||||
this.lines[line] = [];
|
||||
}
|
||||
this.lines[line].push({
|
||||
type: type,
|
||||
position: position
|
||||
});
|
||||
};
|
||||
|
||||
this.setSource = function(source)
|
||||
{
|
||||
this.plain = source.data;
|
||||
this.source = this.plain.split("\n");
|
||||
};
|
||||
//console.log("Line: " + token.getLine());
|
||||
//console.log(token.getText());
|
||||
//console.log(type);
|
||||
};
|
||||
});
|
||||
File diff suppressed because it is too large
Load diff
315
lib/ace/mode/xquery/visitors/SyntaxHighlighter.js
Normal file
315
lib/ace/mode/xquery/visitors/SyntaxHighlighter.js
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
define(function(require, exports, module){
|
||||
|
||||
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 states = ["cdata", "comment", "tag"];
|
||||
var info = { lines: [ [] ], states: [] };
|
||||
var inName = false;
|
||||
|
||||
this.getTokens = function() {
|
||||
this.visit(tree);
|
||||
return info;
|
||||
};
|
||||
|
||||
this.addTokens = function(value, type)
|
||||
{
|
||||
var tokens = value.split("\n");
|
||||
var lastState = "start";
|
||||
for(var i in tokens)
|
||||
{
|
||||
if(i > 0) {
|
||||
info.lines.push([]);
|
||||
info.states.push(lastState);
|
||||
}
|
||||
var value = tokens[i];
|
||||
var linesLength = info.lines.length - 1;
|
||||
var linesIdx = info.lines[linesLength];
|
||||
linesIdx.push({ value: value, type: type });
|
||||
lastState = states.indexOf(type) != -1 ? type : "start";
|
||||
}
|
||||
};
|
||||
|
||||
this.getNodeValue = function(node)
|
||||
{
|
||||
return source.substring(node.begin, node.end);
|
||||
};
|
||||
|
||||
this.DirPIConstructor = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "xml_pe");
|
||||
return true;
|
||||
};
|
||||
|
||||
this.DirElemConstructor = function(node)
|
||||
{
|
||||
for(var i in node.children)
|
||||
{
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN" || child.name === "QName") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "meta.tag");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.DirAttributeList = function(node)
|
||||
{
|
||||
for(var i in node.children)
|
||||
{
|
||||
var child = node.children[i];
|
||||
if(child.name === "QName") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "meta.tag");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.DirAttributeValue = function(node)
|
||||
{
|
||||
for(var i in node.children)
|
||||
{
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "string");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.QuotAttrContentChar = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "string");
|
||||
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)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "keyword.operator");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.AdditiveExpr = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "keyword.operator");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.MultiplicativeExpr = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "keyword.operator");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.UnaryExpr = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "keyword.operator");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.GeneralComp = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "keyword.operator");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
this.NumericLiteral = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name != "TEXT") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "constant");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}return true;
|
||||
}
|
||||
|
||||
this.DirCommentConstructor = function(node)
|
||||
{
|
||||
for(var i in node.children) {
|
||||
var child = node.children[i];
|
||||
if(child.name != "TEXT") {
|
||||
var value = this.getNodeValue(child);
|
||||
this.addTokens(value, "comment");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}return true;
|
||||
}
|
||||
|
||||
this.Comment = function(node)
|
||||
{
|
||||
return true;
|
||||
};
|
||||
|
||||
this.URILiteral = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "string");
|
||||
return true;
|
||||
};
|
||||
|
||||
this.StringLiteral = function(node)
|
||||
{
|
||||
var value = this.getNodeValue(node);
|
||||
this.addTokens(value, "string");
|
||||
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)
|
||||
{
|
||||
inName = true;
|
||||
for(var i in node.children)
|
||||
{
|
||||
var child = node.children[i];
|
||||
this.visit(child);
|
||||
}
|
||||
inName = false;
|
||||
return true;
|
||||
};
|
||||
|
||||
this.TOKEN = function(node)
|
||||
{
|
||||
value = node.children[0].value;
|
||||
if(keywords.indexOf(value) > -1 && !inName) {
|
||||
this.addTokens(value, "keyword");
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
this.EverythingElse = function(node)
|
||||
{
|
||||
if(typeof node["pos"] === "object")
|
||||
{
|
||||
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");
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
this.visit = function(node){
|
||||
var name = node.name;
|
||||
var skip = false;
|
||||
|
||||
if(typeof this[name] === "function")
|
||||
skip = this[name](node) === true ? true : false ;
|
||||
else
|
||||
skip = this.EverythingElse(node) === true ? true : false;
|
||||
|
||||
if(!skip && typeof node.children === "object")
|
||||
{
|
||||
for(var i = 0; i < node.children.length; i++)
|
||||
{
|
||||
var child = node.children[i];
|
||||
if(child.name === "TOKEN" && child.children[0].value === "$") {
|
||||
i++;
|
||||
var next = node.children[i];
|
||||
var value = source.substring(child.children[0].pos.begin, next.end);
|
||||
this.addTokens(value, "variable");
|
||||
} else {
|
||||
this.visit(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
});
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/* ***** 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 antlr = require("./antlr3-all");
|
||||
var org = antlr.org;
|
||||
var NewLazyTokenStream = antlr.NewLazyTokenStream;
|
||||
var XQueryLexer = require("./XQueryLexer").XQueryLexer;
|
||||
var XQueryParser = require("./XQueryParser").XQueryParser;
|
||||
|
||||
exports.getParser = function(code) {
|
||||
var cstream = new org.antlr.runtime.ANTLRStringStream(code);
|
||||
var lexer = new XQueryLexer(cstream);
|
||||
var tstream = new NewLazyTokenStream(lexer);
|
||||
tstream.jumpToFirstValidToken();
|
||||
var parser = new XQueryParser(tstream);
|
||||
parser.setSource(cstream);
|
||||
return parser;
|
||||
};
|
||||
});
|
||||
|
|
@ -33,10 +33,8 @@ define(function(require, exports, module) {
|
|||
|
||||
var oop = require("../lib/oop");
|
||||
var Mirror = require("../worker/mirror").Mirror;
|
||||
var xquery = require("../mode/xquery/xquery");
|
||||
var Tokenizer = require("../tokenizer").Tokenizer;
|
||||
var XQueryHighlightRules = require("./xquery_highlight_rules").XQueryHighlightRules;
|
||||
|
||||
var XQueryParser = require("./xquery/XQueryParser").XQueryParser;
|
||||
var SyntaxHighlighter = require("../mode/xquery/visitors/SyntaxHighlighter").SyntaxHighlighter;
|
||||
window.addEventListener = function() {};
|
||||
|
||||
|
||||
|
|
@ -52,26 +50,26 @@ oop.inherits(XQueryWorker, Mirror);
|
|||
this.onUpdate = function() {
|
||||
this.sender.emit("start");
|
||||
var value = this.doc.getValue();
|
||||
var parser = xquery.getParser(value);
|
||||
var ast = parser.p_Module();
|
||||
if(parser.hasErrors()) {
|
||||
var errors = parser.getErrors();
|
||||
var i = 0;
|
||||
for(i in errors) {
|
||||
var error = errors[i];
|
||||
this.sender.emit("error", {
|
||||
row: error.line,
|
||||
column: error.column,
|
||||
text: error.message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.sender.emit("ok");
|
||||
var parser = new XQueryParser(value);
|
||||
try {
|
||||
parser.parse_XQuery();
|
||||
var ast = parser.getAST();
|
||||
this.sender.emit("ok");
|
||||
var highlighter = new SyntaxHighlighter(value, ast);
|
||||
var tokens = highlighter.getTokens();
|
||||
this.sender.emit("highlight", tokens);
|
||||
} catch(e) {
|
||||
var prefix = value.substring(0, e.getBegin());
|
||||
var line = prefix.split("\n").length;
|
||||
var column = e.getBegin() - prefix.lastIndexOf("\n");
|
||||
var message = parser.getErrorMessage(e);
|
||||
this.sender.emit("error", {
|
||||
row: line - 1,
|
||||
column: column,
|
||||
text: message,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
parser.highlighter.tokenizer = new Tokenizer(new XQueryHighlightRules().getRules());
|
||||
var tokens = parser.highlighter.getTokens();
|
||||
this.sender.emit("highlight", tokens);
|
||||
};
|
||||
|
||||
}).call(XQueryWorker.prototype);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue