Uh oh!
There was an error while loading. Please reload this page.
Syntax: Don't highlight the LHS of type decl as types - #81
Conversation
Julow
commented
Jul 19, 2022
Ping @Maelan |
Maelan
commented
Jul 19, 2022
Thanks @Julow! I’m fine either way. I’m just slightly concerned by adding complexity to that already complex piece, but I let our maintainers judge. You’d also have to deal with |
Uh oh!
There was an error while loading. Please reload this page.
| \ matchgroup=ocamlTypedef end="\<\(\w\|'\)*\>" | ||
| \ contains=@ocamlAllErrs,ocamlComment,ocamlTypeVariance,ocamlTypeVar | ||
| \ skipwhite skipempty | ||
| \ nextgroup=ocamlTypeDefImpl |
There was a problem hiding this comment.
I note that with this technique, there must be no comment (* *) between the defined type name and the equal sign =, which may be acceptable (we already have that limitation elsewhere).
There was a problem hiding this comment.
I don't see this. Perhaps because the end regex don't contain \@= ?
There was a problem hiding this comment.
I haven’t actually tested your code, but from what I understand about nextgroup= and contained, the ocamlTypeDefImpl group will never be tried except immediately after the end of the ocamlTypeDef group.
There was a problem hiding this comment.
This is what skipwhite is doing, from the :h:
These arguments are only used in combination with "nextgroup". They can be
used to allow the next group to match after skipping some text:
skipwhite skip over space and tab characters
skipnl skip over the end of a line
skipempty skip over empty lines (implies a "skipnl")
I took thought this was doing something between start and end and nothing outside but it's actually the opposite, they take effect after end and do nothing inside the region (whitespace are skipped by default it seems).
Julow
commented
Jul 20, 2022
copy
commented
Jul 20, 2022
Fundamentally this change is fine, but I think we leave the current behavior configurable (personally, I prefer the current behavior). This seems to break some things, in particular (from type-linter-test.ml): type('a, 'b) t = 'alist* ('a, 'b) result(* the left pair of parenthesis *)typenonrec 'a o = 'aoption=privateNone | Someof'a(* the second equal sign *)typet += Cofint(* the of *)The module-rec-and find is interesting, would you mind adding it to type-linter-test.ml with a fixme? |
Uh oh!
There was an error while loading. Please reload this page.
Julow
commented
Jul 21, 2022
I missed type-linter-test.ml, thanks. I've added a way to get back the current behavior, what should be the default ? This is governed by I've fixed the bugs with type params and equal signs but I introduced new bugs around let-bindings, which are matched as type decl. I would like |
I would expect 'ocamlTypeConstr' to apply only to type constructors within type expressions, not to the identifier after 'type' in: type foo = 'a bar list This makes the LHS of types, exceptions and constraints be matched as 'ocamlTypedef', which is not highlighted by default. Variance and type variables on the LHS remain highlighted as before.
Have stricter rules for the identifiers and allow exception constructors to be highlighted as before.
A new region is used to avoid matching the 'and' keyword too often (that would interfere with let-and and module-rec-and.
Fix tupled type params, += and whitespaces around keywords. Add examples to the test file.
Using the commit date instead of the author date.
Julow
commented
Jun 8, 2023
rgrinberg
commented
Jun 8, 2023
@copy do you want to make the call on this? |
copy
commented
Jun 9, 2023
This change and the mechanism to configure it looks good. However, it causes some problems with the highlighting of number literals (highlighted as error across the type-linter-test.ml file), the |
It's a `contained` region but was not added to `ocamlContained`.
This is a styling change.
Julow
commented
Jun 20, 2023
Thanks for the review! I fixed this issue, it was a missing |
copy
commented
Jun 26, 2023
Thanks! Super-minor, but it still removes the type highlighting from the following (on the int): typet (*c*) = int |
Julow
commented
Jun 27, 2023
Good catch! I'm failing to fix it. The |
copy
commented
Jun 27, 2023
This comment from @Maelan looks relevant: #81 (comment) |
Julow
commented
Jul 3, 2023
Sorry for the slow reply. I managed to handle the comment at this location while keeping |
copy
commented
Jul 4, 2023
The latest commit seems to have broken the highlighting of identifiers in some places (e.g. the |
It was missing from the ocamlTypeContained group.
Julow
commented
Jul 5, 2023
I think I managed to fix the identifier issue. The TOhtml diff seems fine now. The added |
copy
commented
Jul 6, 2023
On the last commit (817e8f7), some highlights are still incorrect (e.g. the |


I would expect
ocamlTypeConstrto apply only to type constructorswithin type expressions, not to the identifier after
typein:foois not highlighted with:This makes the LHS of types, exceptions and constraints be matched as
ocamlTypedef, which is not highlighted by default.Variance and type variables on the LHS remain highlighted as before.