Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OCaml] Distorted syntax highlighting on pattern match via function keyword #1756

Open
m-schmidt opened this issue Oct 25, 2018 · 2 comments · May be fixed by #3371
Open

[OCaml] Distorted syntax highlighting on pattern match via function keyword #1756

m-schmidt opened this issue Oct 25, 2018 · 2 comments · May be fixed by #3371
Labels
C: Syntax T: bug A bug in an existing language feature

Comments

@m-schmidt
Copy link

m-schmidt commented Oct 25, 2018

Syntax highlighting for the following OCaml snippet is broken in the current version of SublimeText. The problem is, that the first function foo is not properly detected. Therefore the let of the following function definition is recognised as a variable instead of a keyword:

let foo = function
    | [] -> None
    | _  -> Some 23

let bar = function
    | [] -> None
    | _  -> Some 42
@m-schmidt
Copy link
Author

m-schmidt commented Oct 25, 2018

Furthermore, the following signature for an infix function named <*< is not recognised (e.g. in an .mli file):

val foo   : 'a -> 'a

val (<*<) : 'a -> 'a

val bar   : 'a -> 'a

@keith-hall
Copy link
Collaborator

I don't know OCaml at all, but you may be able to fix it with:

--- Shipped Packages/OCaml/OCaml.sublime-syntax 2018-10-11 19:11:54
+++ Packages/OCaml/OCaml.sublime-syntax 2018-10-26 09:28:16
@@ -444,11 +444,14 @@
     - include: variables
     - include: main
   module-signature:
-    - match: '(val)\s+([a-z_][a-zA-Z0-9_'']*)\s*(:)'
+    - match: '(val)\s+(?:([a-z_][a-zA-Z0-9_'']*)|(\()([^\s)]+)(\)))\s*(:)'
       captures:
         1: keyword.other.ocaml
         2: entity.name.type.value-signature.ocaml
-        3: punctuation.separator.type-constraint.ocaml
+        3: punctuation.section.parens.begin.ocaml
+        4: entity.name.type.value-signature.ocaml
+        5: punctuation.section.parens.end.ocaml
+        6: punctuation.separator.type-constraint.ocaml
       push:
         - meta_scope: meta.module.signature.val.ocaml
         - match: (?=\b(type|val|external|class|module|end)\b)|^\s*$
@@ -557,6 +560,8 @@
     - match: \|
       scope: punctuation.separator.algebraic-type.ocaml
   variables:
+    - match: (?=\blet\b)
+      pop: true
     - match: \(\)
       scope: variable.parameter.unit.ocaml
     - include: constants

deathaxe added a commit to deathaxe/sublime-packages that referenced this issue May 6, 2022
Fixes sublimehq#1756

This commit partly applies the proposed change of the mentioned issue
to fix infix operator definitions as it seems safe enough not to break
something.
@deathaxe deathaxe linked a pull request May 6, 2022 that will close this issue
@deathaxe deathaxe added T: bug A bug in an existing language feature C: Syntax labels Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Syntax T: bug A bug in an existing language feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants