Skip to content

Commit

Permalink
Merge pull request #34 from Quodatum/dev
Browse files Browse the repository at this point in the history
[mod] use xq-catalogs
  • Loading branch information
apb2006 committed Aug 5, 2023
2 parents 09a2d60 + 40a524e commit 9f5f3fc
Show file tree
Hide file tree
Showing 161 changed files with 96 additions and 37,737 deletions.
5 changes: 2 additions & 3 deletions .jshintrc
@@ -1,7 +1,7 @@
{
"node": true,
"browser": false,
"esnext": true,
"esversion": 11,
"bitwise": false,
"camelcase": false,
"curly": true,
Expand All @@ -11,10 +11,9 @@
"latedef": true,
"newcap": false,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"unused": false,
"strict": true,
"trailing": true,
"smarttabs": true,
Expand Down
14 changes: 8 additions & 6 deletions Gruntfile.js
Expand Up @@ -29,12 +29,12 @@ module.exports = function (grunt) {
return new Promise(function (resolve, reject) {
var p = axios.post('https://www.bottlecaps.de/rex/', form, { headers });
p.then(function (response) {
fs.writeFileSync(parser.destination, response.data)
fs.writeFileSync(parser.destination, response.data);
resolve("saved: " + parser.destination);
})
.catch(function (error) {
reject(error);
})
});
});
}

Expand All @@ -45,7 +45,7 @@ module.exports = function (grunt) {
Promise.all(promises).then(function (r){
console.log("dONE",r);
});
console.log("SS")
console.log("SS");
});

