4 ms·
Are there any plans to support modifying the grammar on the fly or without recompiling?
by yig 6y ago
Are there any plans to support modifying the grammar on the fly or without recompiling?
- maxbrunsfeld 6y agoOne day, I would love to generalize the web-based playground so that you could edit the grammars. But it's complicated, because we use C as our output language, so you would always need to recompile the C after changing the grammar. So, I would say that it's not on our near-term roadmap.
- dcreager 6y agoI don't think you can do this without recompiling, since the grammars get translated into C code before use. But the built-in command line tools (‘tree-sitter parse’, etc) all support a mode where they will detect local changes to a checked-out grammar definition, and recompile on the fly if needed. (This happens each time the CLI program is started up; it doesn't happen during a long-running process.)
- sitkack 6y agoThe obvious answer is to embed TCC or another C compiler and either generate a dynamic library or generate wasm and load it directly into the process. exec_wasm(generate_wasm(generate_c(grammar))) Now if you can make that whole fn chain incremental, then a delta_grammar -> delta_c -> delta_wasm -> delta_recomputed_wasm_call stack, this will propagate deltas down to exec_wasm and you could dynamically execute the generated code as the grammar changes.