pulsar-edit / pulsar

A Community-led Hyper-Hackable Text Editor
https://pulsar-edit.dev
Other
3.11k stars 131 forks source link

Add a "JSON with Comments" grammar #1050

Open savetheclocktower opened 1 week ago

savetheclocktower commented 1 week ago

Copied from a draft issue on the WASM/Modern tree-sitter project.

This is an interesting idea because tree-sitter-json properly parses JavaScript-style comments. They aren't automatically errors, which means that tree-sitter-json could just as easily support a JSONC grammar (i.e., “JSON with comments,” used in the VS Code sense) as it does a JSON grammar.

Right now, inserting a comment into a JSON file (using its modern Tree-sitter grammar) has no effect; the comment is highlighted neither as a comment nor as an invalid token.

We could do the following:

savetheclocktower commented 1 week ago

There's another draft issue about adding a JSON5 grammar. That would take more effort, since some of JSON5's enhancements aren't understood by tree-sitter-json. There is a community JSON5 tree-sitter parser (though I haven't investigated it too deeply), but since it'd need a different parser, it might as well be a community package unless people clamor for it. (I think JSON5 is a good idea, but it's not exactly catching on in my corners of the development world.)