Skip to content

Commit

Permalink
[mod] xqdoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
apb2006 committed Apr 21, 2023
1 parent 00e13e0 commit d7d4396
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 146 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## [0.2.2] 2023-04-22
* [xqdoc] vars and functions have .comments created from xqdoc style comments

## [0.2.1] 2023-02-26
function library, availablenamespaces progress.
function library, available namespaces progress.

## [0.2.0] 2023-02-19
reorg, function library progress.
Expand Down
11 changes: 10 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# About @Quodatum/XQLint
# @Quodatum/XQLint

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/quodatum/xqlint/release.yml)

[![Dependency Status](https://deps.rs/repo/github/quodatum/xqlint/status.svg)](https://deps.rs/repo/github/quodatum/xqlint)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/quodatum/xqlint/releases)

[![GitHub Release](https://img.shields.io/github/release/quodatum/xqlint.svg)](https://github.com/quodatum/xqlint/releases/latest)
![GitHub](https://img.shields.io/github/license/quodatum/xqlint)
![GitHub last commit](https://img.shields.io/github/last-commit/quodatum/xqlint)

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
Expand Down
8 changes: 7 additions & 1 deletion docs/comments.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
Suspect:
## Comment handling
Comment are treated as whitespace (WS) by the parser.
`xqdoc.WS()`sets `node.getParent.comment = parseComment(node.value);`

and
`exports.parseComment = function(comment){` returns object `{description:..}`

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

Expand Down
46 changes: 19 additions & 27 deletions docs/notes.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# xqlint

Syntax `new XQLint(source, opts)` where
opts is
* styleCheck: false
* staticContext:


## staticContext.js
Models the static context.
### namespaces

### availableModuleNamespaces
Expand All @@ -16,14 +18,16 @@ moduleNamespace: not set
description: not set
defaultfunctionnamespace wrong

### translator.js
In xqlint
## translator.js
Called in xqlint. Gets markers, also adds to `sctx`

```javascript
var translator = new Translator(sctx, ast);
var translator = new Translator(sctx, ast);
markers = markers.concat(translator.getMarkers());
...
this.visit(ast);

```

messages..
```javascript
StaticWarning('W01', 'Avoid this type of import. Use import module namespace instead', pos);
Expand All @@ -33,7 +37,7 @@ StaticWarning('W02', '"' + uri + '" already bound to the "' + namespace.prefixes
addWarning('W04', 'Unused module "' + uri + '"', namespace.pos);
addWarning('W05', 'Untyped return value', name.pos);
```
#### Vistor
#### Visitor
```
InsertExpr
::= 'insert' ( 'node' | 'nodes' ) SourceExpr InsertExprTargetChoice TargetExpr
Expand All @@ -45,17 +49,19 @@ RenameExpr
::= 'rename' 'node' TargetExpr 'as' NewNameExpr
```
### handlers.js
```
StaticWarning('W06', 'Avoid default element namespace declarations.', node.pos);
```

## definitions
* AST Abstract syntax tree
* 'W06', 'Avoid default element namespace declarations.', node.pos

### formatter/style_check.js

* [SW01] Detected CRLF
* [SW02] Tabs detected
* [SW03] Unexpected indentation of ..
* [SW04] Trailing whitespace

## module.js
Exports Basex, W3, Expath

# tests
## test/module_resolver_test.js
## test/index.js
```xquery
Expand Down Expand Up @@ -130,19 +136,5 @@ POP: EQName
endNonterminal VarName
```

# translator
function(
rootStcx: staticcontext
,ast: ast
)
```
translator.js
this.FunctionCall = function(node){
this.visitOnly(node, ['ArgumentList']);
var name = translator.getFirstChild(node, 'EQName');
declare function local:test($hello){
$hello
};
```
# definitions
* AST Abstract syntax tree
42 changes: 26 additions & 16 deletions docs/walkthru.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# visit
In xqlint
```javascript
var translator = new Translator(sctx, ast);
...
this.visit(ast);
```
visit(node) will
if node.name is function it is called
visit node children unless function returns true


# xqdoc
```
var xql=new XQLint(source, opts)
var ast, xqdoc, sctx
sctx=createStaticContext(opts.processor)
ast = h.getParseTree();
xqdoc=new XQDoc(ast);
markers[],
markers+=new StyleChecker(ast, source).getMarkers()
markers+=new Translator(ast, source).getMarkers()
xql.getXQDoc()
new XQDoc(ast)
walks tree
```

```
///vars
Expand All @@ -22,12 +28,16 @@ var fn=sctx.functions[key];
params:params
pos: pos
```
## Comment handling
Comment are treated as whitespace (WS) by the parser.
`xqdoc.WS()`sets `node.getParent.comment = parseComment(node.value);`

and
`exports.parseComment = function(comment){` returns object `{description:..}`
# visit
In xqlint.js
```javascript
var translator = new Translator(sctx, ast);
...
this.visit(ast);
```
visit(node) will
if node.name is function it is called
visit node children unless function returns true

# response to import module

Expand Down
11 changes: 7 additions & 4 deletions docs/xqdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ xqdoc info can be imported into static context with `sctx.setModulesFromXQDoc()`

```
functions[uri + '#' + fn.name + '#' + fn.arity] = {
type: 'FunctionDecl',
params: [],
annotations: [],
name: fn.name,
arity: fn.arity,
eqname: { uri: uri, name: fn.name }
};
variables[uri + '#' + name] = { type: 'VarDecl',
annotations: [],
eqname: { uri: uri, name: name } };
});
variables[uri + '#' + name] = {
type: 'VarDecl',
annotations: [],
eqname: { uri: uri, name: name }
};
```

Expand Down
3 changes: 3 additions & 0 deletions lib/compiler/static_context.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,12 @@ exports.StaticContext = function (parent, pos, processor) {
throw new StaticError('XQST0034', '"' + qname.name + '": duplicate function declaration', pos);
}
this.functions[key] = {
qname:qname,
arity: arity,
pos: pos,
params: params
};
//console.log("AA",this.functions[key])
return this;
}

Expand Down
35 changes: 19 additions & 16 deletions lib/compiler/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ exports.Translator = function(rootStcx, ast){
});
}
});

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;
Expand Down Expand Up @@ -216,7 +217,6 @@ exports.Translator = function(rootStcx, ast){
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 === '?') {
Expand Down Expand Up @@ -246,19 +246,22 @@ exports.Translator = function(rootStcx, ast){
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 arity = 2; //TODO
// console.log(qname, arity);
// var fn = rootStcx.getFunction(qname, arity);
// fn.annotations = annotations;
// return true;
// }
// });

var qname,arity=0;
var handlers={
EQName: function(fnname){
var value = TreeOps.flatten(fnname);
qname = sctx.resolveQName(value, fnname.pos);
return true;
},
ParamList: function(node){
translator.visitChildren(node,handlers)
},
Param: function(p){
arity++;
}
};
this.visitChildren(node, handlers);
var fn = rootStcx.getFunction(qname, arity);
var isExternal = false;
node.children.forEach(function(child){
if(child.name === 'TOKEN' && child.value === 'external') {
Expand Down
7 changes: 5 additions & 2 deletions lib/formatter/style_checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ exports.StyleChecker = function (ast, source) {
getTokenList(ast);
*/

var tab = ' ';
var tab = '\t';
var markers = [];
//@todo use these
var maxLength=80;
var maxFunctionLines=60;

this.getMarkers = function(){
return markers;
Expand Down Expand Up @@ -73,7 +76,7 @@ exports.StyleChecker = function (ast, source) {
},
type: 'warning',
level: 'warning',
message: '[SW03] Unexcepted indentation of ' + match[0].length
message: '[SW03] Unexpected indentation of ' + match[0].length
});
}
}
Expand Down

0 comments on commit d7d4396

Please sign in to comment.