Skip to content

Commit

Permalink
Merge pull request #30 from Quodatum/v0.2.4
Browse files Browse the repository at this point in the history
V0.2.4 some tests broken
  • Loading branch information
apb2006 committed Jul 23, 2023
2 parents 1868c07 + c912fb2 commit b902763
Show file tree
Hide file tree
Showing 193 changed files with 17,798 additions and 15,462 deletions.
4 changes: 3 additions & 1 deletion .npmignore
Expand Up @@ -2,6 +2,7 @@
.settings/
test/
scripts/
packages.src/
docs/
cases/
specs/
Expand All @@ -10,4 +11,5 @@ specs/
*.ebnf
.vscode
*.tgz
Gruntfile.js
Gruntfile.js
.jshint*
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
## [0.2.4] 2023-07-17
* [fix] wiki scraping for basex v10
* [add] `processors.json`
* [add] getProcessors() on XQLint.
* [mod] parser generator task now a npm script, replacing grunt task.
* [mod] replace dev use of "q" library with native promise.
* [mod] fix some eslint reports
* [mod] Node version min now 16
* [mod] upgrade dependancies
## [0.2.3] 2023-05-15
* [mod] update npm dependancies
* [fix] handling of default function namespace #24
Expand Down
112 changes: 57 additions & 55 deletions Gruntfile.js
@@ -1,88 +1,89 @@
/*jshint esversion: 9 */
const { XQLint } = require('./lib/xqlint');

