From 617d7d7d484292d5d25abee0262eb9559cb428c1 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 6 May 2022 19:10:47 +0200 Subject: [PATCH 1/2] [OCaml] Fix infix operator definition Fixes #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. --- OCaml/OCaml.sublime-syntax | 7 +++++-- OCaml/syntax_test_ml.ml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/OCaml/OCaml.sublime-syntax b/OCaml/OCaml.sublime-syntax index 01c4a36824..f774cc7487 100644 --- a/OCaml/OCaml.sublime-syntax +++ b/OCaml/OCaml.sublime-syntax @@ -516,11 +516,14 @@ contexts: - 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*$ diff --git a/OCaml/syntax_test_ml.ml b/OCaml/syntax_test_ml.ml index e687498bcc..f3d8037dee 100644 --- a/OCaml/syntax_test_ml.ml +++ b/OCaml/syntax_test_ml.ml @@ -25,6 +25,37 @@ (*^^^ keyword.other.ocaml *) (* ^^^^ variable.other.constant.ocaml *) +(* Module Signatures *) + + val foo : 'a -> 'a +(*^^^^^^^^^^^^^^^^^^^^^ meta.module.signature.val.ocaml *) +(*^^^ keyword.other.ocaml *) +(* ^^^ entity.name.type.value-signature.ocaml *) +(* ^ punctuation.separator.type-constraint.ocaml *) +(* ^^ storage.type.ocaml *) +(* ^^ punctuation.separator.function-return.ocaml *) +(* ^^ storage.type.ocaml *) + + val (<*<) : 'a -> 'a +(*^^^^^^^^^^^^^^^^^^^^^ meta.module.signature.val.ocaml *) +(*^^^ keyword.other.ocaml *) +(* ^ punctuation.section.parens.begin.ocaml *) +(* ^^^ entity.name.type.value-signature.ocaml *) +(* ^ punctuation.section.parens.end.ocaml *) +(* ^ punctuation.separator.type-constraint.ocaml *) +(* ^^ storage.type.ocaml *) +(* ^^ punctuation.separator.function-return.ocaml *) +(* ^^ storage.type.ocaml *) + + val bar : 'a -> 'a +(*^^^^^^^^^^^^^^^^^^^^^ meta.module.signature.val.ocaml *) +(*^^^ keyword.other.ocaml *) +(* ^^^ entity.name.type.value-signature.ocaml *) +(* ^ punctuation.separator.type-constraint.ocaml *) +(* ^^ storage.type.ocaml *) +(* ^^ punctuation.separator.function-return.ocaml *) +(* ^^ storage.type.ocaml *) + (* Integers *) From 61dbdce0b99eabc6ee9553b3f181a374f3ce588c Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Fri, 6 May 2022 19:19:24 +0200 Subject: [PATCH 2/2] [OCaml] Add test to verify function definitions This commit adds a test to illustrate correct highlighting of function definitions. --- OCaml/syntax_test_ml.ml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OCaml/syntax_test_ml.ml b/OCaml/syntax_test_ml.ml index f3d8037dee..50ac2a87fb 100644 --- a/OCaml/syntax_test_ml.ml +++ b/OCaml/syntax_test_ml.ml @@ -1,5 +1,41 @@ (* SYNTAX TEST "Packages/OCaml/OCaml.sublime-syntax" *) +(* Function Definitions *) + +let foo = function +(* <- meta.function.ocaml keyword.other.function-definition.ocaml *) +(*^^^^^^^ meta.function.ocaml *) +(* ^^^ entity.name.function.ocaml *) +(* ^ keyword.operator.ocaml *) +(* ^^^^^^^^ keyword.control.match-definition.ocaml *) + | [] -> None +(* ^^^^^^^^ meta.pattern-match.ocaml *) +(* ^ keyword.control.match-definition.ocaml *) +(* ^^ constant.language.pseudo-variable.ocaml *) +(* ^^ punctuation.separator.match-definition.ocaml *) +(* ^^^^ entity.name.type.variant.ocaml *) + | _ -> Some 23 + +let bar = function +(* <- meta.function.ocaml keyword.other.function-definition.ocaml *) +(*^^^^^^^ meta.function.ocaml *) +(* ^^^ entity.name.function.ocaml *) +(* ^ keyword.operator.ocaml *) +(* ^^^^^^^^ keyword.control.match-definition.ocaml *) + | [] -> None +(* ^^^^^^^^ meta.pattern-match.ocaml *) +(* ^ keyword.control.match-definition.ocaml *) +(* ^^ constant.language.pseudo-variable.ocaml *) +(* ^^ punctuation.separator.match-definition.ocaml *) +(* ^^^^ entity.name.type.variant.ocaml *) + | _ -> Some 42 +(* ^^^^^^^ meta.pattern-match.ocaml *) +(* ^ keyword.control.match-definition.ocaml *) +(* ^ constant.language.universal-match.ocaml *) +(* ^^ punctuation.separator.match-definition.ocaml *) +(* ^^^^ entity.name.type.variant.ocaml *) +(* ^^ constant.numeric.value.ocaml *) + let open Core.Std (*^^^ keyword.other.ocaml *) (* ^^^^ keyword.control.import.ocaml *)