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

Add OCamldoc/Odoc highlighting #106

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions doc/ocaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ highlighted. You can turn on highlighting of operators by defining:

let g:ocaml_highlight_operators = 1

*g:odoc_html_support*

By default HTML code inlined in OCamldoc/Odoc syntax is not highlighted to
avoid loading the HTML syntax. You can turn on HTML highlighting by defining:

let g:odoc_html_support = 1

*g:ocaml_compiler_compact_messages*

By default the output of the OCaml compiler is filtered to keep only the
Expand Down
1 change: 1 addition & 0 deletions ftdetect/odoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
au BufNewFile,BufRead *.mld setf odoc
72 changes: 45 additions & 27 deletions syntax/ocaml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
" Issac Trotts <ijtrotts@ucdavis.edu>
" URL: https://github.com/ocaml/vim-ocaml
" Last Change:
" 2024 Jan 25 - Add OCamldoc/Odoc highlighting (Samuel Hym, Nicolas Osborne)
" 2019 Nov 05 - Accurate type highlighting (Maëlan)
" 2018 Nov 08 - Improved highlighting of operators (Maëlan)
" 2018 Apr 22 - Improved support for PPX (Andrey Popp)
Expand Down Expand Up @@ -86,11 +87,21 @@ syn region ocamlNone transparent matchgroup=ocamlEncl start="{" matchgroup=oca
syn region ocamlNone transparent matchgroup=ocamlEncl start="\[" matchgroup=ocamlEncl end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
syn region ocamlNone transparent matchgroup=ocamlEncl start="\[|" matchgroup=ocamlEncl end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr


" Comments
syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
" Comments and documentation
syn keyword ocamlTodo contained TODO FIXME XXX NOTE

syn cluster ocamlCommentLike contains=ocamlComment,ocamlCommentInDoc,ocamlDocumentation,ocamlStopComment

if !exists('odoc_syntax_loading')
" Load odoc syntax only when we are not in a *.mld file
syn region ocamlComment start="(\*" end="\*)" contains=@Spell,ocamlComment,ocamlTodo
syn include @ocamlOdoc syntax/odoc.vim
syn region ocamlDocumentation matchgroup=ocamlDocEncl start="(\*\*[*)]\@!" end="\*)" contains=@ocamlOdoc,ocamlCommentInDoc,@Spell,ocamlTodo
else
syn region ocamlCommentInDoc start="(\*" end="\*)" contains=@Spell,ocamlTodo,ocamlCommentInDoc
n-osborne marked this conversation as resolved.
Show resolved Hide resolved
endif

syn match ocamlStopComment "(\*\*/\*\*)"

" Objects
syn region ocamlEnd matchgroup=ocamlObject start="\<object\>" matchgroup=ocamlObject end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
Expand Down Expand Up @@ -129,9 +140,9 @@ syn match ocamlKeyword "\<include\>" skipwhite skipempty nextgroup=ocamlModPa

