banacorn / language-agda

Agda language support for the Atom editor
https://atom.io/packages/language-agda
MIT License
13 stars 5 forks source link

syntax color assignment #28

Open pnlph opened 4 years ago

pnlph commented 4 years ago

I am intrigued by how the colors of the syntax highlight are chosen and and how they are assigned a meaning. Where could I find this connection in the code/documentation?

From what I see:

Blue and yellow items are only colored when declared, not when used further in code.

Did you follow some kind of standard/convention you can point me to?

banacorn commented 4 years ago

The best "documentation" I can find is the color scheme defined by the syntax theme, for example, in one dark

From there, you can see how colors are assigned to the "selectors" in the theme:

  &.syntax--function  {
    color: @hue-1;

    &.syntax--any-method {
      color: @hue-2;
    }
  }

We assign the "syntax node" that we've parsed to those "selectors"

https://github.com/banacorn/language-agda/blob/5b2275b47fbf79a5b4722b719e6e8e3c77aea0b4/grammars/tree-sitter-agda.cson#L99-L104

We can't really decide the color because it depends on which kind of syntax theme you use. The best we can do is to match the semantics of the selectors.

Blue and yellow items are only colored when declared, not when used further in code.

They are not colored further in the code because they belong to different syntax node.

banacorn commented 4 years ago

Actually the current coloring rules is a mess. I've no idea which selectors are available before I discovered the secrets of syntax themes. It can use some love and update.

pnlph commented 4 years ago

I think the link moved to the one dark syntax theme package in the core Atom repository.

I will take a look at it.

pnlph commented 4 years ago

For example with the one dark theme i see the upper and lowe liner white (mono-1) and the comment itself gray (mono-3)

-------------------------
-- Strings of parentheses
-------------------------

I guess then, in this case the syntax node only detects the comments starting with two hyphens and then a space. Is it defined here? https://github.com/banacorn/language-agda/blob/5b2275b47fbf79a5b4722b719e6e8e3c77aea0b4/grammars/agda.cson#L152

banacorn commented 4 years ago

The file you are referring to is the old way of syntax highlighting (using regular expressions).

Now we use tree-sitter-agda for parsing and Agda files: https://github.com/tree-sitter/tree-sitter-agda/blob/d710ff14d15ddee3764fd73a0837c6c4c8c913e9/grammar.js#L891-L903