grunt.registerMultiTask('index', 'Generate index xqdoc', function () {
Expand Down Expand Up @@ -96,10 +96,12 @@ module.exports = function (grunt) {
},
vows: {
all: {
//
options: {
verbose: false,
verbose: true,
colors: true,
coverage: 'json'
coverage: 'json',
reporter: 'dot-matrix',
},
// String or array of strings
// determining which files to include.
Expand All @@ -108,7 +110,7 @@ module.exports = function (grunt) {
},
one: {
options: {
verbose: false,
verbose: true,
colors: false,
coverage: 'json'
},
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/handlers.js
Expand Up @@ -39,7 +39,7 @@ exports.ModuleImport = function(translator, rootSctx, node,ats) {
URILiteral: function(node) {
let uri = TreeOps.flatten(node);
uri = uri.substring(1, uri.length - 1);
if(moduleURI !== undefined) {return }; //location hints
if(moduleURI !== undefined) {return; } //location hints
moduleURI = uri;
translator.apply(function(){
rootSctx.importModule(uri, prefix, node.pos,ats);
Expand Down
66 changes: 33 additions & 33 deletions lib/compiler/static_context.js
@@ -1,9 +1,15 @@
/*jshint esversion: 9 */
const processors = require('../processors');
"use strict";
const xqc = require('@quodatum/xq-catalogs');

// convert array to object
function keyed(arr) {
const obj = {};
arr.forEach(f => obj[f.key] = f);
return obj;
}

exports.StaticContext = function (parent, pos, processor) {
'use strict';
if(parent) processor=parent.processor;
if (parent) { processor = parent.processor; }
var TreeOps = require('../tree_ops').TreeOps;

var Errors = require('./errors');
Expand All @@ -12,7 +18,7 @@ exports.StaticContext = function (parent, pos, processor) {

var getSchemaBuiltinTypes = require('./schema_built-in_types').getSchemaBuiltinTypes;
//const library = require('./module-library.json');

var emptyPos = { sl: 0, sc: 0, el: 0, ec: 0 };
var namespaces = {
'http://www.w3.org/2005/xpath-functions': {
Expand Down Expand Up @@ -83,8 +89,8 @@ exports.StaticContext = function (parent, pos, processor) {
return getVarKey(qname) + '#' + arity;
};

if (!parent) namespaces= {...namespaces,...processors.namespaces(processor)};
if (!parent) { namespaces = { ...namespaces, ...xqc.library(processor) }; }


/* staticContext
parent:any
Expand Down Expand Up @@ -219,15 +225,15 @@ exports.StaticContext = function (parent, pos, processor) {
namespaces: namespaces,
availableModuleNamespaces: [],
locations: {}, // ns:{url:..,pos:..}
importModule: function (uri, prefix, pos,ats) {
importModule: function (uri, prefix, pos, ats) {
if (this !== this.root) {
throw new Error('Function not invoked from the root static context.');
}
if(ats.length>0){
if (ats.length > 0) {
//console.log("@",ats[0]);
}
this.addNamespace(uri, prefix, pos, 'module',ats);
// if(ats && ats.length>0 ) console.log("$$$"+ats[0]);
this.addNamespace(uri, prefix, pos, 'module', ats);
// if(ats && ats.length>0 ) console.log("$$$"+ats[0]);
if (this.moduleResolver) {
try {
var mod = this.moduleResolver(uri, ats);
Expand All @@ -249,7 +255,7 @@ exports.StaticContext = function (parent, pos, processor) {
},

getProcessors: function () {
return processors.names();
return xqc.names();
},

getAvailableModuleNamespaces: function () {
Expand All @@ -260,7 +266,7 @@ exports.StaticContext = function (parent, pos, processor) {
return this.root.namespaces[uri].prefixes;
},

addNamespace: function (uri, prefix, pos, type,ats) {
addNamespace: function (uri, prefix, pos, type, ats) {
if (prefix === '' && type === 'module') {
throw new StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);
}
Expand Down Expand Up @@ -291,7 +297,7 @@ exports.StaticContext = function (parent, pos, processor) {
pos: pos,
type: type
};
if(ats && ats.length) this.locations[uri]=ats;
if (ats && ats.length) { this.locations[uri] = ats; }
if (namespace && !namespace.override && !(namespace.uri = uri)) {
throw new StaticWarning('W02', '"' + uri + '" already bound to the "' + namespace.prefixes.join(', ') + '" prefix', pos);
}
Expand Down Expand Up @@ -364,7 +370,7 @@ exports.StaticContext = function (parent, pos, processor) {
if (namespace) {
qname.uri = namespace.uri;
} else if (value === 'updating') {
qname.uri = 'http://www.w3.org/2012/xquery' // apb hack for annotations
qname.uri = 'http://www.w3.org/2012/xquery'; // apb hack for annotations
}
qname.name = value.substring(idx + 1);
}
Expand Down Expand Up @@ -476,7 +482,7 @@ exports.StaticContext = function (parent, pos, processor) {
}
},

addFunction: function (qname, pos, params,ret) {
addFunction: function (qname, pos, params, ret) {
if (this !== this.root) {
throw new Error('addFunction() not invoked from the root static context.');
}
Expand All @@ -487,7 +493,7 @@ exports.StaticContext = function (parent, pos, processor) {
) {
throw new StaticError('XQST0048', '"' + qname.prefix + ':' + qname.name + '": Qname not library namespace', pos);
}
if(qname.uri==='' ) qname.uri=this.defaultFunctionNamespace;
if (qname.uri === '') { qname.uri = this.defaultFunctionNamespace; }
var key = getFnKey(qname, arity);
if (this.functions[key]) {
throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos);
Expand All @@ -498,8 +504,8 @@ exports.StaticContext = function (parent, pos, processor) {
pos: pos,
params: params
};
if(ret) {
this.functions[key].return=ret;
if (ret) {
this.functions[key].return = ret;
}
//console.log("AA",this.functions[key])
return this;
Expand All @@ -508,22 +514,16 @@ exports.StaticContext = function (parent, pos, processor) {
};
s.root = parent ? parent.root : s;
if (!parent) {
const importable = Object.keys(namespaces).filter(ns => namespaces[ns].type == 'module');
const importable = Object.keys(namespaces).filter(ns => namespaces[ns].type === 'module');
s.availableModuleNamespaces = importable;

importable.forEach(function(ns){
const xq=namespaces[ns];
s.functions={...s.functions,...xq.functions};
s.variables={...s.variables,...xq.variables};
})
importable.forEach(function (ns) {
const xq = namespaces[ns];
s.functions = { ...s.functions, ...xq.functions };
s.variables = { ...s.variables, ...xq.variables };
});

}
return s;
};
// convert array to object
function keyed(arr){
const obj={};
arr.forEach(f=>obj[f.key]=f);
return obj;
};


2 changes: 1 addition & 1 deletion lib/compiler/translator.js
Expand Up @@ -170,7 +170,7 @@ exports.Translator = function (rootStcx, ast) {
seenAt = 'at' === token.value;
},
URILiteral: function (node) {
if (!seenAt) { return };
if (!seenAt) { return ;}
var uri = TreeOps.flatten(node);
uri = uri.substring(1, uri.length - 1);
ats.push({ uri: uri, range: node.pos });
Expand Down
31 changes: 0 additions & 31 deletions lib/processors.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/tree_ops.js
Expand Up @@ -81,7 +81,7 @@ exports.TreeOps = {
endLineNumber = b.el;
endColumn = Math.max(b.ec, a.ec);
} else {
endLineNumber = a.el
endLineNumber = a.el;
endColumn = a.ec;
}

Expand Down
20 changes: 10 additions & 10 deletions lib/xqdoc/parse_comment.js
Expand Up @@ -18,12 +18,12 @@ exports.parseComment = function (comment) {

lines.forEach(function (line, index) {
line = line.trim();
if (line[0] === ':') line = line.substring(1).trim();
if (line[0] === ':') {line = line.substring(1).trim();}
if (line.length > 0) {
var reTag = new RegExp("^\\s*@(?<tag>\\w+)\\s+(?<rest>.+)$", "g");
var hits = reTag.exec(line);
var hasTag = hits !== null;
if (hasTag) tag = hits.groups.tag;
if (hasTag) {tag = hits.groups.tag;}

switch (tag) {
case "description":
Expand All @@ -32,10 +32,11 @@ exports.parseComment = function (comment) {
case "param":
if (hasTag) {
var reParam = new RegExp("^\\s*(?<param>[$]\\w+)\\s+(?<rest>.+)$", "g");
var phit = reParam.exec(hits.groups.rest)
if (phit !== null) ann.params[phit.groups.param] = phit.groups.rest;
var phit = reParam.exec(hits.groups.rest);
if (phit !== null) {
ann.params[phit.groups.param] = phit.groups.rest;}
} else {
console.log("TODO", tag, line)
console.log("TODO", tag, line);
}
break;
case "return":
Expand All @@ -47,16 +48,15 @@ exports.parseComment = function (comment) {
break;
case "error":
if (hasTag) {
ann.errors.push(hits.groups.rest)
ann.errors.push(hits.groups.rest);
} else {
console.log('TODO', tag, line)
console.log('TODO', tag, line);
}
break;
default:
if (hasTag) {
ann.others.push({ 'tag': tag, 'value': hits.groups.rest })
} else {
console.log('TODO', tag, line)
ann.others.push({ 'tag': tag, 'value': hits.groups.rest });
console.log('TODO', tag, line);
}
}
}
Expand Down

0 comments on commit 9f5f3fc

Please sign in to comment.