" "module" - somewhat complicated stuff ;-)
" 2022-10: please document it?
syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" 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
syn region ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<_\|\u\(\w\|'\)*\>" contains=@ocamlAllErrs,@ocamlCommentLike skipwhite skipempty nextgroup=ocamlPreDef
syn region ocamlPreDef start="."me=e-1 end="[a-z:=)]\@=" contained contains=@ocamlAllErrs,@ocamlCommentLike,ocamlModParam,ocamlGenMod,ocamlModTypeRestr nextgroup=ocamlModTypePre,ocamlModPreRHS
syn region ocamlModParam start="(\*\@!" end=")" contained contains=ocamlGenMod,ocamlModParam1,ocamlSig,ocamlVal
syn match ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty
syn match ocamlGenMod "()" contained skipwhite skipempty

Expand All @@ -140,11 +151,11 @@ syn match ocamlModTypeRestr "\<\w\(\w\|'\)*\( *\. *\w\(\w\|'\)*\)*\>" contain

syn match ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
syn keyword ocamlKeyword val
syn region ocamlVal matchgroup=ocamlKeyword start="\<val\>" 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 region ocamlVal matchgroup=ocamlKeyword start="\<val\>" matchgroup=ocamlLCIdentifier end="\<\l\(\w\|'\)*\>" contains=@ocamlAllErrs,@ocamlCommentLike,ocamlFullMod skipwhite skipempty nextgroup=ocamlModTypePre
syn region ocamlModRHS start="." end=". *\w\|([^*]"me=e-2 contained contains=@ocamlCommentLike 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,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith
syn region ocamlFuncWith start="([*)]\@!" end=")" contained contains=@ocamlCommentLike,ocamlWith,ocamlStruct skipwhite skipempty nextgroup=ocamlFuncWith

syn region ocamlModTRWith start="(\*\@!" end=")" contained contains=@ocamlAENoParen,ocamlWith
syn match ocamlWith "\<\(\u\(\w\|'\)* *\. *\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
Expand All @@ -157,10 +168,10 @@ syn region ocamlStruct matchgroup=ocamlStructEncl start="\<\(module\s\+\)\=str
syn region ocamlSig matchgroup=ocamlSigEncl start="\<sig\>" matchgroup=ocamlSigEncl end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr

" "functor"
syn region ocamlFunctor start="\<functor\>" matchgroup=ocamlKeyword end="->" contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlStruct,ocamlSig,ocamlFuncWith,ocamlFunctor
syn region ocamlFunctor start="\<functor\>" matchgroup=ocamlKeyword end="->" contains=@ocamlAllErrs,@ocamlCommentLike,ocamlModParam,ocamlGenMod skipwhite skipempty nextgroup=ocamlStruct,ocamlSig,ocamlFuncWith,ocamlFunctor

" "module type"
syn region ocamlModTypeOf start="\<module\s\+type\(\s\+of\)\=\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
syn region ocamlModTypeOf start="\<module\s\+type\(\s\+of\)\=\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=@ocamlCommentLike skipwhite skipempty nextgroup=ocamlMTDef
syn match ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s+1 skipwhite skipempty nextgroup=ocamlFullMod

" Quoted strings
Expand Down Expand Up @@ -323,7 +334,7 @@ syn cluster ocamlTypeExpr add=ocamlTypeParen
syn region ocamlTypeParen contained transparent
\ matchgroup=ocamlEncl start="(\*\@!"
\ matchgroup=ocamlEncl end=")"
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,@ocamlCommentLike,ocamlPpx

syn cluster ocamlTypeExpr add=ocamlTypeKeyChar,ocamlTypeAs
syn match ocamlTypeKeyChar contained "->"
Expand Down Expand Up @@ -386,7 +397,7 @@ syn cluster ocamlTypeExpr add=ocamlTypeObject
syn region ocamlTypeObject contained
n-osborne marked this conversation as resolved.
Show resolved Hide resolved
\ matchgroup=ocamlEncl start="<"
\ matchgroup=ocamlEncl end=">"
\ contains=ocamlTypeObjectDots,ocamlLCIdentifier,ocamlTypeObjectAnnot,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeObjectDots,ocamlLCIdentifier,ocamlTypeObjectAnnot,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeObject ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypeObjectDots
syn match ocamlTypeObjectDots contained "\.\."
Expand All @@ -395,15 +406,15 @@ syn cluster ocamlTypeContained add=ocamlTypeObjectAnnot
syn region ocamlTypeObjectAnnot contained
\ matchgroup=ocamlKeyChar start=":"
\ matchgroup=ocamlKeyChar end=";\|>\@="
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeObjectAnnot ocamlTypeCatchAll

" Record type definition
syn cluster ocamlTypeContained add=ocamlTypeRecordDecl
syn region ocamlTypeRecordDecl contained
\ matchgroup=ocamlEncl start="{"
\ matchgroup=ocamlEncl end="}"
\ contains=ocamlTypeMutable,ocamlLCIdentifier,ocamlTypeRecordAnnot,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeMutable,ocamlLCIdentifier,ocamlTypeRecordAnnot,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeRecordDecl ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypeMutable
syn keyword ocamlTypeMutable contained mutable
Expand All @@ -412,7 +423,7 @@ syn cluster ocamlTypeContained add=ocamlTypeRecordAnnot
syn region ocamlTypeRecordAnnot contained
\ matchgroup=ocamlKeyChar start=":"
\ matchgroup=ocamlKeyChar end=";\|}\@="
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeRecordAnnot ocamlTypeCatchAll

" Polymorphic variant types
Expand All @@ -421,7 +432,7 @@ syn cluster ocamlTypeExpr add=ocamlTypeVariant
syn region ocamlTypeVariant contained
\ matchgroup=ocamlEncl start="\[>" start="\[<" start="\[@\@!"
\ matchgroup=ocamlEncl end="\]"
\ contains=ocamlTypeVariantKeyChar,ocamlTypeVariantConstr,ocamlTypeVariantAnnot,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeVariantKeyChar,ocamlTypeVariantConstr,ocamlTypeVariantAnnot,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeVariant ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypeVariantKeyChar
syn match ocamlTypeVariantKeyChar contained "|"
Expand All @@ -434,7 +445,7 @@ syn cluster ocamlTypeContained add=ocamlTypeVariantAnnot
syn region ocamlTypeVariantAnnot contained
\ matchgroup=ocamlKeyword start="\<of\>"
\ matchgroup=ocamlKeyChar end="|\|>\|\]\@="
\ contains=@ocamlTypeExpr,ocamlTypeAmp,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,ocamlTypeAmp,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeVariantAnnot ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypeAmp
syn match ocamlTypeAmp contained "&"
Expand All @@ -449,7 +460,7 @@ syn region ocamlTypeSumDecl contained
\ matchgroup=ocamlTypeSumConstr start="(\_s*)" start="\[\_s*]" start="(\_s*::\_s*)"
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\|=\)\@="
\ matchgroup=NONE end="\(\<and\>\)\@="
\ contains=ocamlTypeSumBar,ocamlTypeSumConstr,ocamlTypeSumAnnot,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeSumBar,ocamlTypeSumConstr,ocamlTypeSumAnnot,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeSumDecl ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypeSumBar
syn match ocamlTypeSumBar contained "|"
Expand All @@ -469,15 +480,15 @@ syn region ocamlTypeSumAnnot contained
\ matchgroup=NONE end="|\@="
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
\ matchgroup=NONE end="\(\<and\>\)\@="
\ contains=@ocamlTypeExpr,ocamlTypeRecordDecl,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,ocamlTypeRecordDecl,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeSumAnnot ocamlTypeCatchAll