module.exports = function(grunt) {
'use strict';
module.exports = function (grunt) {
'use strict';

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
require('time-grunt')(grunt);

grunt.registerMultiTask('rex', 'Generate Parsers', function(){

grunt.registerMultiTask('rex', 'Generate Parsers', function () {

var fs = require('fs');
var axios = require('axios');
var FormData = require('form-data');
var path = require('path');
var Q = require('q');
var done = this.async();
var promises = [];
this.data.grammars.forEach(function(parser){
var deferred = Q.defer();
/* return promise to make REx call and save result to file using parser obj properties */
async function rex(parser) {
var grammar = fs.readFileSync(parser.source);
var form = new FormData();
form.append('tz', parser.tz, { knownLength: Buffer.from(parser.tz).length, contentType: 'text/plain' });
form.append('command', parser.command, { knownLength: Buffer.from(parser.command).length, contentType: 'text/plain' });
form.append('input', grammar, { knownLength : Buffer.from(grammar).length, contentType: 'text/plain', filename: path.basename(parser.source) });
form.append('tz', parser.tz, { knownLength: Buffer.from(parser.tz).length, contentType: 'text/plain' });
form.append('command', parser.command, { knownLength: Buffer.from(parser.command).length, contentType: 'text/plain' });
form.append('input', grammar, { knownLength: Buffer.from(grammar).length, contentType: 'text/plain', filename: path.basename(parser.source) });

// Prepare additional headers for Axios, which include FormData's headers and the Content-Length
const headers = {
const headers = {
...form.getHeaders(),
"Content-Length": form.getLengthSync()
'Content-Length': form.getLengthSync()
};
var r = axios.post('https://www.bottlecaps.de/rex/', form, {headers})
.then(function (response) {
fs.writeFileSync(parser.destination, response.data);
deferred.resolve();
})
.catch(function (error) {
deferred.reject(error);
});

promises.push(deferred.promise);
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)
resolve("saved: " + parser.destination);
})
.catch(function (error) {
reject(error);
})
});
}

var promises = [];
this.data.grammars.forEach(function (parser) {
promises.push( rex(parser));
});
Q.all(promises)
.then(function(){
done();
})
.catch(function(error){
grunt.fail.fatal(error);
});
Promise.all(promises).then(function (r){
console.log("dONE",r);
});
console.log("SS")
});
grunt.registerMultiTask('index', 'Generate index xqdoc', function(){

grunt.registerMultiTask('index', 'Generate index xqdoc', function () {
var fs = require('fs');
grunt.file.expand(this.data.src).forEach(function(filename){
var source=fs.readFileSync(filename, 'utf8');
grunt.file.expand(this.data.src).forEach(function (filename) {
var source = fs.readFileSync(filename, 'utf8');
console.log(filename);
var linter = new XQLint(source, { fileName: filename, styleCheck: false });
var xqdoc = linter.getXQDoc();
// Display the file content
console.log(xqdoc);
});
// Display the file content
console.log(xqdoc);
});

//console.log(this.target,this.data)
//console.log(this.target,this.data)
});
grunt.initConfig({
rex: {
parsers: {
grammars: [
{
source: 'lib/parsers/XQueryParser.ebnf',
destination: 'lib/parsers/XQueryParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '0',
}
{
source: 'lib/parsers/XQueryParser.ebnf',
destination: 'lib/parsers/XQueryParser.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '0',
}
]
},
lexers: {
lexers: {
grammars: [
{
source: 'lib/lexers/XQueryTokenizer.ebnf',
source: 'lib/lexers/XQueryTokenizer.ebnf',
destination: 'lib/lexers/XQueryTokenizer.js',
command: '-ll 2 -backtrack -tree -javascript -a xqlint',
tz: '0'
}
]
}
},
]
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
Expand All @@ -96,7 +97,7 @@ module.exports = function(grunt) {
vows: {
all: {
options: {
verbose: true,
verbose: false,
colors: true,
coverage: 'json'
},
Expand All @@ -107,7 +108,7 @@ module.exports = function(grunt) {
},
one: {
options: {
verbose: true,
verbose: false,
colors: false,
coverage: 'json'
},
Expand All @@ -117,9 +118,10 @@ module.exports = function(grunt) {
//src: ['test/stylecheck_test.js']
//src: ['test/function_test.js']
//src: ['test/variable_test.js']
//src: ['test/namespace_test.js'] //3 fail
//src: ['test/parser_test.js'] //26 fail
src: ['test/completion_test.js'] //26 fail
src: ['test/completion_test.js'] //3 fail
//src: ['test/parser_test.js'] //26 fail
//src: ['test/issue_test.js'] //26 fail
},
},
browserify: {
Expand All @@ -134,7 +136,7 @@ module.exports = function(grunt) {
}
},
index: {
main:{
main: {
src: ['specs/xquery.lib/basex.org/*.xq?'],
dest: 'apb/index.js',
}
Expand Down
8 changes: 4 additions & 4 deletions Readme.md
Expand Up @@ -10,9 +10,9 @@


XQLint parses XQuery files and returns errors and warnings based on static code analysis. It provides the following features:
* Lint: errors and warnings based on static code analysis
* Lint: errors and warnings based on static code analysis.
* Format: standardised indentation of source.
* AST: Abstract syntax tree as XML
* AST: Abstract syntax tree as XML.
* xqdoc: json object with information similar to the xqdoc XML format
* Completion: suggestions for line completion given a source and location.
* Highlight console source listing using https://www.npmjs.com/package/colors
Expand All @@ -24,7 +24,7 @@ XQLint parses XQuery files and returns errors and warnings based on static code
This project is in an Alpha state - errors and changes expected.

This project began as a fork of the marvelous [wcandillon/xqlint](https://github.com/wcandillon/xqlint).
but many features have been added and some removed.
but many features have been added and some, such as JSONiq support, removed.

`quodatum/xqlint` has been used as a drop-in replacement for `wcandillon/xqlint` in the following projects:

Expand Down Expand Up @@ -154,7 +154,7 @@ grunt vows:test
## Generate parsers
`grunt parsers`
`npm run-script rex parsers`
Command generates:
Expand Down
31 changes: 26 additions & 5 deletions docs/comments.md
@@ -1,13 +1,34 @@
## Comment handling
Comment are treated as whitespace (WS) by the parser.
`xqdoc.WS()`sets `node.getParent.comment = parseComment(node.value);`
Comment are treated as whitespace (WS) by the parser. If the comment starts
with an XQDoc marker `(:~`
`xqdoc.WS()` will call
```
lastComment = parseComment(node.value);
```

and
`exports.parseComment = function(comment){` returns object `{description:..}`
`lastComment` is a javascript object. Subsequent parser tree vistors can pick up `lastComment`

```javascript
{
description: '',
params: {},
errors: [],
others: []
pos: lintRange
}

export class LintRange{
sl: number;
sc: number;
el: number;
ec: number;
}
```

## Other
1. `parseComment.ebnf` not used
1. xqdoc.parse_comment returns object with description property with xqdoc comment with any ":"

# bugs

many

Binary file modified docs/lint.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/static_context.md
Expand Up @@ -2,6 +2,7 @@

Constructor: `function (parent, pos, processor)`


if processor
then namespaces= {... N.W3, ... N.Basex, ... N.Expath}
```
Expand Down
19 changes: 18 additions & 1 deletion docs/walkthru.md
Expand Up @@ -39,13 +39,30 @@ visit(node) will
if node.name is function it is called
visit node children unless function returns true

# set platform
# set processor
The `processor` option sets the XQuery engine to target.
It can be set to a known value from the keys of the file `processors.json`

This results in the `StaticContext` to be intialized with the packages listed for that key.

```
XQLint: require('./compiler/static_context').StaticContext(undefined,undefined,opts.processor)
```
`namespaces` initial set to standard Xquery 3.1 namespaces.



Old Inside
```
namespaces = { ...namespaces, ...N.Basex, ...N.Expath }
const library = require('./module-library.json');
switch (processor) {
case "basex
}
if ('basex' === processor) {
s.setModules(library);
}
```
# response to import module

...
6 changes: 5 additions & 1 deletion docs/xqdoc.md
Expand Up @@ -43,7 +43,11 @@ this.visit(ast);
## xqdoc.getXQDoc
```
```

## position information
`addfunction` in static_context adds. it is the qname pos
VSCode usage
* range: full range of object
* selectionRange: to be exposed
## Notes
Need way to get pos and posBody seperate from this call.

Expand Down
2 changes: 1 addition & 1 deletion lib/cli/cli.js
Expand Up @@ -109,7 +109,7 @@ lintCmd.option(
)
.option(
'-p, --processor <name>',
'XQuery/JSONiq Processor (e.g. 28msec)',
'XQuery Processor (e.g. basex-10.6)',
function(value) {
return value.toLowerCase();
}
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

0 comments on commit b902763

Please sign in to comment.