Skip to content

Commit

Permalink
Merge pull request #39 from Quodatum/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
apb2006 committed Aug 12, 2023
2 parents dc4e032 + aabf04a commit 50227da
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,5 @@
## [0.3.2] 2023-08-12
* [fix] defaultfunction namespace issue #38
## [0.3.0] 2023-08-10
* [mod] use xq-catalogs for module library handling
* [fix] xq outline
Expand Down
10 changes: 6 additions & 4 deletions lib/compiler/static_context.js
Expand Up @@ -3,7 +3,7 @@ const xqc = require('@quodatum/xq-catalogs');

// convert array to object representation
function keyed(arr) {
if(!Array.isArray(arr)){return arr;}
if (!Array.isArray(arr)) { return arr; }
const obj = {};
arr.forEach(f => obj[f.key] = f);
return obj;
Expand Down Expand Up @@ -239,7 +239,7 @@ exports.StaticContext = function (parent, pos, processor) {
try {
var mod = this.moduleResolver(uri, ats);
if (mod.variables) {
TreeOps.concat(this.variables,keyed( mod.variables));
TreeOps.concat(this.variables, keyed(mod.variables));
}
if (mod.functions) {
TreeOps.concat(this.functions, keyed(mod.functions));
Expand Down Expand Up @@ -349,7 +349,7 @@ exports.StaticContext = function (parent, pos, processor) {
}
},

// find uri from prefix if required
// find uri from prefix if required note does NOT resolve defaultfunctionnamespace
resolveQName: function (value, pos) {
var qname = {
uri: '',
Expand Down Expand Up @@ -494,7 +494,9 @@ 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 Down
23 changes: 11 additions & 12 deletions lib/xqdoc/xqdoc.js
Expand Up @@ -13,7 +13,7 @@ exports.XQDoc = function (ast,sctx) {
const comments={}; // keyed as fn/vars
const lintRanges={}; // keyed as fn/vars
var prefix=null;
var querybody=null; // caputure pos if present
var querybody=null; // capture pos if present
this.WS = function (node) {
if (node.value.trim().substring(0, 3) === '(:~') {
lastComment=parseComment(node.value);
Expand All @@ -36,14 +36,17 @@ exports.XQDoc = function (ast,sctx) {
comments[key]=lastComment;
lastComment=null;
}
lintRanges[key]=node.getParent.pos;
lintRanges[key]={type: "VarDecl", pos:node.getParent.pos};
// console.log("VarDecl: ",value,", pos: ",node.pos,", comments: ",node.getParent.comments)
};

this.FunctionDecl = function (node) {
var fnname = this.getFirstChild(node, 'EQName');
var value = TreeOps.flatten(fnname);
var qname = sctx.resolveQName(value, fnname.pos);
if(qname.uri===""){
qname.uri=sctx.defaultFunctionNamespace;
}
var arity="0";
var params = this.getFirstChild(node, 'ParamList');
if(params){
Expand All @@ -58,7 +61,7 @@ exports.XQDoc = function (ast,sctx) {
comments[key]=lastComment;
lastComment=null;
}
lintRanges[key]=node.getParent.pos; // save range of enclosing declaration
lintRanges[key]={type:"FunctionDecl",pos:node.getParent.pos}; // save range of enclosing declaration
//console.log("FunctionDecl: ",value,", pos: ",node.pos,", comments: ",node.getParent.comments)
};

Expand All @@ -75,7 +78,7 @@ exports.XQDoc = function (ast,sctx) {
};
// main module,xq not xqm
this.QueryBody=function(node){
console.log("QueryBody");
//console.log("QueryBody");
querybody=node.pos;
};

Expand All @@ -89,7 +92,7 @@ exports.XQDoc = function (ast,sctx) {
};
if(comments.module){doc.description=comments.module.description;}

Object.keys(sctx.variables).forEach((key) => {
Object.keys(lintRanges).filter(k=>lintRanges[k].type==='VarDecl').forEach((key)=>{
var variable = sctx.variables[key];
var varDecl = {... variable.qname}; //name,prefix,uri
varDecl.key = key;
Expand All @@ -103,11 +106,7 @@ exports.XQDoc = function (ast,sctx) {
doc.variables.push(varDecl);
});

Object.keys(sctx.functions).forEach((key) => {
const ns=key.substring(0, key.indexOf("#"));
if (ns === 'http://www.w3.org/2001/XMLSchema') {
return;
}
Object.keys(lintRanges).filter(k=>lintRanges[k].type==='FunctionDecl').forEach((key)=>{
var fn = sctx.functions[key];
//console.log("fn-key:",key)
var tokens = key.split('#');
Expand All @@ -127,13 +126,13 @@ exports.XQDoc = function (ast,sctx) {
doc.functions.push(fnDecl);
});
if(querybody){
doc.querybody=querybody;
doc.queryBody=querybody;
}
return doc;
};
this.setPos = function (decl, key, pos) {
decl.pos = pos;
var full = lintRanges[key];
var full = lintRanges[key].pos;
decl.posAll = full;
};
this.visit = function (node) {
Expand Down
1 change: 1 addition & 0 deletions lib/xqlint.d.ts
Expand Up @@ -37,6 +37,7 @@ declare module '@quodatum/xqlint' {
description: string;
variables: [VarDecl];
functions: [FunDecl];
queryBody?: LintRange;
}
export interface VarDecl {
name: string;
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Andy Bunce <bunce.andy@gmail.com> (https://github.com/apb2006)",
"name": "@quodatum/xqlint",
"description": "XQuery Quality Checker",
"version": "0.3.0",
"version": "0.3.2",
"keywords": [
"xquery",
"dev",
Expand Down
1 change: 1 addition & 0 deletions test/features/xqdoc.js
Expand Up @@ -4,6 +4,7 @@ var fs = require('fs');
var XQLint = require('../../lib/xqlint').XQLint;
//var src="test/queries/rbtree.xq/map.xq";
var src="test/queries/issues/pic-datefix.xq";
//var src="test/queries/rbtree.xq/rbtree.xq";
//src="cases\history.xqm";
var linter = new XQLint(fs.readFileSync(src, 'utf-8'));
// .hasSyntaxError()
Expand Down
5 changes: 3 additions & 2 deletions test/parser_test.js
Expand Up @@ -29,8 +29,9 @@ var files = getFiles('test/queries/basex');
files = files.concat(getFiles('test/queries/update'));
files.forEach(function(file){
batch[file] = function(){
//@todo processor: ?
var linter = new XQLint(fs.readFileSync(file, 'utf-8'), { styleCheck: false, fileName: file, processor: 'basex-9' });
const src=fs.readFileSync(file, 'utf-8');
//console.log(file);
var linter = new XQLint(src, { styleCheck: false, fileName: file, processor: 'basex-9' });
var syntaxError = linter.hasSyntaxError();
if(syntaxError) {
assert.equal(syntaxError, false, linter.getMarkers()[0].message);
Expand Down

0 comments on commit 50227da

Please sign in to comment.