home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / syntax / ocaml.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  10.8 KB  |  252 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:      OCAML
  3. " Maintainers:   Markus Mottl     <mottl>@miss.wu-wien.ac.at
  4. "                Karl-Heinz Sylla <Karl-Heinz.Sylla>@gmd.de
  5. " Last change:   1999 July 26 - completely revised (MM)
  6.  
  7. " Remove any old syntax stuff hanging around.
  8. syn clear
  9.  
  10.  
  11. " OCAML is case sensitive.
  12. syn case match
  13.  
  14.  
  15. " lowercase identifier - the standard way to match
  16. syn match    ocamlLCIdentifier /\<\l\(\w\|'\)*\>/
  17.  
  18.  
  19. " Errors
  20. syn match    ocamlBraceErr   "}"
  21. syn match    ocamlBrackErr   "\]"
  22. syn match    ocamlParenErr   ")"
  23. syn match    ocamlArrErr     "|]"
  24. syn match    ocamlStreamErr  ">]"
  25.  
  26. syn match    ocamlCommentErr "\*)"
  27.  
  28. syn match    ocamlCountErr   "\<downto\>"
  29. syn match    ocamlCountErr   "\<to\>"
  30. syn match    ocamlDoErr      "\<do\>"
  31. syn match    ocamlDoneErr    "\<done\>"
  32. syn match    ocamlThenErr    "\<then\>"
  33.  
  34. " Error-highlighting of "end" without synchronization:
  35. " as keyword or as error (default)
  36. if exists("ocaml_noend_error")
  37.   syn match    ocamlKeyword    "\<end\>"
  38. else
  39.   syn match    ocamlEndErr     "\<end\>"
  40. endif
  41.  
  42. " Some convenient clusters
  43. syn cluster  ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  44.  
  45. syn cluster  ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  46.  
  47. syn cluster  ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod
  48.  
  49.  
  50. " Enclosing delimiters
  51. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr
  52. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}"  contains=ALLBUT,@ocamlContained,ocamlBraceErr
  53. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
  54. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr
  55. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[<" matchgroup=ocamlKeyword end=">\]" contains=ALLBUT,@ocamlContained,ocamlStreamErr
  56.  
  57.  
  58. " Comments
  59. syn region   ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo
  60. syn keyword  ocamlTodo contained TODO FIXME XXX
  61.  
  62.  
  63. " Objects
  64. syn region   ocamlEnd matchgroup=ocamlKeyword start="\<object\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  65.  
  66.  
  67. " Blocks
  68. syn region   ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  69.  
  70.  
  71. " "for"
  72. syn region   ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr
  73.  
  74.  
  75. " "do"
  76. syn region   ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
  77.  
  78.  
  79. " "if"
  80. syn region   ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr
  81.  
  82.  
  83. "" Modules
  84.  
  85. " "struct"
  86. syn region   ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  87.  
  88. " "sig"
  89. syn region   ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  90. syn region   ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
  91.  
  92. " "open"
  93. syn region   ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
  94.  
  95. " "include"
  96. syn region   ocamlNone matchgroup=ocamlKeyword start="\<include\>" matchgroup=ocamlModPath end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\.\(\w\|'\)\+\>" contains=o@ocamlAllErrs,camlComment
  97.  
  98. " "module" - somewhat complicated stuff ;-)
  99. syn region   ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
  100. syn region   ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
  101. syn region   ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1
  102. syn match    ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
  103.  
  104. syn region   ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
  105.  
  106. syn region   ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
  107. syn region   ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  108. syn region   ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam
  109. syn match    ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
  110. syn match  ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  111. syn region  ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  112. syn match   ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
  113.  
  114. syn region  ocamlFuncWith start="("me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct
  115. syn region  ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  116.  
  117. syn match    ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
  118. syn region   ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
  119. syn match    ocamlWith "\<\(\w\|'\)\+\>" contained skipwhite skipempty nextgroup=ocamlWithRest
  120. syn region   ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
  121.  
  122. " "module type"
  123. syn region   ocamlKeyword start="\<module\s*type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
  124. syn match    ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
  125.  
  126. syn keyword  ocamlKeyword  and as assert class
  127. syn keyword  ocamlKeyword  constraint else
  128. syn keyword  ocamlKeyword  exception external fun function
  129. syn keyword  ocamlKeyword  in inherit initializer
  130. syn keyword  ocamlKeyword  land lazy let match
  131. syn keyword  ocamlKeyword  method mutable new of
  132. syn keyword  ocamlKeyword  parser private raise rec
  133. syn keyword  ocamlKeyword  try type
  134. syn keyword  ocamlKeyword  val virtual when while with
  135.  
  136. syn keyword  ocamlType     array bool char exn float format int
  137. syn keyword  ocamlType     list option string unit
  138.  
  139. syn keyword  ocamlOperator asr lor lsl lsr lxor mod not or
  140.  
  141. syn keyword  ocamlBoolean      true false
  142. syn match    ocamlConstructor  "(\s*)"
  143. syn match    ocamlConstructor  "\[\s*\]"
  144. syn match    ocamlConstructor  "\[|\s*>|]"
  145. syn match    ocamlConstructor  "\[<\s*>\]"
  146. syn match    ocamlConstructor  "\u\(\w\|'\)*\>"
  147.  
  148. " Module prefix
  149. syn match    ocamlModPath      "\u\(\w\|'\)*\."he=e-1
  150.  
  151. syn match    ocamlCharacter    "'.'\|'\\\d\d\d'\|'\\[\'ntbr]'"
  152. syn match    ocamlCharErr      "'\\\d\d'\|'\\\d'"
  153. syn match    ocamlCharErr      "'\\\d\d'\|'\\\d'"
  154. syn match    ocamlCharErr      "'\\[^\'ntbr]'"
  155. syn region   ocamlString       start=+"+ skip=+\\\\\|\\"+ end=+"+
  156.  
  157. syn match    ocamlFunDef       "->"
  158. syn match    ocamlRefAssign    ":="
  159. syn match    ocamlTopStop      ";;"
  160. syn match    ocamlOperator     "\^"
  161. syn match    ocamlOperator     "::"
  162. syn match    ocamlOperator     "<-"
  163. syn match    ocamlAnyVar       "\<_\>"
  164. syn match    ocamlKeyChar      "!"
  165. syn match    ocamlKeyChar      "|[^\]]"
  166. syn match    ocamlKeyChar      ";"
  167. syn match    ocamlKeyChar      "?"
  168. syn match    ocamlKeyChar      "\*"
  169. syn match    ocamlKeyChar      "="
  170.  
  171. syn match    ocamlNumber        "\<-\=\d\+\>"
  172. syn match    ocamlNumber        "\<.\=0[x|X]\x\+\>"
  173. syn match    ocamlNumber        "\<.\=0[o|O]\o\+\>"
  174. syn match    ocamlNumber        "\<.\=0[b|B][01]\+\>"
  175. syn match    ocamlFloat         "\<\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
  176.  
  177. " synchronization
  178. syn sync minlines=20
  179. syn sync maxlines=500
  180.  
  181. syn sync match ocamlDoSync      grouphere  ocamlDo      "\<do\>"
  182. syn sync match ocamlDoSync      groupthere ocamlDo      "\<done\>"
  183. syn sync match ocamlEndSync     grouphere  ocamlEnd     "\<\(begin\|object\)\>"
  184. syn sync match ocamlEndSync     groupthere ocamlEnd     "\<end\>"
  185. syn sync match ocamlStructSync  grouphere  ocamlStruct  "\<struct\>"
  186. syn sync match ocamlStructSync  groupthere ocamlStruct  "\<end\>"
  187. syn sync match ocamlSigSync     grouphere  ocamlSig     "\<sig\>"
  188. syn sync match ocamlSigSync     groupthere ocamlSig     "\<end\>"
  189.  
  190. if !exists("did_ocaml_syntax_inits")
  191.   " The default methods for highlighting.  Can be overridden later
  192.   let did_ocaml_syntax_inits = 1
  193.  
  194.   hi link ocamlBraceErr     Error
  195.   hi link ocamlBrackErr     Error
  196.   hi link ocamlParenErr     Error
  197.   hi link ocamlStreamErr    Error
  198.   hi link ocamlArrErr       Error
  199.  
  200.   hi link ocamlCommentErr   Error
  201.  
  202.   hi link ocamlCountErr     Error
  203.   hi link ocamlDoErr        Error
  204.   hi link ocamlDoneErr      Error
  205.   hi link ocamlEndErr       Error
  206.   hi link ocamlThenErr      Error
  207.  
  208.   hi link ocamlCharErr      Error
  209.  
  210.   hi link ocamlComment      Comment
  211.  
  212.   hi link ocamlModPath      Include
  213.   hi link ocamlModule       Include
  214.   hi link ocamlModParam1    Include
  215.   hi link ocamlModType      Include
  216.   hi link ocamlMPRestr3     Include
  217.   hi link ocamlFullMod      Include
  218.   hi link ocamlModTypeRestr Include
  219.   hi link ocamlWith         Include
  220.   hi link ocamlMTDef        Include
  221.  
  222.   hi link ocamlConstructor  Constant
  223.  
  224.   hi link ocamlModPreRHS    Keyword
  225.   hi link ocamlMPRestr2     Keyword
  226.   hi link ocamlEnvKeyword   Keyword
  227.   hi link ocamlKeyword      Keyword
  228.   hi link ocamlFunDef       Keyword
  229.   hi link ocamlRefAssign    Keyword
  230.   hi link ocamlKeyChar      Keyword
  231.   hi link ocamlAnyVar       Keyword
  232.   hi link ocamlTopStop      Keyword
  233.   hi link ocamlOperator     Keyword
  234.  
  235.   hi link ocamlBoolean      Boolean
  236.   hi link ocamlCharacter    Character
  237.   hi link ocamlNumber       Number
  238.   hi link ocamlFloat        Float
  239.   hi link ocamlString       String
  240.  
  241.   hi link ocamlType         Type
  242.  
  243.   hi link ocamlTodo         Todo
  244.  
  245.   hi link ocamlEncl         Keyword
  246.  
  247. endif
  248.  
  249. let b:current_syntax = "ocaml"
  250.  
  251. " vim: ts=28
  252.