lezer-parser / lezer

Dev utils and issues for the Lezer core packages
33 stars 1 forks source link

Query a syntax tree, – a la Tree-Sitter. #10

Closed c4lliope closed 3 years ago

c4lliope commented 3 years ago

I was pleased to find that this library took inspiration from Tree-Sitter; there seems to be no better example of how to build an editor-ingrained parser which can handle reparsing a syntax tree on each keystroke.

I am curious if the inspiration of copying Tree-Sitter's basic constructs extends to copying their "Query" API – see the docs and the playground.

I am deciding on a parser for my in-browser editor program, and I am inspired by Lezer's being Javascript-native, but I need query support for detecting common refactorings that are possible in the code.

I couldn't find any documentation in Lezer regarding querying syntax trees; am I missing the feature someplace?

Much obliged.

marijnh commented 3 years ago

No, there's no query system like that. There's no support for 'fields' either. The only helper for selective tree-walking is getChild (in combination with 'group' properties on node types), which is quite minimal.

I did look into this, but it felt too heavyweight for this library (support for fields would grow the size of each node value in memory, and a query language would add quite a bit of code that every client has to download).

c4lliope commented 3 years ago

No problem – nice reasoning, and thanks for the quick reply.