From a678b0356234bd5c4eb8de06f345ebda99d48554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 14:33:46 +0100 Subject: [PATCH 01/11] ocaml syntax: fix `module type of` inside `sig` --- syntax/ocaml.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 86ef182..69d280a 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -138,7 +138,7 @@ syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty -syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3 +syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\ssig\s\=" matchgroup=ocamlSigEncl end="\" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained @@ -160,7 +160,7 @@ syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT, syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlStructEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr " "module type" -syn region ocamlKeyword start="\" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef +syn region ocamlModTypeOf start="\" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod " Quoted strings @@ -603,6 +603,7 @@ hi def link ocamlEmptyConstructor ocamlConstructor hi def link ocamlVal Keyword hi def link ocamlModPreRHS Keyword hi def link ocamlMPRestr2 Keyword +hi def link ocamlModTypeOf Keyword hi def link ocamlKeyword Keyword hi def link ocamlMethod Include hi def link ocamlArrow Keyword From 39856d63c960017f1ed5488f525b1d9a6aab6200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 15:22:32 +0100 Subject: [PATCH 02/11] ocaml syntax: fix contained `functor` - do not require space before `functor` - do not match `functorx` as `functor x` For precedence reasons, `ocamlMPRestr2` must then be declared after `ocamlMPRestr3`. --- syntax/ocaml.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 69d280a..5c388ba 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -140,8 +140,8 @@ syn match ocamlGenMod "()" contained skipwhite skipempty syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\ssig\s\=" matchgroup=ocamlSigEncl end="\" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule -syn region ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained +syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val syn region ocamlVal matchgroup=ocamlKeyword start="\" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlMPRestr From c987f09951ef9877fb24a70ebe3645b2c2493b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 15:57:51 +0100 Subject: [PATCH 03/11] ocaml syntax: fix contained `sig` - do not require space before contained `sig` - do not match `sigx` as `sig x` For precedence reasons, `ocamlMPRestr1` must then be declared after `ocamlMPRestr3`. --- syntax/ocaml.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 5c388ba..6b7ea1a 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -139,8 +139,8 @@ syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf -syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\ssig\s\=" matchgroup=ocamlSigEncl end="\" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained +syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val From a7eec518390ad0d47de862cf5e04c86d57040520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 16:29:02 +0100 Subject: [PATCH 04/11] ocaml syntax: dedup ocamlSig / ocamlMPRestr1 for precedence reasons, ocamlSig must be declared after ocamlMPRestr3 --- syntax/ocaml.vim | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 6b7ea1a..8a8dc96 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -77,7 +77,7 @@ syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\>" syn cluster ocamlAllErrs contains=@ocamlAENoParen,ocamlParenErr syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr,ocamlKwErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -121,10 +121,6 @@ syn region ocamlPpx matchgroup=ocamlPpxEncl start="\[@\{1,3\}" contains=TOP end= "" Modules -" "sig" -syn region ocamlSig matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule -syn region ocamlModSpec matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr - " "open" syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlFullMod @@ -132,15 +128,15 @@ syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlFullMod syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod " "module" - somewhat complicated stuff ;-) +syn region ocamlModSpec matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr syn region ocamlModule matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|=\|)"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod,ocamlModParam,ocamlModParam1,ocamlSig,ocamlVal syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty -syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf +syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlSig,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained -syn region ocamlMPRestr1 matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val @@ -159,6 +155,9 @@ syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT, " "struct" syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlStructEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr +" "sig" +syn region ocamlSig matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule + " "module type" syn region ocamlModTypeOf start="\" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod From 175ed43f81371ff5cac2dc2e3d8b5f7c75b7caf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 16:55:31 +0100 Subject: [PATCH 05/11] ocaml syntax: dedup ocamlStruct / ocamlFuncStruct also, minor fix: do not require a character before `struct` when nested in parentheses; this fixes the following example: open F( struct end ) --- syntax/ocaml.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 8a8dc96..129039e 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -77,7 +77,7 @@ syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\>" syn cluster ocamlAllErrs contains=@ocamlAENoParen,ocamlParenErr syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr,ocamlKwErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -144,8 +144,7 @@ syn region ocamlVal matchgroup=ocamlKeyword start="\" matchgroup=ocamlLC syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlFuncStruct matchgroup=ocamlStructEncl start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlStructEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr +syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=ocamlComment,ocamlWith,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith From 524c5407d086ef7d22b981c5210ffbb3b5dfaa9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 18:30:14 +0100 Subject: [PATCH 06/11] ocaml syntax: dedup ocamlMPRestr3 / ocamlModTypeRestr (but what is that for?) --- syntax/ocaml.vim | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 129039e..a8ea36a 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -77,7 +77,7 @@ syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\>" syn cluster ocamlAllErrs contains=@ocamlAENoParen,ocamlParenErr syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr,ocamlKwErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -135,8 +135,8 @@ syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty -syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlSig,ocamlMPRestr2,ocamlMPRestr3,ocamlModTypeOf -syn match ocamlMPRestr3 "\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*" contained +syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlSig,ocamlMPRestr2,ocamlModTypeRestr,ocamlModTypeOf +syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val @@ -146,7 +146,6 @@ syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skip syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=ocamlComment,ocamlWith,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith -syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained @@ -583,7 +582,6 @@ hi def link ocamlModule Include hi def link ocamlModParam1 Include hi def link ocamlGenMod Include hi def link ocamlModType Include -hi def link ocamlMPRestr3 Include hi def link ocamlFullMod Include hi def link ocamlFuncWith Include hi def link ocamlModParam Include From 60e70f465f6cdc14faae12fffb914bfff89380fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 21:57:57 +0100 Subject: [PATCH 07/11] ocaml syntax: fix a bug in the highlighting of comments --- syntax/ocaml.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index a8ea36a..7216a73 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -146,7 +146,7 @@ syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skip syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=ocamlComment,ocamlWith,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith +syn region ocamlModTRWith start=":\s*(\*\@!"hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained From 4f399410ad94bc8dffb697616cc6c8f94d77212a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 22:08:19 +0100 Subject: [PATCH 08/11] ocaml syntax: fix linting of `functor` and functor params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `module` keyword is now treated uniformly. Previously, it was matched differently in signatures (matchgroup `ocamlModSpec`) than elsewhere (matchgroup `ocamlModule`). Both cases have almost identical syntax: (* in signatures: *) module M (X1 : T1) … (Xn: Tn) : MODULE TYPE (* in structures: *) module M (X1 : T1) … (Xn: Tn) [: MODULE TYPE] = MODULE DEF The case distinction was not taking profit of the small difference in syntax, and it was creating complexity and mismatch between both cases. Each case had shortcomings. In signatures, functor parameters like this where not highlighted corrrectly: (* in signatures: *) module M (X1 : T1) : … Also, the only case where the `functor` keyword was highlighted correctly was in a `module` type annotation *in a signature*. It was not highlighted correctly in `module` type annotations *in structures*, nor in `module` definitions, nor in `module type` definitions. (* in signatures: *) module type T = functor (X1 : T1) -> … module M : functor (X1 : T1) -> … (* the only case that was working *) (* in structures: *) module type T = functor (X1 : T1) -> … module M : functor (X1 : T1) -> … = … module M = functor (X1 : T1) -> … These bugs are now fixed. The `ocamlModule` matchgroup subsumes the features of both former cases (`module` in signatures / in structures). The `functor` keyword is no more "contained", so that it now matches in all of the 5 situations above. --- syntax/ocaml.vim | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 7216a73..34118df 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -77,7 +77,7 @@ syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\>" syn cluster ocamlAllErrs contains=@ocamlAENoParen,ocamlParenErr syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr,ocamlKwErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlMPRestr2,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -128,16 +128,14 @@ syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlFullMod syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod " "module" - somewhat complicated stuff ;-) -syn region ocamlModSpec matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr syn region ocamlModule matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef -syn region ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|=\|)"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS +syn region ocamlPreDef start="."me=e-1 end="[a-z:=)]\@=" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup=ocamlMPRestr,ocamlModPreRHS syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod,ocamlModParam,ocamlModParam1,ocamlSig,ocamlVal syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty -syn region ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlSig,ocamlMPRestr2,ocamlModTypeRestr,ocamlModTypeOf +syn match ocamlMPRestr ":" contained skipwhite skipempty nextgroup=ocamlModTRWith,ocamlSig,ocamlMPRestr2,ocamlModTypeRestr,ocamlModTypeOf syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained -syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2 syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val syn region ocamlVal matchgroup=ocamlKeyword start="\" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlMPRestr @@ -146,7 +144,7 @@ syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skip syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=ocamlComment,ocamlWith,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith -syn region ocamlModTRWith start=":\s*(\*\@!"hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith +syn region ocamlModTRWith start="(\*\@!" end=")" contained contains=@ocamlAENoParen,ocamlWith syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained @@ -154,7 +152,10 @@ syn region ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT, syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=struct\>" matchgroup=ocamlStructEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr " "sig" -syn region ocamlSig matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule +syn region ocamlSig matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr + +" "functor" +syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlStruct,ocamlSig,ocamlFuncWith,ocamlMPRestr2 " "module type" syn region ocamlModTypeOf start="\" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef From 72cf1d6188752b90a7e393ba6f168a0b273812be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 22:52:08 +0100 Subject: [PATCH 09/11] ocaml syntax: rename some matchgroups relating to modules (those I could make sense of) --- syntax/ocaml.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 34118df..6b9a96e 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -77,7 +77,7 @@ syn match ocamlKwErr "\<\(mutable\|nonrec\|of\|private\)\>" syn cluster ocamlAllErrs contains=@ocamlAENoParen,ocamlParenErr syn cluster ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr,ocamlKwErr -syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlMPRestr,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod,ocamlVal +syn cluster ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlModTypePre,ocamlModRHS,ocamlFuncWith,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlFullMod,ocamlVal " Enclosing delimiters @@ -129,16 +129,17 @@ syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlModPa " "module" - somewhat complicated stuff ;-) syn region ocamlModule matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef -syn region ocamlPreDef start="."me=e-1 end="[a-z:=)]\@=" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup=ocamlMPRestr,ocamlModPreRHS +syn region ocamlPreDef start="."me=e-1 end="[a-z:=)]\@=" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup=ocamlModTypePre,ocamlModPreRHS syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod,ocamlModParam,ocamlModParam1,ocamlSig,ocamlVal syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty syn match ocamlGenMod "()" contained skipwhite skipempty -syn match ocamlMPRestr ":" contained skipwhite skipempty nextgroup=ocamlModTRWith,ocamlSig,ocamlMPRestr2,ocamlModTypeRestr,ocamlModTypeOf +syn match ocamlModTypePre ":" contained skipwhite skipempty nextgroup=ocamlModTRWith,ocamlSig,ocamlFunctor,ocamlModTypeRestr,ocamlModTypeOf syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contained + syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn keyword ocamlKeyword val -syn region ocamlVal matchgroup=ocamlKeyword start="\" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlMPRestr +syn region ocamlVal matchgroup=ocamlKeyword start="\" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment,ocamlFullMod skipwhite skipempty nextgroup=ocamlModTypePre syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod syn match ocamlFullMod "\<\u\(\w\|'\)*\( *\. *\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith @@ -155,7 +156,7 @@ syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=str syn region ocamlSig matchgroup=ocamlSigEncl start="\" matchgroup=ocamlSigEncl end="\" contains=ALLBUT,@ocamlContained,ocamlEndErr " "functor" -syn region ocamlMPRestr2 start="\" matchgroup=ocamlKeyword end="->" contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlStruct,ocamlSig,ocamlFuncWith,ocamlMPRestr2 +syn region ocamlFunctor start="\" matchgroup=ocamlKeyword end="->" contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlStruct,ocamlSig,ocamlFuncWith,ocamlFunctor " "module type" syn region ocamlModTypeOf start="\" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef @@ -582,7 +583,6 @@ hi def link ocamlObject Include hi def link ocamlModule Include hi def link ocamlModParam1 Include hi def link ocamlGenMod Include -hi def link ocamlModType Include hi def link ocamlFullMod Include hi def link ocamlFuncWith Include hi def link ocamlModParam Include @@ -599,7 +599,7 @@ hi def link ocamlEmptyConstructor ocamlConstructor hi def link ocamlVal Keyword hi def link ocamlModPreRHS Keyword -hi def link ocamlMPRestr2 Keyword +hi def link ocamlFunctor Keyword hi def link ocamlModTypeOf Keyword hi def link ocamlKeyword Keyword hi def link ocamlMethod Include From 577635a52e441faafa18b9ddc13c703b5edc7d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 23:00:31 +0100 Subject: [PATCH 10/11] ocaml syntax: highlight ':' for module types --- syntax/ocaml.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index 6b9a96e..c2e0a63 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -598,6 +598,7 @@ hi def link ocamlConstructor Constant hi def link ocamlEmptyConstructor ocamlConstructor hi def link ocamlVal Keyword +hi def link ocamlModTypePre Keyword hi def link ocamlModPreRHS Keyword hi def link ocamlFunctor Keyword hi def link ocamlModTypeOf Keyword From 0676496263de5a4e116166b3c592d14be3ee5ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 1 Nov 2022 23:43:05 +0100 Subject: [PATCH 11/11] request clarification --- syntax/ocaml.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax/ocaml.vim b/syntax/ocaml.vim index c2e0a63..c4bec3a 100644 --- a/syntax/ocaml.vim +++ b/syntax/ocaml.vim @@ -128,6 +128,7 @@ syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlFullMod syn match ocamlKeyword "\" skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod " "module" - somewhat complicated stuff ;-) +" 2022-10: please document it? syn region ocamlModule matchgroup=ocamlKeyword start="\" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef syn region ocamlPreDef start="."me=e-1 end="[a-z:=)]\@=" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup=ocamlModTypePre,ocamlModPreRHS syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod,ocamlModParam,ocamlModParam1,ocamlSig,ocamlVal