" Type context opened by “type” (type definition), “constraint” (type
" constraint) and “exception” (exception definition)
syn region ocamlTypeDef
\ matchgroup=ocamlKeyword start="\<type\>\(\_s\+\<nonrec\>\)\?\|\<constraint\>\|\<exception\>"
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
\ contains=@ocamlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,ocamlTypeEq,ocamlTypePrivate,ocamlTypeDefDots,ocamlTypeRecordDecl,ocamlTypeSumDecl,ocamlTypeDefAnd,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeDef ocamlTypeCatchAll
syn cluster ocamlTypeContained add=ocamlTypePrivate
syn keyword ocamlTypePrivate contained private
Expand All @@ -503,7 +514,7 @@ syn region ocamlTypeAnnot matchgroup=ocamlKeyChar start=":\(>\|\_s*type\>\|[>:=]
\ matchgroup=NONE end="\(\<type\>\|\<exception\>\|\<val\>\|\<module\>\|\<class\>\|\<method\>\|\<constraint\>\|\<inherit\>\|\<object\>\|\<struct\>\|\<open\>\|\<include\>\|\<let\>\|\<external\>\|\<in\>\|\<end\>\|)\|]\|}\|;\|;;\)\@="
\ matchgroup=NONE end="\(;\|}\)\@="
\ matchgroup=NONE end="\(=\|:>\)\@="
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeAnnot ocamlTypeCatchAll

" Type annotation that gives the return type of a `fun` keyword
Expand All @@ -512,7 +523,7 @@ syn cluster ocamlTypeContained add=ocamlFunTypeAnnot
syn region ocamlFunTypeAnnot contained containedin=ocamlFun
\ matchgroup=ocamlKeyChar start=":"
\ matchgroup=NONE end="\(->\)\@="
\ contains=@ocamlTypeExpr,ocamlComment,ocamlPpx
\ contains=@ocamlTypeExpr,@ocamlCommentLike,ocamlPpx
hi link ocamlFunTypeAnnot ocamlTypeCatchAll

