roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.39k stars 309 forks source link

start on tree sitter grammar for highlighting in "legacy mode" #4468

Open Anton-4 opened 1 year ago

Anton-4 commented 1 year ago

The editor will be projectional by default and will not need a tree sitter grammar(TSG) to highlight in that mode because it uses the Abstract Syntax Tree. However because projectional editors can make some editing operations very difficult we want to allow the user to switch to legacy mode where they are completely free to delete or add text just like in regular editors like VScode.

For this legacy mode we would also like to have syntax highlighting, which would be enabled by the TSG.

To construct this grammar the following file will be useful:

rtfeldman commented 1 year ago

I dunno if this is related, but something that would be really handy for documentation generation is a way to take code snippets in doc comments and do token-based highlighting - so, don't translate it into an actual Roc parse::ast node (because that discards spaces, and also fails if it sees something it doesn't recognize) but rather doing a relaxed token-based highlighting that preserves spaces, never fails, and yet would let us emit colored <span>s in the docs generation.

Anton-4 commented 1 year ago

:+1: I think the TSG fits all these constraints :)