Update xqlint with code completion
This commit is contained in:
parent
4e23984ddb
commit
ea532e41bf
5 changed files with 77415 additions and 77120 deletions
|
|
@ -72,7 +72,7 @@ oop.inherits(Mode, TextMode);
|
||||||
if (! /^\s+$/.test(line))
|
if (! /^\s+$/.test(line))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return /^\s*[\}\)]/.test(input);
|
return (/^\s*[\}\)]/).test(input);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.autoOutdent = function(state, doc, row) {
|
this.autoOutdent = function(state, doc, row) {
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ exports.VarRefHandler = function(translator, sctx, node){
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
},{"../tree_ops":9,"./errors":1}],3:[function(_dereq_,module,exports){
|
},{"../tree_ops":10,"./errors":1}],3:[function(_dereq_,module,exports){
|
||||||
exports.StaticContext = function (parent, pos) {
|
exports.StaticContext = function (parent, pos) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
@ -265,6 +265,7 @@ exports.StaticContext = function (parent, pos) {
|
||||||
|
|
||||||
var s = {
|
var s = {
|
||||||
parent: parent,
|
parent: parent,
|
||||||
|
children: [],
|
||||||
pos: pos,
|
pos: pos,
|
||||||
setModuleResolver: function(resolver){
|
setModuleResolver: function(resolver){
|
||||||
this.root.moduleResolver = resolver;
|
this.root.moduleResolver = resolver;
|
||||||
|
|
@ -274,6 +275,7 @@ exports.StaticContext = function (parent, pos) {
|
||||||
defaultFunctionNamespace: '',
|
defaultFunctionNamespace: '',
|
||||||
defaultElementNamespace: '',
|
defaultElementNamespace: '',
|
||||||
namespaces: namespaces,
|
namespaces: namespaces,
|
||||||
|
availableModuleNamespaces: [],
|
||||||
importModule: function(uri, prefix, pos) {
|
importModule: function(uri, prefix, pos) {
|
||||||
this.root.addNamespace(uri, prefix, pos, 'module');
|
this.root.addNamespace(uri, prefix, pos, 'module');
|
||||||
if(this.root.moduleResolver) {
|
if(this.root.moduleResolver) {
|
||||||
|
|
@ -287,6 +289,12 @@ exports.StaticContext = function (parent, pos) {
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
getAvailableModuleNamespaces: function(){
|
||||||
|
return this.root.availableModuleNamespaces;
|
||||||
|
},
|
||||||
|
getPrefixByNamespace: function(uri){
|
||||||
|
return this.root.namespaces[uri].prefix;
|
||||||
|
},
|
||||||
addNamespace: function (uri, prefix, pos, type) {
|
addNamespace: function (uri, prefix, pos, type) {
|
||||||
if(prefix === '' && type === 'module') {
|
if(prefix === '' && type === 'module') {
|
||||||
throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead');
|
throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead');
|
||||||
|
|
@ -320,6 +328,11 @@ exports.StaticContext = function (parent, pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getNamespaces: function(){
|
||||||
|
return this.root.namespaces;
|
||||||
|
},
|
||||||
|
|
||||||
getNamespace: function (uri) {
|
getNamespace: function (uri) {
|
||||||
var that = this;
|
var that = this;
|
||||||
while (that) {
|
while (that) {
|
||||||
|
|
@ -382,7 +395,10 @@ exports.StaticContext = function (parent, pos) {
|
||||||
varRefs: {},
|
varRefs: {},
|
||||||
|
|
||||||
addVariable: function(qname, type, pos){
|
addVariable: function(qname, type, pos){
|
||||||
if(type === 'VarDecl' && qname.uri !== this.moduleNamespace && this.moduleNamespace !== '') {
|
if(
|
||||||
|
type === 'VarDecl' && this.moduleNamespace !== '' &&
|
||||||
|
!(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))
|
||||||
|
) {
|
||||||
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
|
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
|
||||||
}
|
}
|
||||||
var key = getVarKey(qname);
|
var key = getVarKey(qname);
|
||||||
|
|
@ -397,6 +413,21 @@ exports.StaticContext = function (parent, pos) {
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getVariables: function(){
|
||||||
|
var variables = {};
|
||||||
|
var that = this;
|
||||||
|
var handler = function(key){
|
||||||
|
if(!variables[key]){
|
||||||
|
variables[key] = that.variables[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
while(that){
|
||||||
|
Object.keys(that.variables).forEach(handler);
|
||||||
|
that = that.parent;
|
||||||
|
}
|
||||||
|
return variables;
|
||||||
|
},
|
||||||
|
|
||||||
getVariable: function(qname) {
|
getVariable: function(qname) {
|
||||||
var key = getVarKey(qname);
|
var key = getVarKey(qname);
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
@ -420,6 +451,10 @@ exports.StaticContext = function (parent, pos) {
|
||||||
|
|
||||||
functions: {},
|
functions: {},
|
||||||
|
|
||||||
|
getFunctions: function(){
|
||||||
|
return this.root.functions;
|
||||||
|
},
|
||||||
|
|
||||||
getFunction: function(qname, arity){
|
getFunction: function(qname, arity){
|
||||||
var key = getFnKey(qname, arity);
|
var key = getFnKey(qname, arity);
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
@ -431,8 +466,12 @@ exports.StaticContext = function (parent, pos) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addFunction: function(qname, arity, pos) {
|
addFunction: function(qname, pos, params) {
|
||||||
if(qname.uri !== this.moduleNamespace && this.moduleNamespace !== '') {
|
var arity = params.length;
|
||||||
|
if(
|
||||||
|
this.moduleNamespace !== '' &&
|
||||||
|
!(this.moduleNamespace === qname.uri || (qname.uri === '' && this.defaultFunctionNamespace === this.moduleNamespace))
|
||||||
|
) {
|
||||||
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
|
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
|
||||||
}
|
}
|
||||||
var key = getFnKey(qname, arity);
|
var key = getFnKey(qname, arity);
|
||||||
|
|
@ -440,7 +479,8 @@ exports.StaticContext = function (parent, pos) {
|
||||||
throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos);
|
throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos);
|
||||||
}
|
}
|
||||||
this.functions[key] = {
|
this.functions[key] = {
|
||||||
pos: pos
|
pos: pos,
|
||||||
|
params: params
|
||||||
};
|
};
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -449,7 +489,7 @@ exports.StaticContext = function (parent, pos) {
|
||||||
s.root = parent ? parent.root : s;
|
s.root = parent ? parent.root : s;
|
||||||
return s;
|
return s;
|
||||||
};
|
};
|
||||||
},{"../tree_ops":9,"./errors":1}],4:[function(_dereq_,module,exports){
|
},{"../tree_ops":10,"./errors":1}],4:[function(_dereq_,module,exports){
|
||||||
exports.Translator = function(rootStcx, ast){
|
exports.Translator = function(rootStcx, ast){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
@ -461,20 +501,6 @@ exports.Translator = function(rootStcx, ast){
|
||||||
var StaticContext = _dereq_('./static_context').StaticContext;
|
var StaticContext = _dereq_('./static_context').StaticContext;
|
||||||
var Handlers = _dereq_('./handlers');
|
var Handlers = _dereq_('./handlers');
|
||||||
|
|
||||||
var astAsXML = function(node, indent){
|
|
||||||
var result = '';
|
|
||||||
indent = indent ? indent : '';
|
|
||||||
if(node.value) {
|
|
||||||
result += (indent + '<' + node.name + '>' + node.value + '</' + node.name + '>\n');
|
|
||||||
}
|
|
||||||
result += indent + '<' + node.name + '>\n';
|
|
||||||
node.children.forEach(function(child){
|
|
||||||
result += astAsXML(child, indent + ' ');
|
|
||||||
});
|
|
||||||
result += indent + '</' + node.name + '>\n';
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
var get = function(node, path){
|
var get = function(node, path){
|
||||||
var result;
|
var result;
|
||||||
if(path.length === 0){
|
if(path.length === 0){
|
||||||
|
|
@ -527,12 +553,11 @@ exports.Translator = function(rootStcx, ast){
|
||||||
|
|
||||||
var translator = this;
|
var translator = this;
|
||||||
|
|
||||||
rootStcx = rootStcx ? rootStcx : new StaticContext();
|
|
||||||
rootStcx.pos = ast.pos;
|
rootStcx.pos = ast.pos;
|
||||||
var sctx = rootStcx;
|
var sctx = rootStcx;
|
||||||
|
|
||||||
var pushSctx = function(pos){
|
var pushSctx = function(pos){
|
||||||
sctx = new StaticContext(sctx, pos);
|
sctx = new StaticContext(sctx, pos);
|
||||||
|
sctx.parent.children.push(sctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
var popSctx = function(pos){
|
var popSctx = function(pos){
|
||||||
|
|
@ -540,6 +565,7 @@ exports.Translator = function(rootStcx, ast){
|
||||||
sctx.pos.el = pos.el;
|
sctx.pos.el = pos.el;
|
||||||
sctx.pos.ec = pos.ec;
|
sctx.pos.ec = pos.ec;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(sctx.varRefs).forEach(function(key){
|
Object.keys(sctx.varRefs).forEach(function(key){
|
||||||
if(!sctx.variables[key]) {
|
if(!sctx.variables[key]) {
|
||||||
sctx.parent.varRefs[key] = true;
|
sctx.parent.varRefs[key] = true;
|
||||||
|
|
@ -593,7 +619,7 @@ exports.Translator = function(rootStcx, ast){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if(node.name === 'FunctionDecl') {
|
} else if(node.name === 'FunctionDecl') {
|
||||||
var qname, arity = 0, pos;
|
var qname, pos, params = [];
|
||||||
node.children.forEach(function(child){
|
node.children.forEach(function(child){
|
||||||
if(child.name === 'EQName') {
|
if(child.name === 'EQName') {
|
||||||
qname = child;
|
qname = child;
|
||||||
|
|
@ -601,7 +627,7 @@ exports.Translator = function(rootStcx, ast){
|
||||||
} else if(child.name === 'ParamList'){
|
} else if(child.name === 'ParamList'){
|
||||||
child.children.forEach(function(c){
|
child.children.forEach(function(c){
|
||||||
if(c.name === 'Param') {
|
if(c.name === 'Param') {
|
||||||
arity++;
|
params.push(TreeOps.flatten(c));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -609,7 +635,7 @@ exports.Translator = function(rootStcx, ast){
|
||||||
translator.apply(function(){
|
translator.apply(function(){
|
||||||
qname = TreeOps.flatten(qname);
|
qname = TreeOps.flatten(qname);
|
||||||
qname = rootStcx.resolveQName(qname, pos);
|
qname = rootStcx.resolveQName(qname, pos);
|
||||||
rootStcx.addFunction(qname, arity, pos);
|
rootStcx.addFunction(qname, pos, params);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -954,7 +980,212 @@ exports.Translator = function(rootStcx, ast){
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"../tree_ops":9,"./errors":1,"./handlers":2,"./static_context":3}],5:[function(_dereq_,module,exports){
|
},{"../tree_ops":10,"./errors":1,"./handlers":2,"./static_context":3}],5:[function(_dereq_,module,exports){
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var TreeOps = _dereq_('../tree_ops').TreeOps;
|
||||||
|
|
||||||
|
var ID_REGEX = /[a-zA-Z_0-9\$]/;
|
||||||
|
|
||||||
|
function retrievePrecedingIdentifier(text, pos, regex) {
|
||||||
|
console.log(text);
|
||||||
|
console.log(pos);
|
||||||
|
regex = regex || ID_REGEX;
|
||||||
|
var buf = [];
|
||||||
|
for (var i = pos-1; i >= 0; i--) {
|
||||||
|
if (regex.test(text[i])) {
|
||||||
|
buf.push(text[i]);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf.reverse().join('');
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
function retrieveFollowingIdentifier(text, pos, regex) {
|
||||||
|
regex = regex || ID_REGEX;
|
||||||
|
var buf = [];
|
||||||
|
for (var i = pos; i < text.length; i++) {
|
||||||
|
if (regex.test(text[i])) {
|
||||||
|
buf.push(text[i]);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
function prefixBinarySearch(items, prefix) {
|
||||||
|
var startIndex = 0;
|
||||||
|
var stopIndex = items.length - 1;
|
||||||
|
var middle = Math.floor((stopIndex + startIndex) / 2);
|
||||||
|
|
||||||
|
while (stopIndex > startIndex && middle >= 0 && items[middle].indexOf(prefix) !== 0) {
|
||||||
|
if (prefix < items[middle]) {
|
||||||
|
stopIndex = middle - 1;
|
||||||
|
} else if (prefix > items[middle]) {
|
||||||
|
startIndex = middle + 1;
|
||||||
|
}
|
||||||
|
middle = Math.floor((stopIndex + stopIndex) / 2);
|
||||||
|
}
|
||||||
|
while (middle > 0 && items[middle-1].indexOf(prefix) === 0) {
|
||||||
|
middle--;
|
||||||
|
}
|
||||||
|
return middle >= 0 ? middle : 0; // ensure we're not returning a negative index
|
||||||
|
}
|
||||||
|
|
||||||
|
var uriRegex = /[a-zA-Z_0-9\/\.:\-#]/;
|
||||||
|
var char = '-._A-Za-z0-9:\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02ff\u0300-\u037D\u037F-\u1FFF\u200C\u200D\u203f\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD';
|
||||||
|
var nameChar = '[' + char + ']';
|
||||||
|
//var varChar = '[' + char + '\\$]';
|
||||||
|
var nameCharRegExp = new RegExp(nameChar);
|
||||||
|
//var varCharRegExp = new RegExp(varChar);
|
||||||
|
|
||||||
|
var findCompletions = function(prefix, allIdentifiers) {
|
||||||
|
allIdentifiers.sort();
|
||||||
|
var startIdx = prefixBinarySearch(allIdentifiers, prefix);
|
||||||
|
var matches = [];
|
||||||
|
for (var i = startIdx; i < allIdentifiers.length && allIdentifiers[i].indexOf(prefix) === 0; i++) {
|
||||||
|
matches.push(allIdentifiers[i]);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var completePrefix = function(identifier, pos, sctx){
|
||||||
|
var idx = identifier.indexOf(':');
|
||||||
|
if(idx === -1) {
|
||||||
|
var prefixes = [];
|
||||||
|
var namespaces = sctx.getNamespaces();
|
||||||
|
Object.keys(namespaces).forEach(function(key){
|
||||||
|
if(namespaces[key].type === 'module') {
|
||||||
|
prefixes.push(namespaces[key].prefix);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var matches = findCompletions(identifier, prefixes);
|
||||||
|
var match = function(name) {
|
||||||
|
return {
|
||||||
|
name: name + ':',
|
||||||
|
score: 8,
|
||||||
|
value: name + ':'
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return matches.map(match);
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var completeFunction = function(identifier, pos, sctx){
|
||||||
|
var names = [];
|
||||||
|
var functions = sctx.getFunctions();
|
||||||
|
var uri = '';
|
||||||
|
var prefix = '';
|
||||||
|
var name = identifier;
|
||||||
|
var idx = identifier.indexOf(':');
|
||||||
|
if(idx !== -1){
|
||||||
|
prefix = identifier.substring(0, idx);
|
||||||
|
name = identifier.substring(idx + 1);
|
||||||
|
uri = sctx.getNamespaceByPrefix(prefix).uri;
|
||||||
|
}
|
||||||
|
Object.keys(functions).forEach(function(key){
|
||||||
|
var fn = functions[key];
|
||||||
|
var ns = key.substring(0, key.indexOf('#'));
|
||||||
|
var name = key.substring(key.indexOf('#') + 1);
|
||||||
|
name = name.substring(0, name.indexOf('#'));
|
||||||
|
if(ns !== ''){
|
||||||
|
name = sctx.getNamespaces()[ns].prefix + ':' + name;
|
||||||
|
}
|
||||||
|
name += '(';
|
||||||
|
name += fn.params.join(', ');
|
||||||
|
name += ')';
|
||||||
|
names.push(name);
|
||||||
|
});
|
||||||
|
var matches = findCompletions(identifier, names);
|
||||||
|
var match = function(name) {
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
score: 4,
|
||||||
|
value: name
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return matches.map(match);
|
||||||
|
};
|
||||||
|
|
||||||
|
var completeVariable = function(identifier, pos, sctx){
|
||||||
|
var uri = '';
|
||||||
|
var prefix = '';
|
||||||
|
var idx = identifier.indexOf(':');
|
||||||
|
//Does the identifier has a prefix?
|
||||||
|
if(idx !== -1){
|
||||||
|
prefix = identifier.substring(0, idx);
|
||||||
|
uri = sctx.getNamespaceByPrefix(prefix).uri;
|
||||||
|
}
|
||||||
|
var decls = sctx.getVariables();
|
||||||
|
var names = [];
|
||||||
|
Object.keys(decls).forEach(function(key){
|
||||||
|
var i = key.indexOf('#');
|
||||||
|
var ns = key.substring(0, i);
|
||||||
|
var name = key.substring(i+1);
|
||||||
|
if(ns !== ''){
|
||||||
|
names.push(sctx.getPrefixByNamespace(ns) + ':' + name);
|
||||||
|
} else {
|
||||||
|
names.push(name);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var matches = findCompletions(identifier, names);
|
||||||
|
var match = function(name) {
|
||||||
|
return {
|
||||||
|
name: '$' + name,
|
||||||
|
score: 4,
|
||||||
|
value: '$' + name
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return matches.map(match);
|
||||||
|
};
|
||||||
|
|
||||||
|
var completeExpr = function(line, pos, sctx){
|
||||||
|
console.log('line');
|
||||||
|
console.log(line);
|
||||||
|
console.log('=');
|
||||||
|
var identifier = retrievePrecedingIdentifier(line, pos.col, nameCharRegExp);
|
||||||
|
var before = line.substring(0, pos.col - (identifier.length === 0 ? 0 : identifier.length));
|
||||||
|
var isVar = before[before.length - 1] === '$';
|
||||||
|
if(isVar) {
|
||||||
|
return completeVariable(identifier, pos, sctx);
|
||||||
|
} else if(identifier !== '') {
|
||||||
|
return completeFunction(identifier, pos, sctx).concat(completePrefix(identifier, pos, sctx));
|
||||||
|
} else {
|
||||||
|
return completeVariable(identifier, pos, sctx).concat(completeFunction(identifier, pos, sctx)).concat(completePrefix(identifier, pos, sctx));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var completeModuleUri = function(line, pos, sctx){
|
||||||
|
var identifier = retrievePrecedingIdentifier(line, pos.col, uriRegex);
|
||||||
|
var matches = findCompletions(identifier, sctx.getAvailableModuleNamespaces());
|
||||||
|
var match = function(name) {
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
score: 4,
|
||||||
|
value: name
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return matches.map(match);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.complete = function(source, ast, rootSctx, pos){
|
||||||
|
var line = source.split('\n')[pos.line];
|
||||||
|
var node = TreeOps.findNode(ast, pos);
|
||||||
|
var sctx = TreeOps.findNode(rootSctx, pos);
|
||||||
|
sctx = sctx ? sctx : rootSctx;
|
||||||
|
if(node && node.name === 'URILiteral' && node.getParent && node.getParent.name === 'ModuleImport'){
|
||||||
|
return completeModuleUri(line, pos, sctx);
|
||||||
|
} else {
|
||||||
|
return completeExpr(line, pos, sctx);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},{"../tree_ops":10}],6:[function(_dereq_,module,exports){
|
||||||
exports.StyleChecker = function (ast, source) {
|
exports.StyleChecker = function (ast, source) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
@ -1081,7 +1312,7 @@ exports.StyleChecker = function (ast, source) {
|
||||||
});
|
});
|
||||||
this.visit(ast);
|
this.visit(ast);
|
||||||
};
|
};
|
||||||
},{}],6:[function(_dereq_,module,exports){
|
},{}],7:[function(_dereq_,module,exports){
|
||||||
//TODO: don't copy string
|
//TODO: don't copy string
|
||||||
exports.JSONParseTreeHandler = function (code) {
|
exports.JSONParseTreeHandler = function (code) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
@ -1246,7 +1477,7 @@ exports.JSONParseTreeHandler = function (code) {
|
||||||
ptr.pos.ec = ec;
|
ptr.pos.ec = ec;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},{}],7:[function(_dereq_,module,exports){
|
},{}],8:[function(_dereq_,module,exports){
|
||||||
// This file was generated on Mon Mar 24, 2014 11:18 (UTC+01) by REx v5.30 which is Copyright (c) 1979-2014 by Gunther Rademacher <grd@gmx.net>
|
// This file was generated on Mon Mar 24, 2014 11:18 (UTC+01) by REx v5.30 which is Copyright (c) 1979-2014 by Gunther Rademacher <grd@gmx.net>
|
||||||
// REx command line: JSONiqParser.ebnf -ll 2 -backtrack -tree -javascript -a xqlint
|
// REx command line: JSONiqParser.ebnf -ll 2 -backtrack -tree -javascript -a xqlint
|
||||||
|
|
||||||
|
|
@ -43647,7 +43878,7 @@ JSONiqParser.TOKEN =
|
||||||
|
|
||||||
// End
|
// End
|
||||||
|
|
||||||
},{}],8:[function(_dereq_,module,exports){
|
},{}],9:[function(_dereq_,module,exports){
|
||||||
// This file was generated on Mon Mar 24, 2014 11:18 (UTC+01) by REx v5.30 which is Copyright (c) 1979-2014 by Gunther Rademacher <grd@gmx.net>
|
// This file was generated on Mon Mar 24, 2014 11:18 (UTC+01) by REx v5.30 which is Copyright (c) 1979-2014 by Gunther Rademacher <grd@gmx.net>
|
||||||
// REx command line: XQueryParser.ebnf -ll 2 -backtrack -tree -javascript -a xqlint
|
// REx command line: XQueryParser.ebnf -ll 2 -backtrack -tree -javascript -a xqlint
|
||||||
|
|
||||||
|
|
@ -78297,7 +78528,7 @@ XQueryParser.TOKEN =
|
||||||
|
|
||||||
// End
|
// End
|
||||||
|
|
||||||
},{}],9:[function(_dereq_,module,exports){
|
},{}],10:[function(_dereq_,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.TreeOps = {
|
exports.TreeOps = {
|
||||||
|
|
@ -78336,17 +78567,69 @@ exports.TreeOps = {
|
||||||
var child = ast.children[i];
|
var child = ast.children[i];
|
||||||
this.removeParentPtr(child);
|
this.removeParentPtr(child);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
inRange: function(p, pos, exclusive){
|
||||||
|
if(p && p.sl <= pos.line && pos.line <= p.el) {
|
||||||
|
if(p.sl < pos.line && pos.line < p.el) {
|
||||||
|
return true;
|
||||||
|
} else if(p.sl === pos.line && pos.line < p.el) {
|
||||||
|
return p.sc <= pos.col;
|
||||||
|
} else if(p.sl === pos.line && p.el === pos.line) {
|
||||||
|
return p.sc <= pos.col && pos.col <= p.ec + (exclusive ? 1 : 0);
|
||||||
|
} else if(p.sl < pos.line && p.el === pos.line) {
|
||||||
|
return pos.col <= p.ec + (exclusive ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
findNode: function(ast, pos) {
|
||||||
|
if(!ast) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var p = ast.pos;
|
||||||
|
if(this.inRange(p, pos) === true) {
|
||||||
|
for(var i in ast.children) {
|
||||||
|
var child = ast.children[i];
|
||||||
|
var n = this.findNode(child, pos);
|
||||||
|
if(n !== undefined) {
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ast;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
astAsXML: function(node, indent){
|
||||||
|
var result = '';
|
||||||
|
indent = indent ? indent : '';
|
||||||
|
if(node.value) {
|
||||||
|
result += (indent + '<' + node.name + '>' + node.value + '</' + node.name + '>\n');
|
||||||
|
}
|
||||||
|
result += indent + '<' + node.name + '>\n';
|
||||||
|
var that = this;
|
||||||
|
node.children.forEach(function(child){
|
||||||
|
result += that.astAsXML(child, indent + ' ');
|
||||||
|
});
|
||||||
|
result += indent + '</' + node.name + '>\n';
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},{}],10:[function(_dereq_,module,exports){
|
},{}],11:[function(_dereq_,module,exports){
|
||||||
exports.XQLint = function (file, source, sctx, opts) {
|
exports.XQLint = function (source, opts) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
opts = opts ? opts : {};
|
||||||
|
|
||||||
var JSONiqParser = _dereq_('./parsers/JSONiqParser').JSONiqParser;
|
var JSONiqParser = _dereq_('./parsers/JSONiqParser').JSONiqParser;
|
||||||
var XQueryParser = _dereq_('./parsers/XQueryParser').XQueryParser;
|
var XQueryParser = _dereq_('./parsers/XQueryParser').XQueryParser;
|
||||||
var JSONParseTreeHandler = _dereq_('./parsers/JSONParseTreeHandler').JSONParseTreeHandler;
|
var JSONParseTreeHandler = _dereq_('./parsers/JSONParseTreeHandler').JSONParseTreeHandler;
|
||||||
var Translator = _dereq_('./compiler/translator').Translator;
|
var Translator = _dereq_('./compiler/translator').Translator;
|
||||||
var StyleChecker = _dereq_('./formatter/style_checker').StyleChecker;
|
var StyleChecker = _dereq_('./formatter/style_checker').StyleChecker;
|
||||||
|
var StaticContext = _dereq_('./compiler/static_context').StaticContext;
|
||||||
|
var completer = _dereq_('../lib/completion/completer');
|
||||||
|
|
||||||
var defaults = function(current, def){
|
var defaults = function(current, def){
|
||||||
if(!current) {
|
if(!current) {
|
||||||
|
|
@ -78392,6 +78675,10 @@ exports.XQLint = function (file, source, sctx, opts) {
|
||||||
return warnings;
|
return warnings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getCompletions = function(pos){
|
||||||
|
return completer.complete(source, ast, sctx, pos);
|
||||||
|
};
|
||||||
|
|
||||||
var syntaxError = false;
|
var syntaxError = false;
|
||||||
this.hasSyntaxError = function () {
|
this.hasSyntaxError = function () {
|
||||||
return syntaxError;
|
return syntaxError;
|
||||||
|
|
@ -78413,17 +78700,13 @@ exports.XQLint = function (file, source, sctx, opts) {
|
||||||
return pos;
|
return pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var sctx = opts.staticContext ? opts.staticContext : new StaticContext();
|
||||||
|
var file = opts.fileName ? opts.fileName : '';
|
||||||
var isJSONiq = ((file.substring(file.length - '.jq'.length).indexOf('.jq') !== -1) && source.indexOf('xquery version') !== 0) || source.indexOf('jsoniq version') === 0;
|
var isJSONiq = ((file.substring(file.length - '.jq'.length).indexOf('.jq') !== -1) && source.indexOf('xquery version') !== 0) || source.indexOf('jsoniq version') === 0;
|
||||||
var h = new JSONParseTreeHandler(source);
|
var h = new JSONParseTreeHandler(source);
|
||||||
var parser = isJSONiq ? new JSONiqParser(source, h) : new XQueryParser(source, h);
|
var parser = isJSONiq ? new JSONiqParser(source, h) : new XQueryParser(source, h);
|
||||||
try {
|
try {
|
||||||
parser.parse_XQuery();
|
parser.parse_XQuery();
|
||||||
ast = h.getParseTree();
|
|
||||||
if(opts.styleCheck) {
|
|
||||||
markers = markers.concat(new StyleChecker(ast, source).getMarkers());
|
|
||||||
}
|
|
||||||
var translator = new Translator(sctx, ast);
|
|
||||||
markers = markers.concat(translator.getMarkers());
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof parser.ParseException) {
|
if (e instanceof parser.ParseException) {
|
||||||
syntaxError = true;
|
syntaxError = true;
|
||||||
|
|
@ -78439,13 +78722,18 @@ exports.XQLint = function (file, source, sctx, opts) {
|
||||||
level: 'error',
|
level: 'error',
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
//ast = h.getParseTree();
|
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast = h.getParseTree();
|
||||||
|
if(opts.styleCheck) {
|
||||||
|
markers = markers.concat(new StyleChecker(ast, source).getMarkers());
|
||||||
|
}
|
||||||
|
var translator = new Translator(sctx, ast);
|
||||||
|
markers = markers.concat(translator.getMarkers());
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"./compiler/translator":4,"./formatter/style_checker":5,"./parsers/JSONParseTreeHandler":6,"./parsers/JSONiqParser":7,"./parsers/XQueryParser":8}]},{},[10])
|
},{"../lib/completion/completer":5,"./compiler/static_context":3,"./compiler/translator":4,"./formatter/style_checker":6,"./parsers/JSONParseTreeHandler":7,"./parsers/JSONiqParser":8,"./parsers/XQueryParser":9}]},{},[11])
|
||||||
(10)
|
(11)
|
||||||
});
|
});
|
||||||
|
|
@ -38,6 +38,13 @@ var XQLint = require("./xquery/xqlint").XQLint;
|
||||||
var XQueryWorker = exports.XQueryWorker = function(sender) {
|
var XQueryWorker = exports.XQueryWorker = function(sender) {
|
||||||
Mirror.call(this, sender);
|
Mirror.call(this, sender);
|
||||||
this.setTimeout(200);
|
this.setTimeout(200);
|
||||||
|
var that = this;
|
||||||
|
this.sender.on("complete", function(e){
|
||||||
|
that.sender.emit("markers", that.xqlint.getMarkers());
|
||||||
|
var pos = { line: e.data.pos.row, col: e.data.pos.column };
|
||||||
|
var proposals = that.xqlint.getCompletions(pos);
|
||||||
|
that.sender.emit("complete", proposals);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(XQueryWorker, Mirror);
|
oop.inherits(XQueryWorker, Mirror);
|
||||||
|
|
@ -47,8 +54,8 @@ 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 xqlint = new XQLint('test', value);
|
this.xqlint = new XQLint(value);
|
||||||
this.sender.emit("markers", xqlint.getMarkers());
|
this.sender.emit("markers", this.xqlint.getMarkers());
|
||||||
};
|
};
|
||||||
}).call(XQueryWorker.prototype);
|
}).call(XQueryWorker.prototype);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue