3 ms·
XPath is very impressive and expressive when one just looks outside the xml/html world. An abstract XPath query selector only needs a tree enumerator with nodes
by Agraillo 3y ago
XPath is very impressive and expressive when one just looks outside the xml/html world. An abstract XPath query selector only needs a tree enumerator with nodes reporting the name and (optionally) some attributes. One of such application is querying against Abstract Syntax Trees [1] of programming languages. The name here is the name of the rule of then node. A further step is to have semantic relationships understood. In this case something like //IDENT[@owning_class='CFooBar'] is possible
[1] https://en.wikipedia.org/wiki/Abstract_syntax_tree https://en.wikipedia.org/wiki/Abstract_syntax_tree
- eyelidlessness 3y agoNot XPath, but for folks interested in querying (rather than walking) syntax trees for arbitrary nodes, this is also a cool feature of tree-sitter[1]. It uses a scheme-like syntax, and it’s impressively efficient. And in terms of XPath, for folks using a JS stack, fontoxpath[2] supports a DOM facade adapter interface which allows for querying any arbitrary tree-like structure, so it could certainly handle the same use case. 1: https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries https://tree-sitter.github.io/tree-sitter/using-parsers#patt... 2: https://github.com/FontoXML/fontoxpath https://github.com/FontoXML/fontoxpath
- marcelr 3y agoI'm doing this with css to do syntax highlighting & formatting for [my editor](https://coil-editor.netlify.app/ https://coil-editor.netlify.app/). I also wrote some linters like using undefined variable names in like 5 lines of code using query selectors, this was before I learned more about xpath, so I imagine it'll only be more powerful