PageRenderTime 26ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/vim73/syntax/mma.vim

https://gitlab.com/shinvdu/vim_win_config
Vim Script | 325 lines | 97 code | 48 blank | 180 comment | 4 complexity | f2e6281c413eb2dc5012b9989d365c16 MD5 | raw file
  1. " Vim syntax file
  2. " Language: Mathematica
  3. " Maintainer: steve layland <layland@wolfram.com>
  4. " Last Change: Thu May 19 21:36:04 CDT 2005
  5. " Source: http://members.wri.com/layland/vim/syntax/mma.vim
  6. " http://vim.sourceforge.net/scripts/script.php?script_id=1273
  7. " Id: $Id: mma.vim,v 1.4 2006/04/14 20:40:38 vimboss Exp $
  8. " NOTE:
  9. "
  10. " Empty .m files will automatically be presumed as Matlab files
  11. " unless you have the following in your .vimrc:
  12. "
  13. " let filetype_m="mma"
  14. "
  15. " I also recommend setting the default 'Comment' hilighting to something
  16. " other than the color used for 'Function', since both are plentiful in
  17. " most mathematica files, and they are often the same color (when using
  18. " background=dark).
  19. "
  20. " Credits:
  21. " o Original Mathematica syntax version written by
  22. " Wolfgang Waltenberger <wwalten@ben.tuwien.ac.at>
  23. " o Some ideas like the CommentStar,CommentTitle were adapted
  24. " from the Java vim syntax file by Claudio Fleiner. Thanks!
  25. " o Everything else written by steve <layland@wolfram.com>
  26. "
  27. " Bugs:
  28. " o Vim 6.1 didn't really have support for character classes
  29. " of other named character classes. For example, [\a\d]
  30. " didn't work. Therefore, a lot of this code uses explicit
  31. " character classes instead: [0-9a-zA-Z]
  32. "
  33. " TODO:
  34. " folding
  35. " fix nesting
  36. " finish populating popular symbols
  37. if version < 600
  38. syntax clear
  39. elseif exists("b:current_syntax")
  40. finish
  41. endif
  42. " Group Definitions:
  43. syntax cluster mmaNotes contains=mmaTodo,mmaFixme
  44. syntax cluster mmaComments contains=mmaComment,mmaFunctionComment,mmaItem,mmaFunctionTitle,mmaCommentStar
  45. syntax cluster mmaCommentStrings contains=mmaLooseQuote,mmaCommentString,mmaUnicode
  46. syntax cluster mmaStrings contains=@mmaCommentStrings,mmaString
  47. syntax cluster mmaTop contains=mmaOperator,mmaGenericFunction,mmaPureFunction,mmaVariable
  48. " Predefined Constants:
  49. " to list all predefined Symbols would be too insane...
  50. " it's probably smarter to define a select few, and get the rest from
  51. " context if absolutely necessary.
  52. " TODO - populate this with other often used Symbols
  53. " standard fixed symbols:
  54. syntax keyword mmaVariable True False None Automatic All Null C General
  55. " mathematical constants:
  56. syntax keyword mmaVariable Pi I E Infinity ComplexInfinity Indeterminate GoldenRatio EulerGamma Degree Catalan Khinchin Glaisher
  57. " stream data / atomic heads:
  58. syntax keyword mmaVariable Byte Character Expression Number Real String Word EndOfFile Integer Symbol
  59. " sets:
  60. syntax keyword mmaVariable Integers Complexes Reals Booleans Rationals
  61. " character classes:
  62. syntax keyword mmaPattern DigitCharacter LetterCharacter WhitespaceCharacter WordCharacter EndOfString StartOfString EndOfLine StartOfLine WordBoundary
  63. " SelectionMove directions/units:
  64. syntax keyword mmaVariable Next Previous After Before Character Word Expression TextLine CellContents Cell CellGroup EvaluationCell ButtonCell GeneratedCell Notebook
  65. syntax keyword mmaVariable CellTags CellStyle CellLabel
  66. " TableForm positions:
  67. syntax keyword mmaVariable Above Below Left Right
  68. " colors:
  69. syntax keyword mmaVariable Black Blue Brown Cyan Gray Green Magenta Orange Pink Purple Red White Yellow
  70. " function attributes
  71. syntax keyword mmaVariable Protected Listable OneIdentity Orderless Flat Constant NumericFunction Locked ReadProtected HoldFirst HoldRest HoldAll HoldAllComplete SequenceHold NHoldFirst NHoldRest NHoldAll Temporary Stub
  72. " Comment Sections:
  73. " this:
  74. " :that:
  75. syntax match mmaItem "\%(^[( |*\t]*\)\@<=\%(:\+\|\w\)\w\+\%( \w\+\)\{0,3}:" contained contains=@mmaNotes
  76. " Comment Keywords:
  77. syntax keyword mmaTodo TODO NOTE HEY contained
  78. syntax match mmaTodo "X\{3,}" contained
  79. syntax keyword mmaFixme FIX[ME] FIXTHIS BROKEN contained
  80. syntax match mmaFixme "BUG\%( *\#\=[0-9]\+\)\=" contained
  81. " yay pirates...
  82. syntax match mmaFixme "\%(Y\=A\+R\+G\+\|GRR\+\|CR\+A\+P\+\)\%(!\+\)\=" contained
  83. " EmPHAsis:
  84. " this unnecessary, but whatever :)
  85. syntax match mmaemPHAsis "\%(^\|\s\)\([_/]\)[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*\1\%(\s\|$\)" contained contains=mmaemPHAsis
  86. syntax match mmaemPHAsis "\%(^\|\s\)(\@<!\*[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*)\@!\*\%(\s\|$\)" contained contains=mmaemPHAsis
  87. " Regular Comments:
  88. " (* *)
  89. " allow nesting (* (* *) *) even though the frontend
  90. " won't always like it.
  91. syntax region mmaComment start=+(\*+ end=+\*)+ skipempty contains=@mmaNotes,mmaItem,@mmaCommentStrings,mmaemPHAsis,mmaComment
  92. " Function Comments:
  93. " just like a normal comment except the first sentance is Special ala Java
  94. " (** *)
  95. " TODO - fix this for nesting, or not...
  96. syntax region mmaFunctionComment start="(\*\*\+" end="\*\+)" contains=@mmaNotes,mmaItem,mmaFunctionTitle,@mmaCommentStrings,mmaemPHAsis,mmaComment
  97. syntax region mmaFunctionTitle contained matchgroup=mmaFunctionComment start="\%((\*\*[ *]*\)" matchgroup=mmaFunctionTitle keepend end=".[.!-]\=\s*$" end="[.!-][ \t\r<&]"me=e-1 end="\%(\*\+)\)\@=" contained contains=@mmaNotes,mmaItem,mmaCommentStar
  98. " catch remaining (**********)'s
  99. syntax match mmaComment "(\*\*\+)"
  100. " catch preceding *
  101. syntax match mmaCommentStar "^\s*\*\+" contained
  102. " Variables:
  103. " Dollar sign variables
  104. syntax match mmaVariable "\$\a\+[0-9a-zA-Z$]*"
  105. " Preceding and Following Contexts
  106. syntax match mmaVariable "`[a-zA-Z$]\+[0-9a-zA-Z$]*" contains=mmaVariable
  107. syntax match mmaVariable "[a-zA-Z$]\+[0-9a-zA-Z$]*`" contains=mmaVariable
  108. " Strings:
  109. " "string"
  110. " 'string' is not accepted (until literal strings are supported!)
  111. syntax region mmaString start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+
  112. syntax region mmaCommentString oneline start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+ contained
  113. " Patterns:
  114. " Each pattern marker below can be Blank[] (_), BlankSequence[] (__)
  115. " or BlankNullSequence[] (___). Most examples below can also be
  116. " combined, for example Pattern tests with Default values.
  117. "
  118. " _Head Anonymous patterns
  119. " name_Head
  120. " name:(_Head|_Head2) Named patterns
  121. "
  122. " _Head : val
  123. " name:_Head:val Default values
  124. "
  125. " _Head?testQ,
  126. " _Head?(test[#]&) Pattern tests
  127. "
  128. " name_Head/;test[name] Conditionals
  129. "
  130. " _Head:. Predefined Default
  131. "
  132. " .. ... Pattern Repeat
  133. syntax match mmaPatternError "\%(_\{4,}\|)\s*&\s*)\@!\)" contained
  134. "pattern name:
  135. syntax match mmaPattern "[A-Za-z0-9`]\+\s*:\+[=>]\@!" contains=mmaOperator
  136. "pattern default:
  137. syntax match mmaPattern ": *[^ ,]\+[\], ]\@=" contains=@mmaCommentStrings,@mmaTop,mmaOperator
  138. "pattern head/test:
  139. syntax match mmaPattern "[A-Za-z0-9`]*_\+\%(\a\+\)\=\%(?([^)]\+)\|?[^\]},]\+\)\=" contains=@mmaTop,@mmaCommentStrings,mmaPatternError
  140. " Operators:
  141. " /: ^= ^:= UpValue
  142. " /; Conditional
  143. " := = DownValue
  144. " == === ||
  145. " != =!= && Logic
  146. " >= <= < >
  147. " += -= *=
  148. " /= ++ -- Math
  149. " ^*
  150. " -> :> Rules
  151. " @@ @@@ Apply
  152. " /@ //@ Map
  153. " /. //. Replace
  154. " // @ Function application
  155. " <> ~~ String/Pattern join
  156. " ~ infix operator
  157. " . : Pattern operators
  158. syntax match mmaOperator "\%(@\{1,3}\|//[.@]\=\)"
  159. syntax match mmaOperator "\%(/[;:@.]\=\|\^\=:\==\)"
  160. syntax match mmaOperator "\%([-:=]\=>\|<=\=\)"
  161. "syntax match mmaOperator "\%(++\=\|--\=\|[/+-*]=\|[^*]\)"
  162. syntax match mmaOperator "[*+=^.:?-]"
  163. syntax match mmaOperator "\%(\~\~\=\)"
  164. syntax match mmaOperator "\%(=\{2,3}\|=\=!=\|||\=\|&&\|!\)" contains=ALLBUT,mmaPureFunction
  165. " Symbol Tags:
  166. " "SymbolName::item"
  167. "syntax match mmaSymbol "`\=[a-zA-Z$]\+[0-9a-zA-Z$]*\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*" contained
  168. syntax match mmaMessage "`\=\([a-zA-Z$]\+[0-9a-zA-Z$]*\)\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*::\a\+" contains=mmaMessageType
  169. syntax match mmaMessageType "::\a\+"hs=s+2 contained
  170. " Pure Functions:
  171. syntax match mmaPureFunction "#\%(#\|\d\+\)\="
  172. syntax match mmaPureFunction "&"
  173. " Named Functions:
  174. " Since everything is pretty much a function, get this straight
  175. " from context
  176. syntax match mmaGenericFunction "[A-Za-z0-9`]\+\s*\%([@[]\|/:\|/\=/@\)\@=" contains=mmaOperator
  177. syntax match mmaGenericFunction "\~\s*[^~]\+\s*\~"hs=s+1,he=e-1 contains=mmaOperator,mmaBoring
  178. syntax match mmaGenericFunction "//\s*[A-Za-z0-9`]\+"hs=s+2 contains=mmaOperator
  179. " Numbers:
  180. syntax match mmaNumber "\<\%(\d\+\.\=\d*\|\d*\.\=\d\+\)\>"
  181. syntax match mmaNumber "`\d\+\%(\d\@!\.\|\>\)"
  182. " Special Characters:
  183. " \[Name] named character
  184. " \ooo octal
  185. " \.xx 2 digit hex
  186. " \:xxxx 4 digit hex (multibyte unicode)
  187. syntax match mmaUnicode "\\\[\w\+\d*\]"
  188. syntax match mmaUnicode "\\\%(\x\{3}\|\.\x\{2}\|:\x\{4}\)"
  189. " Syntax Errors:
  190. syntax match mmaError "\*)" containedin=ALLBUT,@mmaComments,@mmaStrings
  191. syntax match mmaError "\%([/]{3,}\|[&:|+*?~-]\{3,}\|[.=]\{4,}\|_\@<=\.\{2,}\|`\{2,}\)" containedin=ALLBUT,@mmaComments,@mmaStrings
  192. " Punctuation:
  193. " things that shouldn't really be highlighted, or highlighted
  194. " in they're own group if you _really_ want. :)
  195. " ( ) { }
  196. " TODO - use Delimiter group?
  197. syntax match mmaBoring "[(){}]" contained
  198. " ------------------------------------
  199. " future explorations...
  200. " ------------------------------------
  201. " Function Arguments:
  202. " anything between brackets []
  203. " (fold)
  204. "syntax region mmaArgument start="\[" end="\]" containedin=ALLBUT,@mmaComments,@mmaStrings transparent fold
  205. " Lists:
  206. " (fold)
  207. "syntax region mmaLists start="{" end="}" containedin=ALLBUT,@mmaComments,@mmaStrings transparent fold
  208. " Regions:
  209. " (fold)
  210. "syntax region mmaRegion start="(\*\+[^<]*<!--[^>]*\*\+)" end="--> \*)" containedin=ALLBUT,@mmaStrings transparent fold keepend
  211. " show fold text
  212. set commentstring='(*%s*)'
  213. "set foldtext=MmaFoldText()
  214. "function MmaFoldText()
  215. " let line = getline(v:foldstart)
  216. "
  217. " let lines = v:foldend-v:foldstart+1
  218. "
  219. " let sub = substitute(line, '(\*\+|\*\+)|[-*_]\+', '', 'g')
  220. "
  221. " if match(line, '(\*') != -1
  222. " let lines = lines.' line comment'
  223. " else
  224. " let lines = lines.' lines'
  225. " endif
  226. "
  227. " return v:folddashes.' '.lines.' '.sub
  228. "endf
  229. "this is slow for computing folds, but it does so accurately
  230. syntax sync fromstart
  231. " but this seems to do alright for non fold syntax coloring.
  232. " for folding, however, it doesn't get the nesting right.
  233. " TODO - find sync group for multiline modules? ick...
  234. " sync multi line comments
  235. "syntax sync match syncComments groupthere NONE "\*)"
  236. "syntax sync match syncComments groupthere mmaComment "(\*"
  237. "set foldmethod=syntax
  238. "set foldnestmax=1
  239. "set foldminlines=15
  240. if version >= 508 || !exists("did_mma_syn_inits")
  241. if version < 508
  242. let did_mma_syn_inits = 1
  243. command -nargs=+ HiLink hi link <args>
  244. else
  245. command -nargs=+ HiLink hi def link <args>
  246. endif
  247. " NOTE - the following links are not guaranteed to
  248. " look good under all colorschemes. You might need to
  249. " :so $VIMRUNTIME/syntax/hitest.vim and tweak these to
  250. " look good in yours
  251. HiLink mmaComment Comment
  252. HiLink mmaCommentStar Comment
  253. HiLink mmaFunctionComment Comment
  254. HiLink mmaLooseQuote Comment
  255. HiLink mmaGenericFunction Function
  256. HiLink mmaVariable Identifier
  257. " HiLink mmaSymbol Identifier
  258. HiLink mmaOperator Operator
  259. HiLink mmaPatternOp Operator
  260. HiLink mmaPureFunction Operator
  261. HiLink mmaString String
  262. HiLink mmaCommentString String
  263. HiLink mmaUnicode String
  264. HiLink mmaMessage Type
  265. HiLink mmaNumber Type
  266. HiLink mmaPattern Type
  267. HiLink mmaError Error
  268. HiLink mmaFixme Error
  269. HiLink mmaPatternError Error
  270. HiLink mmaTodo Todo
  271. HiLink mmaemPHAsis Special
  272. HiLink mmaFunctionTitle Special
  273. HiLink mmaMessageType Special
  274. HiLink mmaItem Preproc
  275. delcommand HiLink
  276. endif
  277. let b:current_syntax = "mma"