Can a parser, generated by tree-sitter, be used both for both syntax highlighting and compiler itself? If not - why?
It would be counterproductive to write 2 different parsers and maintain them.
Note: I haven't used tree-sitter yet, but consider using it for highlighting syntax of my own programming language. Due-to that, I may misunderstand how it's parser actually works.
Quoting the answer from https://github.com/tree-sitter/tree-sitter/discussions/831:
I managed to use a tree-sitter parser for a toy language to implement an interpreter in Rust: https://github.com/sgraf812/tree-sitter-lambda/blob/35fe05520e806548dedb48e7f97118847b531b26/src/main.rs
Having done that, I can't recommend it:
bison
and C). This means you have to switch overNode::kind
, a string. Inefficient and incomplete matches everywhere.ut8_text
.I have a feeling that tree-sitter is best in class only when you don't need a typed overlay of the syntax tree.
See also https://github.com/tree-sitter/tree-sitter/discussions/831#discussioncomment-5797368 for another experience report.