Hacker News new | ask | show | jobs
by mickeyp 653 days ago
Impressive! The grammar.json file is just a little bit too underspecced to automate some things. Not to mention it's self-referential. How did you deal with extras and other 'specialisms' that are secretly hidden away in the C-level scanner and so on?

I ask because I wrote Combobulate [1], a structured editing and movement tool for Emacs using TS.

1: https://github.com/mickeynp/combobulate

2 comments

Also there was several requests to create a more formal grammar to describe the grammars but the tree-sitter developers doesn't like the idea and reject then.

But some people did nice attempts like https://github.com/eatkins/tree-sitter-ebnf-generator that I also adapted and exposed it here https://mingodad.github.io/lua-wasm-playground/ to allow play with it online (select "Tree-sitter-ebnf-generator" from examples then click "Run" to see a "grammar.js" generated from the content in "Input Text (arg[1])").

I've added more non trivial grammars Javascript, Java, Kotlin, PHP, C, CPP, Rust, Ruby, CSS, HTML, Python using a quickjs script to convert "src/grammar.json" to an EBNF understood by https://mingodad.github.io/lua-wasm-playground/ (the script is here https://github.com/mingodad/plgh/blob/main/json2ebnf-lua.js).
I simple ignore then as right now they doesn't seen relevant in most grammars to generate an usable railroad diagram.