UNPKG

ace-code-editor

Version:

Ajax.org Code Editor is a full featured source code highlighting editor that powers the Cloud9 IDE

1,269 lines (1,156 loc) 6.53 MB
define(function(require, exports, module) { module.exports = (function outer (modules, cache, entry) { var previousRequire = typeof require == "function" && require; function newRequire(name, jumped){ if(!cache[name]) { if(!modules[name]) { var currentRequire = typeof require == "function" && require; if (!jumped && currentRequire) return currentRequire(name, true); if (previousRequire) return previousRequire(name, true); var err = new Error('Cannot find module \'' + name + '\''); err.code = 'MODULE_NOT_FOUND'; throw err; } var m = cache[name] = {exports:{}}; modules[name][0].call(m.exports, function(x){ var id = modules[name][1][x]; return newRequire(id ? id : x); },m,m.exports,outer,modules,cache,entry); } return cache[name].exports; } for(var i=0;i<entry.length;i++) newRequire(entry[i]); return newRequire(entry[0]); }) ({"/node_modules/xqlint/lib/compiler/errors.js":[function(_dereq_,module,exports){ 'use strict'; var init = function(that, code, message, pos, type){ if(!code) { throw new Error(type + ' code is missing.'); } if(!message) { throw new Error(type + ' message is missing.'); } if(!pos) { throw new Error(type + ' position is missing.'); } that.getCode = function(){ return code; }; that.getMessage = function(){ return message; }; that.getPos = function(){ return pos; }; }; var StaticError = {}; var StaticWarning = {}; StaticError.prototype = new Error(); StaticWarning.prototype = new Error(); exports.StaticError = StaticError.prototype.constructor = function(code, message, pos) { init(this, code, message, pos, 'Error'); }; exports.StaticWarning = StaticWarning.prototype.constructor = function(code, message, pos) { init(this, code, message, pos, 'Warning'); }; },{}],"/node_modules/xqlint/lib/compiler/handlers.js":[function(_dereq_,module,exports){ 'use strict'; var TreeOps = _dereq_('../tree_ops').TreeOps; var Errors = _dereq_('./errors'); var StaticWarning = Errors.StaticWarning; // // Prolog Handlers // exports.ModuleDecl = function(translator, rootSctx, node){ var prefix = ''; return { NCName: function(ncname){ prefix = TreeOps.flatten(ncname); }, URILiteral: function(uri) { uri = TreeOps.flatten(uri); uri = uri.substring(1, uri.length - 1); translator.apply(function(){ rootSctx.moduleNamespace = uri; rootSctx.addNamespace(uri, prefix, node.pos, 'moduleDecl'); }); } }; }; exports.ModuleImport = function(translator, rootSctx, node) { var prefix = ''; var moduleURI; //location hints return { NCName: function(ncname){ prefix = TreeOps.flatten(ncname); }, URILiteral: function(uri) { if(moduleURI !== undefined) { //location hints return; } uri = TreeOps.flatten(uri); uri = uri.substring(1, uri.length - 1); moduleURI = uri; translator.apply(function(){ rootSctx.importModule(uri, prefix, node.pos); }); } }; }; exports.SchemaImport = function(translator, rootSctx, node) { var prefix = ''; var schemaURI; return { SchemaPrefix: function(schemaPrefix) { var SchemaPrefixHandler = function () { this.NCName = function (ncname) { prefix = TreeOps.flatten(ncname); }; }; translator.visitChildren(schemaPrefix, new SchemaPrefixHandler()); }, URILiteral: function(uri) { if(schemaURI !== undefined) { //location hints return; } uri = TreeOps.flatten(uri); uri = uri.substring(1, uri.length - 1); schemaURI = uri; translator.apply(function(){ rootSctx.addNamespace(uri, prefix, node.pos, 'schema'); }); } }; }; exports.DefaultNamespaceDecl = function(translator, rootSctx, node) { var fn = false; var ns = ''; return { TOKEN: function(token){ fn = fn ? true : (token.value === 'function'); }, URILiteral: function(uri){ ns = TreeOps.flatten(uri); ns = ns.substring(1, ns.length - 1); if(!fn) { translator.apply(function(){ throw new StaticWarning('W06', 'Avoid default element namespace declarations.', node.pos); }); rootSctx.defaultElementNamespace = ns; } else { rootSctx.defaultFunctionNamespace = ns; } } }; }; exports.NamespaceDecl = function(translator, rootSctx, node) { var prefix = ''; return { NCName: function(ncname) { prefix = TreeOps.flatten(ncname); }, URILiteral: function(uri) { uri = TreeOps.flatten(uri); uri = uri.substring(1, uri.length - 1); translator.apply(function(){ rootSctx.addNamespace(uri, prefix, node.pos, 'declare'); }); } }; }; // // // exports.VarHandler = function(translator, sctx, node){ var EQNameHandler = function(eqname){ var value = TreeOps.flatten(eqname); translator.apply(function(){ var qname = sctx.resolveQName(value, eqname.pos); sctx.addVariable(qname, node.name, eqname.pos); }); }; return { ExprSingle: function(){ return true; }, VarValue: function(){ return true; }, VarDefaultValue: function(){ return true; }, VarName: EQNameHandler, EQName: EQNameHandler }; }; exports.VarRefHandler = function(translator, sctx, node){ return { VarName: function(eqname){ var value = TreeOps.flatten(eqname); translator.apply(function(){ var qname = sctx.resolveQName(value, node.pos); if(qname.uri !== '') { sctx.root.namespaces[qname.uri].used = true; } sctx.addVarRef(qname, eqname.pos); }); } }; }; /* exports.FunctionCallHandler = function(translator, sctx, node, arity){ return { EQName: function(eqname){ var value = TreeOps.flatten(eqname); translator.apply(function(){ var qname = sctx.resolveQName(value, node.pos); if(qname.uri !== '') { sctx.root.namespaces[qname.uri].used = true; } sctx.addFunctionCall(qname, arity, eqname.pos); }); } }; }; */ },{"../tree_ops":"/node_modules/xqlint/lib/tree_ops.js","./errors":"/node_modules/xqlint/lib/compiler/errors.js"}],"/node_modules/xqlint/lib/compiler/schema_built-in_types.js":[function(_dereq_,module,exports){ 'use strict'; /** * http://www.w3.org/TR/xpath-functions/#constructor-functions-for-xsd-types */ exports.getSchemaBuiltinTypes = function(){ var ns = 'http://www.w3.org/2001/XMLSchema'; var SchemaBuiltinTypes = {}; SchemaBuiltinTypes[ns] = { variables: {}, functions: {} }; SchemaBuiltinTypes[ns].functions[ns + '#string#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'string', arity: 1, eqname: { uri: ns, name: 'string' } }; SchemaBuiltinTypes[ns].functions[ns + '#boolean#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'boolean', arity: 1, eqname: { uri: ns, name: 'boolean' } }; SchemaBuiltinTypes[ns].functions[ns + '#decimal#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'decimal', arity: 1, eqname: { uri: ns, name: 'decimal' } }; SchemaBuiltinTypes[ns].functions[ns + '#float#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'float', arity: 1, eqname: { uri: ns, name: 'float' } }; SchemaBuiltinTypes[ns].functions[ns + '#double#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'double', arity: 1, eqname: { uri: ns, name: 'double' } }; SchemaBuiltinTypes[ns].functions[ns + '#duration#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'duration', arity: 1, eqname: { uri: ns, name: 'duration' } }; SchemaBuiltinTypes[ns].functions[ns + '#dateTime#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'dateTime', arity: 1, eqname: { uri: ns, name: 'dateTime' } }; SchemaBuiltinTypes[ns].functions[ns + '#time#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'time', arity: 1, eqname: { uri: ns, name: 'time' } }; SchemaBuiltinTypes[ns].functions[ns + '#date#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'date', arity: 1, eqname: { uri: ns, name: 'date' } }; SchemaBuiltinTypes[ns].functions[ns + '#gYearMonth#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'gYearMonth', arity: 1, eqname: { uri: ns, name: 'gYearMonth' } }; SchemaBuiltinTypes[ns].functions[ns + '#gYear#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'gYear', arity: 1, eqname: { uri: ns, name: 'gYear' } }; SchemaBuiltinTypes[ns].functions[ns + '#gMonthDay#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'gMonthDay', arity: 1, eqname: { uri: ns, name: 'gMonthDay' } }; SchemaBuiltinTypes[ns].functions[ns + '#gDay#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'gDay', arity: 1, eqname: { uri: ns, name: 'gDay' } }; SchemaBuiltinTypes[ns].functions[ns + '#gMonth#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'gMonth', arity: 1, eqname: { uri: ns, name: 'gMonth' } }; SchemaBuiltinTypes[ns].functions[ns + '#hexBinary#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'hexBinary', arity: 1, eqname: { uri: ns, name: 'hexBinary' } }; SchemaBuiltinTypes[ns].functions[ns + '#base64Binary#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'base64Binary', arity: 1, eqname: { uri: ns, name: 'base64Binary' } }; SchemaBuiltinTypes[ns].functions[ns + '#anyURI#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'anyURI', arity: 1, eqname: { uri: ns, name: 'anyURI' } }; SchemaBuiltinTypes[ns].functions[ns + '#QName#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'QName', arity: 1, eqname: { uri: ns, name: 'QName' } }; SchemaBuiltinTypes[ns].functions[ns + '#normalizedString#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'normalizedString', arity: 1, eqname: { uri: ns, name: 'normalizedString' } }; SchemaBuiltinTypes[ns].functions[ns + '#token#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'token', arity: 1, eqname: { uri: ns, name: 'token' } }; SchemaBuiltinTypes[ns].functions[ns + '#language#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'language', arity: 1, eqname: { uri: ns, name: 'language' } }; SchemaBuiltinTypes[ns].functions[ns + '#NMTOKEN#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'NMTOKEN', arity: 1, eqname: { uri: ns, name: 'NMTOKEN' } }; SchemaBuiltinTypes[ns].functions[ns + '#Name#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'Name', arity: 1, eqname: { uri: ns, name: 'Name' } }; SchemaBuiltinTypes[ns].functions[ns + '#NCName#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'NCName', arity: 1, eqname: { uri: ns, name: 'NCName' } }; SchemaBuiltinTypes[ns].functions[ns + '#ID#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'ID', arity: 1, eqname: { uri: ns, name: 'ID' } }; SchemaBuiltinTypes[ns].functions[ns + '#IDREF#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'IDREF', arity: 1, eqname: { uri: ns, name: 'IDREF' } }; SchemaBuiltinTypes[ns].functions[ns + '#ENTITY#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'ENTITY', arity: 1, eqname: { uri: ns, name: 'ENTITY' } }; SchemaBuiltinTypes[ns].functions[ns + '#integer#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'integer', arity: 1, eqname: { uri: ns, name: 'integer' } }; SchemaBuiltinTypes[ns].functions[ns + '#nonPositiveInteger#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'nonPositiveInteger', arity: 1, eqname: { uri: ns, name: 'nonPositiveInteger' } }; SchemaBuiltinTypes[ns].functions[ns + '#negativeInteger#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'negativeInteger', arity: 1, eqname: { uri: ns, name: 'negativeInteger' } }; SchemaBuiltinTypes[ns].functions[ns + '#long#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'long', arity: 1, eqname: { uri: ns, name: 'long' } }; SchemaBuiltinTypes[ns].functions[ns + '#int#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'int', arity: 1, eqname: { uri: ns, name: 'int' } }; SchemaBuiltinTypes[ns].functions[ns + '#short#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'short', arity: 1, eqname: { uri: ns, name: 'short' } }; SchemaBuiltinTypes[ns].functions[ns + '#byte#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'byte', arity: 1, eqname: { uri: ns, name: 'byte' } }; SchemaBuiltinTypes[ns].functions[ns + '#nonNegativeInteger#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'nonNegativeInteger', arity: 1, eqname: { uri: ns, name: 'nonNegativeInteger' } }; SchemaBuiltinTypes[ns].functions[ns + '#unsignedLong#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'unsignedLong', arity: 1, eqname: { uri: ns, name: 'unsignedLong' } }; SchemaBuiltinTypes[ns].functions[ns + '#unsignedInt#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'unsignedInt', arity: 1, eqname: { uri: ns, name: 'unsignedInt' } }; SchemaBuiltinTypes[ns].functions[ns + '#unsignedShort#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'unsignedShort', arity: 1, eqname: { uri: ns, name: 'unsignedShort' } }; SchemaBuiltinTypes[ns].functions[ns + '#unsignedByte#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'unsignedByte', arity: 1, eqname: { uri: ns, name: 'unsignedByte' } }; SchemaBuiltinTypes[ns].functions[ns + '#positiveInteger#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'positiveInteger', arity: 1, eqname: { uri: ns, name: 'positiveInteger' } }; SchemaBuiltinTypes[ns].functions[ns + '#yearMonthDuration#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'yearMonthDuration', arity: 1, eqname: { uri: ns, name: 'yearMonthDuration' } }; SchemaBuiltinTypes[ns].functions[ns + '#dayTimeDuration#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'dayTimeDuration', arity: 1, eqname: { uri: ns, name: 'dayTimeDuration' } }; SchemaBuiltinTypes[ns].functions[ns + '#untypedAtomic#1'] = { params: ['$arg as xs:anyAtomicType?'], annotations: [], name: 'untypedAtomic', arity: 1, eqname: { uri: ns, name: 'untypedAtomic' } }; return SchemaBuiltinTypes; }; },{}],"/node_modules/xqlint/lib/compiler/static_context.js":[function(_dereq_,module,exports){ exports.StaticContext = function (parent, pos) { 'use strict'; var TreeOps = _dereq_('../tree_ops').TreeOps; var Errors = _dereq_('./errors'); var StaticError = Errors.StaticError; var StaticWarning = Errors.StaticWarning; var getSchemaBuiltinTypes = _dereq_('./schema_built-in_types').getSchemaBuiltinTypes; var emptyPos = { sl:0, sc: 0, el: 0, ec: 0 }; var namespaces = {}; var getVarKey = function(qname) { return qname.uri + '#' + qname.name; }; var getFnKey = function(qname, arity) { return getVarKey(qname) + '#' + arity; }; if(!parent) { namespaces['http://jsoniq.org/functions'] = { prefixes: ['jn'], pos: emptyPos, type: 'module', override: true }; namespaces['http://www.28msec.com/modules/collections'] = { prefixes: ['db'], pos: emptyPos, type: 'module', override: true }; namespaces['http://www.28msec.com/modules/store'] = { prefixes: ['store'], pos: emptyPos, type: 'module', override: true }; namespaces['http://jsoniq.org/function-library'] = { prefixes: ['libjn'], pos: emptyPos, type: 'module', override: true }; //namespaces['http://www.28msec.com/modules/mongodb/types'] = { // prefix: 'ms', // pos: emptyPos, // type: 'module', // override: true //}; namespaces['http://www.w3.org/2005/xpath-functions'] = { prefixes: ['fn'], pos: emptyPos, type: 'module', override: true }; namespaces['http://www.w3.org/2005/xquery-local-functions'] = { prefixes: ['local'], pos: emptyPos, type: 'declare', override: true }; namespaces['http://www.w3.org/2001/XMLSchema-instance'] = { prefixes: ['xsi'], pos: emptyPos, type: 'declare' }; namespaces['http://www.w3.org/2001/XMLSchema'] = { prefixes: ['xs'], pos: emptyPos, type: 'declare' }; namespaces['http://www.w3.org/XML/1998/namespace'] = { prefixes: ['xml'], pos: emptyPos, type: 'declare' }; namespaces['http://zorba.io/annotations'] = { prefixes: ['an'], pos: emptyPos, type: 'declare', override: true }; namespaces['http://www.28msec.com/annotations/rest'] = { prefixes: ['rest'], pos: emptyPos, type: 'declare', override: true }; namespaces['http://www.w3.org/2005/xqt-errors'] = { prefixes: ['err'], pos: emptyPos, type: 'declare', override: true }; namespaces['http://zorba.io/errors'] = { prefixes: ['zerr'], pos: emptyPos, type: 'declare', override: true }; } var s = { parent: parent, children: [], pos: pos, setModuleResolver: function(resolver){ this.root.moduleResolver = resolver; return this; }, setModules: function(index){ if(this !== this.root){ throw new Error('setModules() not invoked from the root static context.'); } this.moduleResolver = function(uri){ return index[uri]; }; var that = this; Object.keys(this.namespaces).forEach(function(uri){ var ns = that.namespaces[uri]; if(ns.type === 'module') { var mod = that.moduleResolver(uri); if(mod.variables) { TreeOps.concat(that.variables, mod.variables); } if(mod.functions) { TreeOps.concat(that.functions, mod.functions); } } }); return this; }, setModulesFromXQDoc: function(xqdoc){ if(this !== this.root){ throw new Error('setModulesFromXQDoc() not invoked from the root static context.'); } //We throw away all the unecessary xqdoc information var index = {}; Object.keys(xqdoc).forEach(function(uri) { var mod = xqdoc[uri]; var variables = {}; var functions = {}; mod.functions.forEach(function(fn){ functions[uri + '#' + fn.name + '#' + fn.arity] = { params: [], annotations: [], name: fn.name, arity: fn.arity, eqname: { uri: uri, name: fn.name } }; fn.parameters.forEach(function(param){ functions[uri + '#' + fn.name + '#' + fn.arity].params.push('$' + param.name); }); }); mod.variables.forEach(function(variable){ var name = variable.name.substring(variable.name.indexOf(':') + 1); variables[uri + '#' + name] = { type: 'VarDecl', annotations: [], eqname: { uri: uri, name: name } }; }); index[uri] = { variables: variables, functions: functions }; }); this.root.moduleResolver = function(uri){ return index[uri]; }; var that = this; Object.keys(this.namespaces).forEach(function(uri){ var ns = that.namespaces[uri]; if(ns.type === 'module') { var mod = that.moduleResolver(uri); if(mod.variables) { TreeOps.concat(that.variables, mod.variables); } if(mod.functions) { TreeOps.concat(that.functions, mod.functions); } } }); return this; }, moduleNamespace: '', description: '', defaultFunctionNamespace: 'http://www.w3.org/2005/xpath-functions', defaultFunctionNamespaces: [ 'http://www.28msec.com/modules/collections', 'http://www.28msec.com/modules/store', 'http://jsoniq.org/functions', 'http://jsoniq.org/function-library', 'http://www.w3.org/2001/XMLSchema' //Built-in type constructors ], defaultElementNamespace: '', namespaces: namespaces, availableModuleNamespaces: [], importModule: function(uri, prefix, pos) { if(this !== this.root){ throw new Error('Function not invoked from the root static context.'); } this.addNamespace(uri, prefix, pos, 'module'); if(this.moduleResolver) { try { var mod = this.moduleResolver(uri, []); if(mod.variables) { TreeOps.concat(this.variables, mod.variables); } if(mod.functions) { TreeOps.concat(this.functions, mod.functions); } } catch(e) { throw new StaticError('XQST0059', 'module "' + uri + '" not found', pos); } } return this; }, getAvailableModuleNamespaces: function(){ return this.root.availableModuleNamespaces; }, getPrefixesByNamespace: function(uri){ return this.root.namespaces[uri].prefixes; }, addNamespace: function (uri, prefix, pos, type) { if(prefix === '' && type === 'module') { throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos); } //Check for empty target namespace if (uri === '') { throw new StaticError('XQST0088', 'empty target namespace in module import or module declaration', pos); } //Check for duplicate target namespace var namespace = this.getNamespace(uri); if (namespace && namespace.type === type && type !== 'declare' && !namespace.override) { throw new StaticError('XQST0047', '"' + uri + '": duplicate target namespace', pos); } //Check for duplicate prefix namespace = this.getNamespaceByPrefix(prefix); if (namespace && !namespace.override) { throw new StaticError('XQST0033', '"' + prefix + '": namespace prefix already bound to "' + namespace.uri + '"', pos); } namespace = this.namespaces[uri]; var prefixes = [prefix]; if(namespace) { prefixes = prefixes.concat(this.namespaces[uri].prefixes); } this.namespaces[uri] = { prefixes: prefixes, pos: pos, type: type }; if (namespace) { throw new StaticWarning('W02', '"' + uri + '" already bound to the "' + namespace.prefixes.join(', ') + '" prefix', pos); } }, getNamespaces: function(){ return this.root.namespaces; }, getNamespace: function (uri) { var that = this; while (that) { var namespace = that.namespaces[uri]; if (namespace) { return namespace; } that = that.parent; } }, getNamespaceByPrefix: function (prefix) { var found = []; var handler = function (uri) { var namespace = that.namespaces[uri]; if (namespace.prefixes.indexOf(prefix) !== -1) { namespace.uri = uri; found.push(namespace); } }; var that = this; while (that) { Object.keys(that.namespaces).forEach(handler); that = that.parent; } var result; found.forEach(function(ns){ if(ns.type === 'moduleDecl') { result = ns; } }); if(result) { return result; } else { return found[0]; } }, resolveQName: function(value, pos){ var qname = { uri: '', prefix: '', name: '' }; var idx; if (value.substring(0, 2) === 'Q{') { idx = value.indexOf('}'); qname.uri = value.substring(2, idx); qname.name = value.substring(idx + 1); } else { idx = value.indexOf(':'); qname.prefix = value.substring(0, idx); var namespace = this.getNamespaceByPrefix(qname.prefix); if(!namespace && qname.prefix !== '' && ['fn', 'jn'].indexOf(qname.prefix) === -1) { throw new StaticError('XPST0081', '"' + qname.prefix + '": can not expand prefix of lexical QName to namespace URI', pos); } if(namespace) { qname.uri = namespace.uri; } qname.name = value.substring(idx + 1); } return qname; }, variables: {}, varRefs: {}, functionCalls: {}, addVariable: function(qname, type, pos){ if( type === 'VarDecl' && this.moduleNamespace !== '' && !(this.moduleNamespace === qname.uri || qname.uri === '') ) { throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos); } var key = getVarKey(qname); if(type === 'VarDecl' && this.variables[key]) { throw new StaticError('XQST0049', '"' + qname.name + '": duplicate variable declaration', pos); } this.variables[key] = { type: type, pos: pos, qname: qname, annotations: {} }; 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) { var key = getVarKey(qname); var that = this; while(that) { if(that.variables[key]) { return that.variables[key]; } that = that.parent; } }, addVarRef: function(qname, pos){ var varDecl = this.getVariable(qname); //If no moduleResolver is available, then only resolve 'local' variables if(!varDecl && (qname.uri === '' || this.root.moduleResolver)) { throw new StaticError('XPST0008', '"' + qname.name + '": undeclared variable', pos); } var key = getVarKey(qname); this.varRefs[key] = true; }, addFunctionCall: function(qname, arity, pos){ var fn = this.getFunction(qname, arity); if(!fn && (qname.uri === 'http://www.w3.org/2005/xquery-local-functions' || this.root.moduleResolver)){ //Is it concat? (variadic) if((qname.uri === 'http://www.w3.org/2005/xpath-functions' || (qname.uri === '' && this.root.defaultFunctionNamespaces.concat(this.root.defaultFunctionNamespace).indexOf('http://www.w3.org/2005/xpath-functions') !== -1)) && qname.name === 'concat') { //do nothing } else if(!fn){ throw new StaticError('XPST0008', '"' + qname.name + '#' + arity + '": undeclared function', pos); } } var key = getFnKey(qname, arity); this.functionCalls[key] = true; }, functions: getSchemaBuiltinTypes()['http://www.w3.org/2001/XMLSchema'].functions, //functions: {}, getFunctions: function(){ return this.root.functions; }, getFunction: function(qname, arity){ var key = getFnKey(qname, arity); var fn; if(qname.uri === '') { var that = this; this.root.defaultFunctionNamespaces.concat([this.root.defaultFunctionNamespace]).forEach(function(defaultFunctionNamespace){ if(!fn){ fn = that.getFunction({ uri: defaultFunctionNamespace, prefix: qname.prefix, name: qname.name }, arity); } else { return false; } }); return fn; } else { return this.root.functions[key]; } }, addFunction: function(qname, pos, params) { if(this !== this.root){ throw new Error('addFunction() not invoked from the root static context.'); } 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); } var key = getFnKey(qname, arity); if(this.functions[key]) { throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos); } this.functions[key] = { pos: pos, params: params }; return this; } }; s.root = parent ? parent.root : s; return s; }; },{"../tree_ops":"/node_modules/xqlint/lib/tree_ops.js","./errors":"/node_modules/xqlint/lib/compiler/errors.js","./schema_built-in_types":"/node_modules/xqlint/lib/compiler/schema_built-in_types.js"}],"/node_modules/xqlint/lib/compiler/translator.js":[function(_dereq_,module,exports){ exports.Translator = function(rootStcx, ast){ 'use strict'; var Errors = _dereq_('./errors'); var StaticError = Errors.StaticError; var StaticWarning = Errors.StaticWarning; var TreeOps = _dereq_('../tree_ops').TreeOps; var StaticContext = _dereq_('./static_context').StaticContext; var Handlers = _dereq_('./handlers'); var get = function(node, path){ var result = []; if(path.length === 0){ return node; } node.children.forEach(function(child){ if(child.name === path[0] && path.length > 1) { result = get(child, path.slice(1)); } else if(child.name === path[0]) { result.push(child); } }); return result; }; var markers = []; this.apply = function(fn) { try { fn(); } catch(e) { if(e instanceof StaticError) { addStaticError(e); } else if(e instanceof StaticWarning) { addWarning(e.getCode(), e.getMessage(), e.getPos()); } else { throw e; } } }; var addStaticError = function(e){ markers.push({ pos: e.getPos(), type: 'error', level: 'error', message: '[' + e.getCode() + '] ' + e.getMessage() }); }; var addWarning = function(code, message, pos) { markers.push({ pos: pos, type: 'warning', level: 'warning', message: '[' + code + '] ' + message }); }; this.getMarkers = function(){ return markers; }; var translator = this; rootStcx.pos = ast.pos; var sctx = rootStcx; var pushSctx = function(pos){ sctx = new StaticContext(sctx, pos); sctx.parent.children.push(sctx); }; var popSctx = function(pos){ if (pos !== undefined) { sctx.pos.el = pos.el; sctx.pos.ec = pos.ec; } Object.keys(sctx.varRefs).forEach(function(key){ if(!sctx.variables[key]) { sctx.parent.varRefs[key] = true; } }); Object.keys(sctx.variables).forEach(function(key){ if(!sctx.varRefs[key] && sctx.variables[key].type !== 'GroupingVariable' && sctx.variables[key].type !== 'CatchVar') { addWarning('W03', 'Unused variable "$' + sctx.variables[key].qname.name + '"', sctx.variables[key].pos); } }); sctx = sctx.parent; }; this.visitOnly = function(node, names) { node.children.forEach(function(child){ if (names.indexOf(child.name) !== -1){ translator.visit(child); } }); }; this.getFirstChild = function(node, name) { var result; node.children.forEach(function(child){ if(child.name === name && result === undefined){ result = child; } }); return result; }; this.XQuery = function(node) { rootStcx.description = node.comment ? node.comment.description : undefined; }; this.ModuleDecl = function(node){ this.visitChildren(node, Handlers.ModuleDecl(translator, rootStcx, node)); return true; }; this.Prolog = function(node){ //Visit first part of the prolog this.visitOnly(node, ['DefaultNamespaceDecl', 'Setter', 'NamespaceDecl', 'Import']); //Get the Index of variable and function Declarations ast.index.forEach(function(node){ if(node.name === 'VarDecl') { node.children.forEach(function(child){ if(child.name === 'VarName') { translator.apply(function(){ var value = TreeOps.flatten(child); var qname = rootStcx.resolveQName(value, child.pos); rootStcx.addVariable(qname, node.name, child.pos); }); } }); } else if(node.name === 'FunctionDecl') { var qname, pos, params = []; node.children.forEach(function(child){ if(child.name === 'EQName') { qname = child; pos = child.pos; } else if(child.name === 'ParamList'){ child.children.forEach(function(c){ if(c.name === 'Param') { params.push(TreeOps.flatten(c)); } }); } }); translator.apply(function(){ qname = TreeOps.flatten(qname); qname = rootStcx.resolveQName(qname, pos); rootStcx.addFunction(qname, pos, params); }); } }); //Visit second part of the prolog this.visitOnly(node, ['ContextItemDecl', 'AnnotatedDecl', 'OptionDecl']); return true; }; this.ModuleImport = function (node) { this.visitChildren(node, Handlers.ModuleImport(translator, rootStcx, node)); return true; }; this.SchemaImport = function (node) { this.visitChildren(node, Handlers.SchemaImport(translator, rootStcx, node)); return true; }; this.DefaultNamespaceDecl = function(node){ this.visitChildren(node, Handlers.DefaultNamespaceDecl(translator, rootStcx, node)); return true; }; this.NamespaceDecl = function (node) { this.visitChildren(node, Handlers.NamespaceDecl(translator, rootStcx, node)); return true; }; var annotations = {}; this.AnnotatedDecl = function(node) { annotations = {}; this.visitChildren(node, Handlers.NamespaceDecl(translator, rootStcx, node)); return true; }; this.CompatibilityAnnotation = function(){ annotations['http://www.w3.org/2012/xquery#updating'] = []; return true; }; this.Annotation = function(node){ this.visitChildren(node, { EQName: function(eqname){ var value = TreeOps.flatten(eqname); translator.apply(function(){ var qname = sctx.resolveQName(value, eqname.pos); annotations[qname.uri + '#' + qname.name] = []; }); } }); return true; }; this.VarDecl = function(node){ //var typeDecl = get(node, ['TypeDeclaration']); //if(!typeDecl){ // addWarning('W05', 'Untyped module variable', node.pos); //} try { var varname = translator.getFirstChild(node, 'VarName'); var value = TreeOps.flatten(varname); var qname = sctx.resolveQName(value, varname.pos); var variable = rootStcx.getVariable(qname); if(variable) { variable.annotations = annotations; variable.description = node.getParent.comment ? node.getParent.comment.description : undefined; variable.type = TreeOps.flatten(get(node, ['TypeDeclaration'])[0]).substring(2).trim(); var last = variable.type.substring(variable.type.length - 1); if(last === '?') { variable.occurrence = 0; variable.type = variable.type.substring(0, variable.type.length - 1); } else if(last === '*') { variable.occurrence = -1; variable.type = variable.type.substring(0, variable.type.length - 1); } else if(last === '+') { variable.occurrence = 2; variable.type = variable.type.substring(0, variable.type.length - 1); } else { variable.occurrence = 1; } } } catch(e) { //ignore resolution exceptions } this.visitOnly(node, ['ExprSingle', 'VarValue', 'VarDefaultValue']); return true; }; this.FunctionDecl = function(node) { //var updateAn = get(node, ['CompatibilityAnnotation'])[0]; //console.log(updateAn); var isUpdating = annotations['http://www.w3.org/2012/xquery#updating'] !== undefined; var typeDecl = get(node, ['ReturnType'])[0]; var name = get(node, ['EQName'])[0]; if(!typeDecl && !isUpdating){ addWarning('W05', 'Untyped return value', name.pos); } /* this.visitChildren(node, { EQName: function(fnname){ var value = TreeOps.flatten(fnname); var qname = sctx.resolveQName(value, fnname.pos); var fn = rootStcx.getFunction(qname, arity); fn.annotations = annotations; return true; } }); */ var isExternal = false; node.children.forEach(function(child){ if(child.name === 'TOKEN' && child.value === 'external') { isExternal = true; return false; } }); if(!isExternal) { pushSctx(node.pos); this.visitChildren(node); popSctx(); } return true; }; this.VarRef = function(node) { this.visitChildren(node, Handlers.VarRefHandler(translator, sctx, node)); return true; }; this.Param = function(node){ var typeDecl = get(node, ['TypeDeclaration'])[0]; if(!typeDecl){ addWarning('W05', 'Untyped function parameter', node.pos); } this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.InlineFunctionExpr = function(node) { pushSctx(node.pos); this.visitChildren(node); popSctx(); return true; }; //Scripting var statementCount = []; var handleStatements = function(node) { pushSctx(node.pos); statementCount.push(0); translator.visitChildren(node); for (var i = 1; i <= statementCount[statementCount.length - 1]; i++) { popSctx(node.pos); } statementCount.pop(); popSctx(); }; this.StatementsAndOptionalExpr = function (node) { handleStatements(node); return true; }; this.StatementsAndExpr = function (node) { handleStatements(node); return true; }; this.BlockStatement = function (node) { handleStatements(node); return true; }; this.VarDeclStatement = function(node){ pushSctx(node.pos); statementCount[statementCount.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); //return true; }; //FLWOR Expressions var clauses = []; this.FLWORExpr = this.FLWORStatement = function (node) { pushSctx(node.pos); clauses.push(0); this.visitChildren(node); for(var i=1; i <= clauses[clauses.length - 1]; i++) { popSctx(node.pos); } clauses.pop(); popSctx(); return true; }; //this.ReturnClause = function(node){ //var expr = get(['ExprSingle', 'FLWORExpr']); // console.log(astAsXML(node)); //}; this.ForBinding = function (node) { this.visitOnly(node, ['ExprSingle', 'VarValue', 'VarDefaultValue']); pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.LetBinding = function(node){ this.visitOnly(node, ['ExprSingle', 'VarValue', 'VarDefaultValue']); pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.GroupingSpec = function(node){ var isVarDecl = false; node.children.forEach(function(child){ if(child.value === ':=') { isVarDecl = true; return false; } }); if(isVarDecl) { var groupingVariable = node.children[0]; this.visitOnly(node, ['ExprSingle', 'VarValue', 'VarDefaultValue']); pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(groupingVariable, Handlers.VarHandler(translator, sctx, groupingVariable)); return true; } else { } }; this.TumblingWindowClause = function (node) { this.visitOnly(node, ['ExprSingle']); pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); this.visitOnly(node, ['WindowStartCondition', 'WindowEndCondition']); return true; }; this.WindowVars = function (node) { pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.SlidingWindowClause = function (node) { this.visitOnly(node, ['ExprSingle', 'VarValue', 'VarDefaultValue']); pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); this.visitOnly(node, ['WindowStartCondition', 'WindowEndCondition']); return true; }; this.PositionalVar = function (node) { this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.PositionalVar = function (node) { this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.CurrentItem = function (node) { this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.PreviousItem = function (node) { this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.NextItem = function (node) { this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.CountClause = function (node) { pushSctx(node.pos); clauses[clauses.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; //SwitchExpr ::= 'switch' '(' Expr ')' SwitchCaseClause+ 'default' 'return' ExprSingle //SwitchCaseClause ::= ( 'case' SwitchCaseOperand )+ 'return' ExprSingle //SwitchCaseOperand ::= ExprSingle /* this.SwitchCaseClause = function(node){ pushSctx(node.pos); this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); this.visitOnly(node, ['ExprSingle']); popSctx(); return true; }; */ this.CaseClause = function(node) { pushSctx(node.pos); this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); this.visitOnly(node, ['ExprSingle']); popSctx(); return true; }; //TransformExpr ::= 'copy' TransformSpec ( ',' TransformSpec )* 'modify' ExprSingle 'return' ExprSingle //TransformSpec ::= '$' VarName ':=' ExprSingle var copies = []; this.TransformExpr = function (node) { pushSctx(node.pos); copies.push(0); this.visitChildren(node); for(var i=1; i <= copies[copies.length - 1]; i++) { popSctx(node.pos); } copies.pop(); popSctx(); return true; }; this.TransformSpec = function(node) { this.visitOnly(node, ['ExprSingle']); pushSctx(node.pos); copies[copies.length-1] += 1; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; //QuantifiedExpr ::= ( 'some' | 'every' ) QuantifiedVarDecl ( ',' QuantifiedVarDecl )* 'satisfies' ExprSingle //QuantifiedVarDecl ::= '$' VarName TypeDeclaration? 'in' ExprSingle var quantifiedDecls = []; this.QuantifiedExpr = function (node) { pushSctx(node.pos); quantifiedDecls.push(0); this.visitChildren(node); for(var i=1; i <= quantifiedDecls[quantifiedDecls.length - 1]; i++) { popSctx(node.pos); } quantifiedDecls.pop(); popSctx(); return true; }; this.QuantifiedVarDecl = function(node) { this.visitOnly(node, ['ExprSingle']); pushSctx(node.pos); quantifiedDecls[quantifiedDecls.length - 1]++; this.visitChildren(node, Handlers.VarHandler(translator, sctx, node)); return true; }; this.FunctionCall = function(node){ this.visitOnly(node, ['Argu