" Module paths (including functors) in types.
Expand All @@ -525,14 +536,14 @@ syn match ocamlTypeModPath contained "\<\u\(\w\|'\)*\_s*\."
syn region ocamlTypeModPath contained transparent
\ matchgroup=ocamlModPath start="\<\u\(\w\|'\)*\_s*(\*\@!"
\ matchgroup=ocamlModPath end=")\_s*\."
\ contains=ocamlTypeDotlessModPath,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeDotlessModPath,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeModPath ocamlModPath
syn cluster ocamlTypeContained add=ocamlTypeDotlessModPath
syn match ocamlTypeDotlessModPath contained "\<\u\(\w\|'\)*\_s*\.\?"
syn region ocamlTypeDotlessModPath contained transparent
\ matchgroup=ocamlModPath start="\<\u\(\w\|'\)*\_s*(\*\@!"
\ matchgroup=ocamlModPath end=")\_s*\.\?"
\ contains=ocamlTypeDotlessModPath,ocamlTypeBlank,ocamlComment,ocamlPpx
\ contains=ocamlTypeDotlessModPath,ocamlTypeBlank,@ocamlCommentLike,ocamlPpx
hi link ocamlTypeDotlessModPath ocamlTypeModPath

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Expand Down Expand Up @@ -577,6 +588,9 @@ hi def link ocamlCharErr Error
hi def link ocamlErr Error

hi def link ocamlComment Comment
hi def link ocamlDocEncl ocamlComment
hi def link ocamlCommentInDoc ocamlComment
hi def link ocamlStopComment PreProc
hi def link ocamlShebang ocamlComment

hi def link ocamlModPath Include
Expand Down Expand Up @@ -662,7 +676,11 @@ hi def link ocamlPpxEncl ocamlEncl

let b:current_syntax = "ocaml"

let &cpo = s:keepcpo
unlet s:keepcpo
" Because of the nesting (ocaml in odoc in ocaml), s:keepcpo might have been
" unlet already
if exists('s:keepcpo')
let &cpo = s:keepcpo
unlet s:keepcpo
endif

" vim: ts=8
109 changes: 109 additions & 0 deletions syntax/odoc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
" Vim syntax file
" Language: Odoc/OCamldoc
" Filenames: *.mld
" Maintainers: Samuel Hym
" Nicolas Osborne
" URL: https://github.com/ocaml/vim-ocaml
n-osborne marked this conversation as resolved.
Show resolved Hide resolved
" Last Change:
" 2024 Jan 26 - initial version

" Quit when a syntax file was already loaded
if !exists("odoc_syntax_loading")
if exists("b:current_syntax")
finish
endif
let odoc_syntax_loading = 1
endif

let s:keepcpo = &cpo
set cpo&vim

syn spell toplevel

syn case match

syn include @odocSyntaxOCaml syntax/ocaml.vim
unlet b:current_syntax

n-osborne marked this conversation as resolved.
Show resolved Hide resolved
syn cluster odocInline contains=odocBold,odocItalic,odocEmphasis,odocMiscInline,odocList,odocLinkText,odocUrl,odocCrossref,odocCode,odocCodeBlock,odocVerbatim,odocTargetSpecific,odocTag,odocEscaped,odocEscapedError,odocBraceError,odocTagError

syn match odocBraceError "[{}]"

syn region odocLinkText transparent matchgroup=odocMarker start="{\%({[!:]\)\@=" end="}" contains=odocUrl,odocCrossref,@Spell,@odocInline
syn region odocUrl matchgroup=odocUrlMarker start="{:\_s*" end="\_s*}"
" a bit leniant with ":"
syn match odocCrossrefKw contained "\<\%(!modules\|module\%(-type\)\?\|class\%(-type\)\?\|val\|type\|exception\|method\|constructor\|extension\|extension-decl\|field\|instance-variable\|section\|page\)[-:]"
syn match odocCrossrefKwDeprecated contained "\<\%(modtype\|classtype\|value\|exn\|const\|label\)[-:]"
syn region odocCrossref matchgroup=odocCrossrefMarker start="{!" end="}" contains=odocCrossrefKw,odocCrossrefKwDeprecated

