Skip to content

Commit

Permalink
[add] getDocLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
apb2006 committed May 13, 2023
1 parent a088031 commit 53ce5f0
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [0.2.3] 2023-05-15
* [mod] update npm dependancies
* [fix] handling of default function namespace #24
* [fix] module level xqdoc comments #25
* [add] documentLink support

## [0.2.2] 2023-04-22
* [xqdoc] vars and functions have .comments created from xqdoc style comments

Expand Down
File renamed without changes.
16 changes: 6 additions & 10 deletions lib/compiler/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ exports.ModuleDecl = function(translator, rootSctx, node){
};
};

exports.ModuleImport = function(translator, rootSctx, node) {

exports.ModuleImport = function(translator, rootSctx, node,ats) {
var prefix = '';
var moduleURI;
//location hints
Expand All @@ -35,18 +36,13 @@ exports.ModuleImport = function(translator, rootSctx, node) {
prefix = TreeOps.flatten(ncname);
},

URILiteral: function(uri) {
uri = TreeOps.flatten(uri);
URILiteral: function(node) {
let uri = TreeOps.flatten(node);
uri = uri.substring(1, uri.length - 1);
if(moduleURI !== undefined) {
//location hints
console.log("AT: ",uri);
return;
}

if(moduleURI !== undefined) return ; //location hints
moduleURI = uri;
translator.apply(function(){
rootSctx.importModule(uri, prefix, node.pos);
rootSctx.importModule(uri, prefix, node.pos,ats);
});
}
};
Expand Down
16 changes: 10 additions & 6 deletions lib/compiler/static_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,16 @@ exports.StaticContext = function (parent, pos, processor) {
defaultElementNamespace: '',
namespaces: namespaces,
availableModuleNamespaces: [],
importModule: function (uri, prefix, pos) {
locations: {}, // ns:{location:..,pos:..}
importModule: function (uri, prefix, pos,ats) {
if (this !== this.root) {
throw new Error('Function not invoked from the root static context.');
}
this.addNamespace(uri, prefix, pos, 'module');
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, []);
var mod = this.moduleResolver(uri, ats);
if (mod.variables) {
TreeOps.concat(this.variables, mod.variables);
}
Expand All @@ -241,7 +243,9 @@ exports.StaticContext = function (parent, pos, processor) {
}
return this;
},

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

addNamespace: function (uri, prefix, pos, type) {
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 @@ -281,7 +285,7 @@ exports.StaticContext = function (parent, pos, processor) {
pos: pos,
type: type
};

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
13 changes: 12 additions & 1 deletion lib/compiler/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,18 @@ exports.Translator = function(rootStcx, ast){
};

this.ModuleImport = function (node) {
this.visitChildren(node, Handlers.ModuleImport(translator, rootStcx, node));
let ats=[],seenAt=false;
this.visitChildren(node,{
TOKEN: function(token){
seenAt="at"===token.value;
},
URILiteral: function(node) {
if(!seenAt) return;
var uri = TreeOps.flatten(node);
uri = uri.substring(1, uri.length - 1);
ats.push({location:uri,pos: node.pos});
}});
this.visitChildren(node, Handlers.ModuleImport(translator, rootStcx, node,ats));
return true;
};

Expand Down
7 changes: 6 additions & 1 deletion lib/xqlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports.XQLint = function (source, opts) {
//ACE editor worker hack
opts = { ...defaults, ...opts }

var ast, xqdoc;
var ast;
var sctx = opts.staticContext ? opts.staticContext : createStaticContext(opts.processor);

this.getAST = function (pos) {
Expand All @@ -59,6 +59,11 @@ exports.XQLint = function (source, opts) {
return xqdoc.getXQDoc(withPos);
};

this.getDocLinks = function () {
const dl=sctx.getDocLinks();
return dl;
};

var markers = [];
this.getMarkers = function () {
return markers;
Expand Down
4 changes: 2 additions & 2 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
Original file line number Diff line number Diff line change
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.2.2",
"version": "0.2.3",
"keywords": [
"xquery",
"dev",
Expand Down
2 changes: 1 addition & 1 deletion scripts/modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
// generate index.json file from xqm files in dir
// generate module-library.json file from xqm files in dir
var dir='specs/libs/basex-9.7';
var fn='specs/libs/w3c/xpath3.1-fn.xqm';
var out='lib/compiler/module-library.json';
Expand Down
9 changes: 9 additions & 0 deletions test/features/doclinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// generate xqdoc
var fs = require('fs');

var XQLint = require('../../lib/xqlint').XQLint;
var baseUri="C:/Users/andy/git/quodatum/xqlint/";

var linter = new XQLint(fs.readFileSync(baseUri+'cases/override.xq', 'utf-8'), { styleCheck: false });
var links = linter.getDocLinks();
console.log(links);
7 changes: 3 additions & 4 deletions test/features/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
var fs = require('fs');

var XQLint = require('../../lib/xqlint').XQLint;
var baseUri="C:/Users/andy/git/quodatum/xqlint/";

var src="C:/Users/andy/git/quodatum/xqlint/test/queries/update/fun.xq";
//src="cases/history.xqm";
var linter = new XQLint(fs.readFileSync(src, 'utf-8'),{fileName: src});
var markers = linter.getMarkers()
var linter = new XQLint(fs.readFileSync(baseUri+'test/xqlint_queries/namespaces/1.xq', 'utf-8'), { styleCheck: false });
var markers = linter.getMarkers();
console.log(markers);
2 changes: 1 addition & 1 deletion test/namespace_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ vows.describe('Test Namespace declarations').addBatch({
var error = markers[0];
assert.equal(error.type, 'error', 'Type of marker');
assert.equal(error.message.indexOf('[XQST0047]'), 0, 'Is Error [XQST0047]');
assert.deepEqual(error.pos, { sl: 1, sc: 0, el: 1, ec: 50 }, 'Marker Position');
assert.deepEqual(error.pos, { sl: 1, sc: 30, el: 1, ec: 50 }, 'Marker Position');
var warning = markers[1];
assert.equal(warning.type, 'warning', 'Type of marker');
},
Expand Down
3 changes: 0 additions & 3 deletions test/test.xq

This file was deleted.

0 comments on commit 53ce5f0

Please sign in to comment.