npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tree-sitter-xquery

v0.1.2

Published

XQuery tree-sitter

Downloads

9

Readme

A tree-sitter for XQuery

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

The aim is to provide fast identification of syntax tree parts that enable 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 syntax highlighting.

A tree-sitter web playground

Visit the interactive treesitter web playground to see the XQuery tree-sitter in action.

Building

Both Make and Yarn are required to use this repo, 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.

All the work is done in the grammar.js file

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

Identifiers in XQuery

An identifier in XQuery is a Extended QName, aka an EQName. The aim of the XQuery highlight captures for identifiers is show their syntactic role.

my:salary(),
(: highlight 'my' as 'namespace', 'salary' as 'function.call' :)
(salary, bonus),
(: highlight 'salary' and  'bonus' as type.name_test :)

I have attempted to make highlight captures indicates syntactic context

let $salary := 1000 return $salary
(: 
first '$salary' as  variable.let_binding 
'return' as  keyword.return.flwor 
next '$salary' as variable.reference 
:)

An attempt to eliminate semantic token ambiguity

Note: This list is incomplete

brackets

  • [x] "[" "]" predicate in postfix expression
  • [x] "[" "]" predicate in axis step
  • [x] "[" "]" square array constructor

keywords

  • [x] element in prolog declarations

  • [x] element in computed element constructor

  • [x] element in element kind test

  • [x] function in prolog declarations 'default namespace declaration' and 'function declaration'

  • [x] function in inline function expression

  • [x] function in any function test

  • [x] item in prolog declarations 'context item declarations'

  • [x] item in any item test

Testing Goals:

  1. make parse-all The parser SHOULD NOT throw a parse error with any valid XQuery module text.

Tests are run via GitHub actions

The parsing examples that are derived from the W3C xQuery recommendation are found in the 'examples/spec' folder. Other parse examples are from the qt3tests suite and are in the examples/qt3tests folder

To peek at tree-sitter highlight captures in action, I run some query examples in GitHub actions, which you might want to look at.

using tree-sitter with neovim

Follow the instructions at GitHub: nvim-treesitter to use the xquery treesitter

local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.xquery = {
  install_info = {
    url = "~/projects/grantmacken/tree-sitter-xquery", -- where you have cloned this project
    files = {"src/parser.c"}
  }
}

Contributing, Discussions and Issues

Contributions and suggestions in form of issues are welcome.