I’m thinking of writing an F# plugin for Atom and I was wondering if it is possible to reuse an existing tokenizer that is exposed by the F# Compiler Services rather than describing the grammar using a CSON file.
I found the
Grammar class, which sounds like exactly what I could use. So, I’m thinking that I could implement my own
Grammar and pass it to the
addGrammar function on
My questions are:
- Would this work? And are there any examples where people already did this that I could follow?
- Is there any way to change the colorization later? Say, there is a long running asynchronous process in the background that eventually tells me more information about some identifiers…
PS: Before I’m told that I should not be doing this here is a couple of reasons:
Some of the tokenization rules in F# are not trivial. For example, string in a comment still behaves like a string (useful if you want to comment out code), for example:
code (* comment " *) " still comment *) code. It gets more subtle than this.
It just sounds silly not to reuse a tokenizer for the language that already exists and can be easily called (and will always be sync with the version of the language currently used).
This is perhaps a separate thing (that could be done on top of basic grammar), but F# queries have extensible syntax where the keywords can be highlighted only after we know the types (after type checking).
PPS: Yes, there is already language-fsharp for Atom, which is probably a good start if we really have to use CSON grammar specification.