Skip to content

Commit

Permalink
wip: format, readme
Browse files Browse the repository at this point in the history
  • Loading branch information
grantmacken committed Jun 1, 2023
1 parent 4a1a436 commit f54b3c9
Show file tree
Hide file tree
Showing 8 changed files with 485 additions and 622 deletions.
22 changes: 15 additions & 7 deletions README.md
@@ -1,5 +1,4 @@

# tree-sitter-xQuery
# tree-sitter-xquery

A tree-sitter grammar is built for an as-you-type experience in a text editor.

Expand All @@ -9,33 +8,33 @@ text highlighting, indenting, folding, scope info and more for a text editor.
The incremental tree-sitter parse should be a step above text highlighting with regular
expressions, however tree-sitter should not be confused with a validating parser. Unlike a
validating parser, tree-sitter will not stop on-error, but continue to parse and provide
a syntatic highlighting.
a syntax highlighting.

- [tree-sitter presentation](https://www.youtube.com/watch?v=Jes3bD6P0To) - a new parsing system for programming tools
- [why tree sitter](https://github.com/github/semantic/blob/master/docs/why-tree-sitter.md) - github semantic team


## tree-sitter web playground

Visit the interactive treesitter web [playground](https://grantmacken.github.io/tree-sitter-xquery) to see the
XQuery treesitter in action.


## building

Both Make and Yarn are required to use this repo used so you will need to install both.
Clone and cd into this repo then run `make install` which will use Yarn to install the tree-sitter cli.
Clone and `cd` into this repo then run `make install` which will use Yarn to install the tree-sitter cli.


All the work is done in the grammar.js file

The repo contains a Makefile as I use `make` for treeitter aliases.
The repo contains a Makefile as I use `make` for treesitter aliases.
The default `make` target is an alias for `tree-sitter generate` which will create tree-sitter files from the grammar

To see other make targets type `make help`

## An attempt to eliminate semantic token ambiguity

Note: This list is not complete

### brackets

- [x] ` "[" "]" ` predicate in postfix expression
Expand All @@ -55,6 +54,8 @@ To see other make targets type `make help`
- [x] `item` in prolog declarations 'context item declarations'
- [x] `item` in any item test



## testing gaols: 1, 2, 3

1. `make parse-all` The parser **SHOULD NOT** throw a parse error with any **valid** xQuery module text.
Expand All @@ -66,8 +67,10 @@ Tests are run via [github actions](https://github.com/grantmacken/tree-sitter-xQ
The parsing examples that are derived from the [W3C xQuery recommendation](https://www.w3.org/TR/xquery-31)
are found in the 'examples/spec' folder. Other parse examples are from the [qt3tests suite](https://github.com/w3c/qt3tests) and are in the examples/qt3tests folder

<!-- TODO
The `test/corpus/` tree-sitter tests are mainly organised around the sections outlined in the
[W3C xQuery recommendation](https://www.w3.org/TR/xquery-31).
-->

To peek at tree-sitter highlight captures in action, I run some query examples in
[github actions](https://github.com/grantmacken/tree-sitter-xQuery/actions)
Expand All @@ -92,6 +95,9 @@ parser_config.xquery = {
}
```

<!--
## better semantic highlighting: example in neovim
![terminal screeshot](assets/2021-09-02_10-56.png)
Expand All @@ -106,6 +112,8 @@ More spot the semantic color differences
- '[' ']' can be a square array constructors or delimit predicates
- '(' ')' can be a parenthesized expr or delimit parameter and argument lists
-->

## Contributing, Discussions and Issues

[Contributions](CONTRIBUTING.md) and suggestions in form of
Expand Down
12 changes: 7 additions & 5 deletions examples/spec/arrow.xq
@@ -1,5 +1,7 @@
$string => upper-case() => normalize-unicode() => tokenize("\s+"),
'abc'=> substring(1,2),
let $string := 'aa bb cc'
return
$string=>replace('a','b')=>normalize-space()=>tokenize("\s")
'3.20 Arrow operator (=>)',
U => F(A, B, C),
'is the same as',
F(U, A, B, C),
tokenize((normalize-unicode(upper-case($string))),"\s+"),
'is the same as',
$string => upper-case() => normalize-unicode() => tokenize("\s+")
2 changes: 1 addition & 1 deletion examples/spec/construction_declaration.xq
@@ -1,2 +1,2 @@
declare construction;
declare construction preserve;
()
3 changes: 2 additions & 1 deletion grammar.js
Expand Up @@ -264,7 +264,8 @@ module.exports = grammar({
rel_path_expr: ($) => prec.left(19, seq($._step_expr, repeat(seq(choice('/', '//'), $._step_expr)))),
_step_expr: ($) => prec.left(19, seq(choice($._postfix_expr, $._axis_step))),
_axis_step: ($) => seq(field('axis', choice($._forward_step, $._reverse_step)), repeat(prec.left(20, field('filter', $.predicate)))), // predicate within steps 123
_reverse_step: ($) => choice($.reverse_axis, '..'),
_reverse_step: ($) => choice($.reverse_axis, $.abbrev_reverse_step),
abbrev_reverse_step: ($) => '..',
_forward_step: ($) => choice($.forward_axis, $.abbrev_forward_step),
forward_axis: ($) => seq(choice('child', 'descendant', 'attribute', 'self', 'descendant-or-self', 'following-sibling', 'following'), '::', $._node_test), //113
reverse_axis: ($) => seq(choice('parent', 'ancestor', 'preceding-sibling', 'preceding', 'ancestor-or-self'), '::', $._node_test), //116
Expand Down

0 comments on commit f54b3c9

Please sign in to comment.