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 / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / syntax / ocaml.vim < prev    next >
Encoding:
Text File  |  2003-05-04  |  12.4 KB  |  318 lines

  1. " Vim syntax file
  2. " Language:     OCaml
  3. " Filenames:    *.ml *.mli *.mll *.mly
  4. " Maintainers:  Markus Mottl      <markus@oefai.at>
  5. "        Karl-Heinz Sylla  <Karl-Heinz.Sylla@gmd.de>
  6. "        Issac Trotts      <<ijtrotts@ucdavis.edu>
  7. " URL:        http://www.oefai.at/~markus/vim/syntax/ocaml.vim
  8. " Last Change:    2003 May 04
  9. "        2002 Oct 24 - Small fix for "module type" (MM)
  10. "        2002 Jun 16 - Added "&&", "<" and ">" as operators (MM)
  11.  
  12. " For version 5.x: Clear all syntax items
  13. " For version 6.x: Quit when a syntax file was already loaded
  14. if version < 600
  15.   syntax clear
  16. elseif exists("b:current_syntax")
  17.   finish
  18. endif
  19.  
  20. " OCaml is case sensitive.
  21. syn case match
  22.  
  23. " Script headers highlighted like comments
  24. syn match    ocamlComment   "^#!.*"
  25.  
  26. " Scripting directives
  27. syn match    ocamlScript "^#\<\(quit\|labels\|warnings\|directory\|cd\|load\|use\|install_printer\|remove_printer\|trace\|untrace\|untrace_all\|print_depth\|print_length\)\>"
  28.  
  29. " lowercase identifier - the standard way to match
  30. syn match    ocamlLCIdentifier /\<\(\l\|_\)\(\w\|'\)*\>/
  31.  
  32. syn match    ocamlKeyChar    "|"
  33.  
  34. " Errors
  35. syn match    ocamlBraceErr   "}"
  36. syn match    ocamlBrackErr   "\]"
  37. syn match    ocamlParenErr   ")"
  38. syn match    ocamlArrErr     "|]"
  39.  
  40. syn match    ocamlCommentErr "\*)"
  41.  
  42. syn match    ocamlCountErr   "\<downto\>"
  43. syn match    ocamlCountErr   "\<to\>"
  44.  
  45. if !exists("ocaml_revised")
  46.   syn match    ocamlDoErr      "\<do\>"
  47. endif
  48.  
  49. syn match    ocamlDoneErr    "\<done\>"
  50. syn match    ocamlThenErr    "\<then\>"
  51.  
  52. " Error-highlighting of "end" without synchronization:
  53. " as keyword or as error (default)
  54. if exists("ocaml_noend_error")
  55.   syn match    ocamlKeyword    "\<end\>"
  56. else
  57.   syn match    ocamlEndErr     "\<end\>"
  58. endif
  59.  
  60. " Some convenient clusters
  61. syn cluster  ocamlAllErrs contains=ocamlBraceErr,ocamlBrackErr,ocamlParenErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  62.  
  63. syn cluster  ocamlAENoParen contains=ocamlBraceErr,ocamlBrackErr,ocamlCommentErr,ocamlCountErr,ocamlDoErr,ocamlDoneErr,ocamlEndErr,ocamlThenErr
  64.  
  65. syn cluster  ocamlContained contains=ocamlTodo,ocamlPreDef,ocamlModParam,ocamlModParam1,ocamlPreMPRestr,ocamlMPRestr,ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3,ocamlModRHS,ocamlFuncWith,ocamlFuncStruct,ocamlModTypeRestr,ocamlModTRWith,ocamlWith,ocamlWithRest,ocamlModType,ocamlFullMod
  66.  
  67.  
  68. " Enclosing delimiters
  69. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="(" matchgroup=ocamlKeyword end=")" contains=ALLBUT,@ocamlContained,ocamlParenErr
  70. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="{" matchgroup=ocamlKeyword end="}"  contains=ALLBUT,@ocamlContained,ocamlBraceErr
  71. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[" matchgroup=ocamlKeyword end="\]" contains=ALLBUT,@ocamlContained,ocamlBrackErr
  72. syn region   ocamlEncl transparent matchgroup=ocamlKeyword start="\[|" matchgroup=ocamlKeyword end="|\]" contains=ALLBUT,@ocamlContained,ocamlArrErr
  73.  
  74.  
  75. " Comments
  76. syn region   ocamlComment start="(\*" end="\*)" contains=ocamlComment,ocamlTodo
  77. syn keyword  ocamlTodo contained TODO FIXME XXX
  78.  
  79.  
  80. " Objects
  81. syn region   ocamlEnd matchgroup=ocamlKeyword start="\<object\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  82.  
  83.  
  84. " Blocks
  85. if !exists("ocaml_revised")
  86.   syn region   ocamlEnd matchgroup=ocamlKeyword start="\<begin\>" matchgroup=ocamlKeyword end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  87. endif
  88.  
  89.  
  90. " "for"
  91. syn region   ocamlNone matchgroup=ocamlKeyword start="\<for\>" matchgroup=ocamlKeyword end="\<\(to\|downto\)\>" contains=ALLBUT,@ocamlContained,ocamlCountErr
  92.  
  93.  
  94. " "do"
  95. if !exists("ocaml_revised")
  96.   syn region   ocamlDo matchgroup=ocamlKeyword start="\<do\>" matchgroup=ocamlKeyword end="\<done\>" contains=ALLBUT,@ocamlContained,ocamlDoneErr
  97. endif
  98.  
  99. " "if"
  100. syn region   ocamlNone matchgroup=ocamlKeyword start="\<if\>" matchgroup=ocamlKeyword end="\<then\>" contains=ALLBUT,@ocamlContained,ocamlThenErr
  101.  
  102.  
  103. "" Modules
  104.  
  105. " "struct"
  106. syn region   ocamlStruct matchgroup=ocamlModule start="\<struct\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  107.  
  108. " "sig"
  109. syn region   ocamlSig matchgroup=ocamlModule start="\<sig\>" matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  110. syn region   ocamlModSpec matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contained contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlModTRWith,ocamlMPRestr
  111.  
  112. " "open"
  113. syn region   ocamlNone matchgroup=ocamlKeyword start="\<open\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*\>" contains=@ocamlAllErrs,ocamlComment
  114.  
  115. " "include"
  116. syn match    ocamlKeyword "\<include\>" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  117.  
  118. " "module" - somewhat complicated stuff ;-)
  119. syn region   ocamlModule matchgroup=ocamlKeyword start="\<module\>" matchgroup=ocamlModule end="\<\u\(\w\|'\)*\>" contains=@ocamlAllErrs,ocamlComment skipwhite skipempty nextgroup=ocamlPreDef
  120. syn region   ocamlPreDef start="."me=e-1 matchgroup=ocamlKeyword end="\l\|="me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam,ocamlModTypeRestr,ocamlModTRWith nextgroup=ocamlModPreRHS
  121. syn region   ocamlModParam start="([^*]" end=")" contained contains=@ocamlAENoParen,ocamlModParam1
  122. syn match    ocamlModParam1 "\<\u\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlPreMPRestr
  123.  
  124. syn region   ocamlPreMPRestr start="."me=e-1 end=")"me=e-1 contained contains=@ocamlAllErrs,ocamlComment,ocamlMPRestr,ocamlModTypeRestr
  125.  
  126. syn region   ocamlMPRestr start=":" end="."me=e-1 contained contains=@ocamlComment skipwhite skipempty nextgroup=ocamlMPRestr1,ocamlMPRestr2,ocamlMPRestr3
  127. syn region   ocamlMPRestr1 matchgroup=ocamlModule start="\ssig\s\=" matchgroup=ocamlModule end="\<end\>" contained contains=ALLBUT,@ocamlContained,ocamlEndErr,ocamlModule
  128. syn region   ocamlMPRestr2 start="\sfunctor\(\s\|(\)\="me=e-1 matchgroup=ocamlKeyword end="->" contained contains=@ocamlAllErrs,ocamlComment,ocamlModParam skipwhite skipempty nextgroup=ocamlFuncWith,ocamlMPRestr2
  129. syn match    ocamlMPRestr3 "\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*" contained
  130. syn match    ocamlModPreRHS "=" contained skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  131. syn region   ocamlModRHS start="." end=".\w\|([^*]"me=e-2 contained contains=ocamlComment skipwhite skipempty nextgroup=ocamlModParam,ocamlFullMod
  132. syn match    ocamlFullMod "\<\u\(\w\|'\)*\(\.\u\(\w\|'\)*\)*" contained skipwhite skipempty nextgroup=ocamlFuncWith
  133.  
  134. syn region   ocamlFuncWith start="([^*]"me=e-1 end=")" contained contains=ocamlComment,ocamlWith,ocamlFuncStruct skipwhite skipempty nextgroup=ocamlFuncWith
  135. syn region   ocamlFuncStruct matchgroup=ocamlModule start="[^a-zA-Z]struct\>"hs=s+1 matchgroup=ocamlModule end="\<end\>" contains=ALLBUT,@ocamlContained,ocamlEndErr
  136.  
  137. syn match    ocamlModTypeRestr "\<\w\(\w\|'\)*\(\.\w\(\w\|'\)*\)*\>" contained
  138. syn region   ocamlModTRWith start=":\s*("hs=s+1 end=")" contained contains=@ocamlAENoParen,ocamlWith
  139. syn match    ocamlWith "\<\(\u\(\w\|'\)*\.\)*\w\(\w\|'\)*\>" contained skipwhite skipempty nextgroup=ocamlWithRest
  140. syn region   ocamlWithRest start="[^)]" end=")"me=e-1 contained contains=ALLBUT,@ocamlContained
  141.  
  142. " "module type"
  143. syn region   ocamlKeyword start="\<module\>\s*\<type\>" matchgroup=ocamlModule end="\<\w\(\w\|'\)*\>" contains=ocamlComment skipwhite skipempty nextgroup=ocamlMTDef
  144. syn match    ocamlMTDef "=\s*\w\(\w\|'\)*\>"hs=s+1,me=s
  145.  
  146. syn keyword  ocamlKeyword  and as assert class
  147. syn keyword  ocamlKeyword  constraint else
  148. syn keyword  ocamlKeyword  exception external fun
  149.  
  150. syn keyword  ocamlKeyword  in inherit initializer
  151. syn keyword  ocamlKeyword  land lazy let match
  152. syn keyword  ocamlKeyword  method mutable new of
  153. syn keyword  ocamlKeyword  parser private raise rec
  154. syn keyword  ocamlKeyword  try type
  155. syn keyword  ocamlKeyword  val virtual when while with
  156.  
  157. if exists("ocaml_revised")
  158.   syn keyword  ocamlKeyword  do value
  159.   syn keyword  ocamlBoolean  True False
  160. else
  161.   syn keyword  ocamlKeyword  function
  162.   syn keyword  ocamlBoolean  true false
  163.   syn match    ocamlKeyChar  "!"
  164. endif
  165.  
  166. syn keyword  ocamlType     array bool char exn float format int
  167. syn keyword  ocamlType     list option string unit
  168.  
  169. syn keyword  ocamlOperator asr lor lsl lsr lxor mod not
  170.  
  171. syn match    ocamlConstructor  "(\s*)"
  172. syn match    ocamlConstructor  "\[\s*\]"
  173. syn match    ocamlConstructor  "\[|\s*>|]"
  174. syn match    ocamlConstructor  "\[<\s*>\]"
  175. syn match    ocamlConstructor  "\u\(\w\|'\)*\>"
  176.  
  177. " Polymorphic variants
  178. syn match    ocamlConstructor  "`\w\(\w\|'\)*\>"
  179.  
  180. " Module prefix
  181. syn match    ocamlModPath      "\u\(\w\|'\)*\."he=e-1
  182.  
  183. syn match    ocamlCharacter    "'\\\d\d\d'\|'\\[\'ntbr]'\|'.'"
  184. syn match    ocamlCharErr      "'\\\d\d'\|'\\\d'"
  185. syn match    ocamlCharErr      "'\\[^\'ntbr]'"
  186. syn region   ocamlString       start=+"+ skip=+\\\\\|\\"+ end=+"+
  187.  
  188. syn match    ocamlFunDef       "->"
  189. syn match    ocamlRefAssign    ":="
  190. syn match    ocamlTopStop      ";;"
  191. syn match    ocamlOperator     "\^"
  192. syn match    ocamlOperator     "::"
  193.  
  194. syn match    ocamlOperator     "&&"
  195. syn match    ocamlOperator     "<"
  196. syn match    ocamlOperator     ">"
  197. syn match    ocamlAnyVar       "\<_\>"
  198. syn match    ocamlKeyChar      "|[^\]]"me=e-1
  199. syn match    ocamlKeyChar      ";"
  200. syn match    ocamlKeyChar      "\~"
  201. syn match    ocamlKeyChar      "?"
  202. syn match    ocamlKeyChar      "\*"
  203. syn match    ocamlKeyChar      "="
  204.  
  205. if exists("ocaml_revised")
  206.   syn match    ocamlErr        "<-"
  207. else
  208.   syn match    ocamlOperator    "<-"
  209. endif
  210.  
  211. syn match    ocamlNumber    "\<-\=\d\+\>"
  212. syn match    ocamlNumber    "\<-\=0[x|X]\x\+\>"
  213. syn match    ocamlNumber    "\<-\=0[o|O]\o\+\>"
  214. syn match    ocamlNumber    "\<-\=0[b|B][01]\+\>"
  215. syn match    ocamlFloat        "\<-\=\d\+\.\d*\([eE][-+]\=\d\+\)\=[fl]\=\>"
  216.  
  217. " Labels
  218. syn match    ocamlLabel        "\~\(\l\|_\)\(\w\|'\)*"lc=1
  219. syn match    ocamlLabel        "?\(\l\|_\)\(\w\|'\)*"lc=1
  220. syn region   ocamlLabel transparent matchgroup=ocamlLabel start="?(\(\l\|_\)\(\w\|'\)*"lc=2 end=")"me=e-1 contains=ALLBUT,@ocamlContained,ocamlParenErr
  221.  
  222.  
  223. " Synchronization
  224. syn sync minlines=50
  225. syn sync maxlines=500
  226.  
  227. if !exists("ocaml_revised")
  228.   syn sync match ocamlDoSync      grouphere  ocamlDo      "\<do\>"
  229.   syn sync match ocamlDoSync      groupthere ocamlDo      "\<done\>"
  230. endif
  231.  
  232. if exists("ocaml_revised")
  233.   syn sync match ocamlEndSync     grouphere  ocamlEnd     "\<\(object\)\>"
  234. else
  235.   syn sync match ocamlEndSync     grouphere  ocamlEnd     "\<\(begin\|object\)\>"
  236. endif
  237.  
  238. syn sync match ocamlEndSync     groupthere ocamlEnd     "\<end\>"
  239. syn sync match ocamlStructSync  grouphere  ocamlStruct  "\<struct\>"
  240. syn sync match ocamlStructSync  groupthere ocamlStruct  "\<end\>"
  241. syn sync match ocamlSigSync     grouphere  ocamlSig     "\<sig\>"
  242. syn sync match ocamlSigSync     groupthere ocamlSig     "\<end\>"
  243.  
  244. " Define the default highlighting.
  245. " For version 5.7 and earlier: only when not done already
  246. " For version 5.8 and later: only when an item doesn't have highlighting yet
  247. if version >= 508 || !exists("did_ocaml_syntax_inits")
  248.   if version < 508
  249.     let did_ocaml_syntax_inits = 1
  250.     command -nargs=+ HiLink hi link <args>
  251.   else
  252.     command -nargs=+ HiLink hi def link <args>
  253.   endif
  254.  
  255.   HiLink ocamlBraceErr       Error
  256.   HiLink ocamlBrackErr       Error
  257.   HiLink ocamlParenErr       Error
  258.   HiLink ocamlArrErr       Error
  259.  
  260.   HiLink ocamlCommentErr   Error
  261.  
  262.   HiLink ocamlCountErr       Error
  263.   HiLink ocamlDoErr       Error
  264.   HiLink ocamlDoneErr       Error
  265.   HiLink ocamlEndErr       Error
  266.   HiLink ocamlThenErr       Error
  267.  
  268.   HiLink ocamlCharErr       Error
  269.  
  270.   HiLink ocamlErr       Error
  271.  
  272.   HiLink ocamlComment       Comment
  273.  
  274.   HiLink ocamlModPath       Include
  275.   HiLink ocamlModule       Include
  276.   HiLink ocamlModParam1    Include
  277.   HiLink ocamlModType       Include
  278.   HiLink ocamlMPRestr3       Include
  279.   HiLink ocamlFullMod       Include
  280.   HiLink ocamlModTypeRestr Include
  281.   HiLink ocamlWith       Include
  282.   HiLink ocamlMTDef       Include
  283.  
  284.   HiLink ocamlScript       Include
  285.  
  286.   HiLink ocamlConstructor  Constant
  287.  
  288.   HiLink ocamlModPreRHS    Keyword
  289.   HiLink ocamlMPRestr2       Keyword
  290.   HiLink ocamlKeyword       Keyword
  291.   HiLink ocamlFunDef       Keyword
  292.   HiLink ocamlRefAssign    Keyword
  293.   HiLink ocamlKeyChar       Keyword
  294.   HiLink ocamlAnyVar       Keyword
  295.   HiLink ocamlTopStop       Keyword
  296.   HiLink ocamlOperator       Keyword
  297.  
  298.   HiLink ocamlBoolean       Boolean
  299.   HiLink ocamlCharacter    Character
  300.   HiLink ocamlNumber       Number
  301.   HiLink ocamlFloat       Float
  302.   HiLink ocamlString       String
  303.  
  304.   HiLink ocamlLabel       Identifier
  305.  
  306.   HiLink ocamlType       Type
  307.  
  308.   HiLink ocamlTodo       Todo
  309.  
  310.   HiLink ocamlEncl       Keyword
  311.  
  312.   delcommand HiLink
  313. endif
  314.  
  315. let b:current_syntax = "ocaml"
  316.  
  317. " vim: ts=8
  318.