syn region odocBold matchgroup=odocMarker start="{b\>" end="}" contains=@Spell,@odocInline
syn region odocEmphasis matchgroup=odocMarker start="{e\>" end="}" contains=@Spell,@odocInline
syn region odocItalic matchgroup=odocMarker start="{i\>" end="}" contains=@Spell,@odocInline
syn region odocMiscInline matchgroup=odocMarker start="{[CLR^_]" end="}" contains=@Spell,@odocInline
syn region odocVerbatim matchgroup=odocMarker start="{v\>" end="\<v}"

n-osborne marked this conversation as resolved.
Show resolved Hide resolved
syn region odocTargetSpecific matchgroup=odocUnknownTarget start="{%.\{-}:\|{%" end="%}"

if get(g:,'odoc_html_support',0)
syn include @odocHtml syntax/html.vim
unlet b:current_syntax
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@odocHtml
else
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@Spell
endif

syn region odocDyckWord contained transparent start="{" end="}" contains=odocDyckWord
syn region odocTargetSpecific matchgroup=odocMarker start="{m\%(ath\)\?\>" end="}" contains=odocDyckWord
syn region odocTargetSpecific matchgroup=odocMarker start="{%\%(latex\|texi\|man\):" end="%}"
syn region odocHeading start="{[0-5]\%(\s\|$\|:\)\@=" end="}" contains=@Spell,odocHeadingLabel
syn match odocHeadingLabel contained "\%({[0-5]\)\@<=:[^ \t:]*"
syn region odocTable transparent matchgroup=odocMarker start="{t\>" end="}" contains=@Spell,@odocInline
syn region odocTable transparent matchgroup=odocMarker start="{table\>" end="}" contains=odocTableRow
syn region odocTableRow transparent matchgroup=odocMarker start="{tr\>" end="}" contains=odocTableEntry contained
syn region odocTableEntry transparent matchgroup=odocMarker start="{t[dh]\>" end="}" contains=@Spell,@odocInline contained
syn match odocEscapedBracket contained "\\[][]"
syn region odocBalancedBracket contained transparent start="\[" end="]"
syn region odocCode matchgroup=odocMarker start="\[" end="\]" contains=odocBalancedBracket,odocEscapedBracket
syn region odocCodeBlock matchgroup=odocMarker start="{@[^\[]\+\[" end="\]}"
syn region odocCodeBlock matchgroup=odocMarker start="{\%(@ocaml\%(\_s[^\[]*\)\?\)\?\[" end="\]}" contains=@odocSyntaxOCaml
syn match odocListMarker "^\s*[-+]\s"
syn region odocListItem contained transparent matchgroup=odocListMarker start="{\%(-\|li\>\)" end="}" contains=@Spell,@odocInline
syn region odocList transparent matchgroup=odocListMarker start="{[ou]l\>" end="}" contains=odocListItem
syn match odocTagError "@[a-zA-Z]*"
syn match odocTag "@\%(author\|deprecated\|param\|raises\?\|returns\?\|see\|since\|before\|version\|open\|closed\|inline\|canonical\)\>"

syn match odocEscapedError "\\."
syn match odocEscaped "\\[][{}@\\]"

n-osborne marked this conversation as resolved.
Show resolved Hide resolved
" Shamelessly borrowed from HTML syntax
hi def odocBold term=bold cterm=bold gui=bold
hi def odocEmphasis term=underline cterm=underline gui=underline
hi def odocItalic term=italic cterm=italic gui=italic

hi def link odocUrlMarker odocMarker
hi def link odocUrl Underlined
hi def link odocCrossrefMarker odocCrossref " or odocMarker
hi def link odocCrossref Label
hi def link odocCrossrefKw Keyword
hi def link odocCrossrefKwDeprecated Keyword " we may highlight it differently
hi def link odocHeading Title
hi def link odocHeadingLabel Label
hi def link odocListMarker Operator
hi def link odocMarker Delimiter
hi def link odocTag Keyword

hi def link odocBraceError Error
hi def link odocUnknownTarget Error
hi def link odocTagError Error
hi def link odocEscapedError Error
hi def link odocEscaped SpecialChar
hi def link odocEscapedBracket odocEscaped

let b:current_syntax = "odoc"

unlet odoc_syntax_loading

let &cpo = s:keepcpo
unlet s:keepcpo

" vim: ts=8