Closed LukaHorvat closed 8 years ago
Yes and no.
As for 'no' part, with TextMate's grammar model (used by Atom) it's impossible to detect =>
on the next line. See https://github.com/atom-haskell/language-haskell/issues/57 for more information.
As for 'yes' part, I just pushed v1.9.0 which plain and simply gives up on trying to detect constraints in type signatures, and just highlights prelude typeclasses as typeclasses, so that would actually make your definitions the same color, although not as nicely as one might hope.
Well, that looks nice. I was wondering, would it be possible to highlight identifiers that are in the current scope, differently? That sounds like a pretty useful feature.
I guess it would just consist of updating your "known classes" dynamically. I assume you already do a similar thing with the autocomplete lists.
On Mon, Aug 8, 2016, 5:52 PM Nikolay Yakimov notifications@github.com wrote:
Yes and no.
As for 'no' part, TextMate's grammar model (used by Atom) it's impossible to detect => on the next line. See #57 https://github.com/atom-haskell/language-haskell/issues/57 for more information.
As for 'yes' part, I just pushed v1.9.0 which plain and simply gives up on trying to detect constraints in type signatures, and just highlights prelude typeclasses as typeclasses, so that would actually make your definitions the same color, although not as nicely as one might hope. [image: image] https://cloud.githubusercontent.com/assets/7275622/17486346/25fff556-5d99-11e6-8958-b8d0b22cdc29.png
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/atom-haskell/language-haskell/issues/81#issuecomment-238281409, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWnwygi69bHd9xoleKvcTzRE46C5uYfks5qd1DbgaJpZM4JfHCX .
No, no. Atom's grammar model doesn't support actual parsing, only tokenizing, so no dynamic updates or anything, I'm afraid.
Hmm, that's a shame. I'm closing this issue.
I would like to hear your opinion about something like this though: https://atom.io/packages/language-javascript-semantic
language-javascript-semantic
hacks into Atom's internal grammar representation and runs an external tokenizer from there (acorn.js in this case). Then it uses token string hash to assign color to variable. It's not context-aware or anything like that. Source is still parsed line-by-line, with no backtracking. It's a neat hack, but doesn't really apply to Haskell.
That said, something like this could be possible with display layers in post, although that would require to parse whole source file (which isn't exactly fast, so would have to be done asynchronously). But that's an issue entirely separate from actual grammar definition.
Well yeah, but isn't this enough? When I say "identifiers in scope" I just mean things that are available from the imports. You must have a list of those somewhere to provide autocompletions. Couldn't the tokenizer just take the current token, check if it's in the list of imported identifiers and color it differently if it is?
Couldn't the tokenizer just take the current token, check if it's in the list of imported identifiers and color it differently if it is
Not unless I hack into Atom's internals and write my own streaming tokenizer for Haskell. Atom's grammar is just a declarative collection of regular expressions, basically. So no real state there.
Besides, collecting identifiers from imports is _slow_ -- you don't want to wait for that to highlight your code. And highlighter is synchronous, by the way, if you were wondering. Also it doesn't retokenize whole buffer if you changed one line (which is good, since large buffer could take seconds to retokenize)
Long story short, what you're describing is entirely orthogonal to actual grammar.
I understand. So there is a possibility of this being implemented as a package, but not as a part of the grammar. Thank you again for your work!
Let's just say this, when (if) Atom implements multiple text decoration layers, something like what you described will become viable (as a package). Right now, it's purely theoretical, since there's virtually no good way of hacking into highlighter. And highlighting parts of buffer with absolute divs sounds like a nightmare (although pigments does exactly that). And you're welcome.
I've played around a bit with Atom's internals, and here's what I came up with: https://atom.io/packages/language-haskell-scoped
Bear in mind that it's pretty hackish and basically of pre-alpha quality.
Man, I don't know what to say. This is some seriously amazing work. It works great!
These two declarations should be colored the same
Would it be possible to fix that?