Install vim74
[msysgit.git] / share / vim / vim74 / syntax / mma.vim
blobc63beb11951053f65f698ad8439cf9b6ce62ef39
1 " Vim syntax file
2 " Language:     Mathematica
3 " Maintainer:   steve layland <layland@wolfram.com>
4 " Last Change:  2012 Feb 03 by Thilo Six
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:
10 " Empty .m files will automatically be presumed as Matlab files
11 " unless you have the following in your .vimrc:
13 "       let filetype_m="mma"
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).
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>
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]
33 " TODO:
34 "   folding
35 "   fix nesting
36 "   finish populating popular symbols
38 if version < 600
39         syntax clear
40 elseif exists("b:current_syntax")
41     finish
42 endif
44 let s:cpo_save = &cpo
45 set cpo&vim
47 " Group Definitions:
48 syntax cluster mmaNotes contains=mmaTodo,mmaFixme
49 syntax cluster mmaComments contains=mmaComment,mmaFunctionComment,mmaItem,mmaFunctionTitle,mmaCommentStar
50 syntax cluster mmaCommentStrings contains=mmaLooseQuote,mmaCommentString,mmaUnicode
51 syntax cluster mmaStrings contains=@mmaCommentStrings,mmaString
52 syntax cluster mmaTop contains=mmaOperator,mmaGenericFunction,mmaPureFunction,mmaVariable
54 " Predefined Constants:
55 "   to list all predefined Symbols would be too insane...
56 "   it's probably smarter to define a select few, and get the rest from
57 "   context if absolutely necessary.
58 "   TODO - populate this with other often used Symbols
60 " standard fixed symbols:
61 syntax keyword mmaVariable True False None Automatic All Null C General
63 " mathematical constants:
64 syntax keyword mmaVariable Pi I E Infinity ComplexInfinity Indeterminate GoldenRatio EulerGamma Degree Catalan Khinchin Glaisher
66 " stream data / atomic heads:
67 syntax keyword mmaVariable Byte Character Expression Number Real String Word EndOfFile Integer Symbol
69 " sets:
70 syntax keyword mmaVariable Integers Complexes Reals Booleans Rationals
72 " character classes:
73 syntax keyword mmaPattern DigitCharacter LetterCharacter WhitespaceCharacter WordCharacter EndOfString StartOfString EndOfLine StartOfLine WordBoundary
75 " SelectionMove directions/units:
76 syntax keyword mmaVariable Next Previous After Before Character Word Expression TextLine CellContents Cell CellGroup EvaluationCell ButtonCell GeneratedCell Notebook
77 syntax keyword mmaVariable CellTags CellStyle CellLabel
79 " TableForm positions:
80 syntax keyword mmaVariable Above Below Left Right
82 " colors:
83 syntax keyword mmaVariable Black Blue Brown Cyan Gray Green Magenta Orange Pink Purple Red White Yellow
85 " function attributes
86 syntax keyword mmaVariable Protected Listable OneIdentity Orderless Flat Constant NumericFunction Locked ReadProtected HoldFirst HoldRest HoldAll HoldAllComplete SequenceHold NHoldFirst NHoldRest NHoldAll Temporary Stub
88 " Comment Sections:
89 "   this:
90 "   :that:
91 syntax match mmaItem "\%(^[( |*\t]*\)\@<=\%(:\+\|\w\)\w\+\%( \w\+\)\{0,3}:" contained contains=@mmaNotes
93 " Comment Keywords:
94 syntax keyword mmaTodo TODO NOTE HEY contained
95 syntax match mmaTodo "X\{3,}" contained
96 syntax keyword mmaFixme FIX[ME] FIXTHIS BROKEN contained
97 syntax match mmaFixme "BUG\%( *\#\=[0-9]\+\)\=" contained
98 " yay pirates...
99 syntax match mmaFixme "\%(Y\=A\+R\+G\+\|GRR\+\|CR\+A\+P\+\)\%(!\+\)\=" contained
101 " EmPHAsis:
102 " this unnecessary, but whatever :)
103 syntax match mmaemPHAsis "\%(^\|\s\)\([_/]\)[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*\1\%(\s\|$\)" contained contains=mmaemPHAsis
104 syntax match mmaemPHAsis "\%(^\|\s\)(\@<!\*[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*)\@!\*\%(\s\|$\)" contained contains=mmaemPHAsis
106 " Regular Comments:
107 "   (* *)
108 "   allow nesting (* (* *) *) even though the frontend
109 "   won't always like it.
110 syntax region mmaComment start=+(\*+ end=+\*)+ skipempty contains=@mmaNotes,mmaItem,@mmaCommentStrings,mmaemPHAsis,mmaComment
112 " Function Comments:
113 "   just like a normal comment except the first sentance is Special ala Java
114 "   (** *)
115 "   TODO - fix this for nesting, or not...
116 syntax region mmaFunctionComment start="(\*\*\+" end="\*\+)" contains=@mmaNotes,mmaItem,mmaFunctionTitle,@mmaCommentStrings,mmaemPHAsis,mmaComment
117 syntax region mmaFunctionTitle contained matchgroup=mmaFunctionComment start="\%((\*\*[ *]*\)" matchgroup=mmaFunctionTitle keepend end=".[.!-]\=\s*$" end="[.!-][ \t\r<&]"me=e-1 end="\%(\*\+)\)\@=" contained contains=@mmaNotes,mmaItem,mmaCommentStar
119 " catch remaining (**********)'s
120 syntax match mmaComment "(\*\*\+)"
121 " catch preceding *
122 syntax match mmaCommentStar "^\s*\*\+" contained
124 " Variables:
125 "   Dollar sign variables
126 syntax match mmaVariable "\$\a\+[0-9a-zA-Z$]*"
128 "   Preceding and Following Contexts
129 syntax match mmaVariable "`[a-zA-Z$]\+[0-9a-zA-Z$]*" contains=mmaVariable
130 syntax match mmaVariable "[a-zA-Z$]\+[0-9a-zA-Z$]*`" contains=mmaVariable
132 " Strings:
133 "   "string"
134 "   'string' is not accepted (until literal strings are supported!)
135 syntax region mmaString start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+
136 syntax region mmaCommentString oneline start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+ contained
139 " Patterns:
140 "   Each pattern marker below can be Blank[] (_), BlankSequence[] (__)
141 "   or BlankNullSequence[] (___).  Most examples below can also be
142 "   combined, for example Pattern tests with Default values.
144 "   _Head                   Anonymous patterns
145 "   name_Head
146 "   name:(_Head|_Head2)     Named patterns
148 "   _Head : val
149 "   name:_Head:val          Default values
151 "   _Head?testQ,
152 "   _Head?(test[#]&)        Pattern tests
154 "   name_Head/;test[name]   Conditionals
156 "   _Head:.                 Predefined Default
158 "   .. ...                  Pattern Repeat
160 syntax match mmaPatternError "\%(_\{4,}\|)\s*&\s*)\@!\)" contained
162 "pattern name:
163 syntax match mmaPattern "[A-Za-z0-9`]\+\s*:\+[=>]\@!" contains=mmaOperator
164 "pattern default:
165 syntax match mmaPattern ": *[^ ,]\+[\], ]\@=" contains=@mmaCommentStrings,@mmaTop,mmaOperator
166 "pattern head/test:
167 syntax match mmaPattern "[A-Za-z0-9`]*_\+\%(\a\+\)\=\%(?([^)]\+)\|?[^\]},]\+\)\=" contains=@mmaTop,@mmaCommentStrings,mmaPatternError
169 " Operators:
170 "   /: ^= ^:=   UpValue
171 "   /;          Conditional
172 "   := =        DownValue
173 "   == === ||
174 "   != =!= &&   Logic
175 "   >= <= < >
176 "   += -= *=
177 "   /= ++ --    Math
178 "   ^*
179 "   -> :>       Rules
180 "   @@ @@@      Apply
181 "   /@ //@      Map
182 "   /. //.      Replace
183 "   // @        Function application
184 "   <> ~~       String/Pattern join
185 "   ~           infix operator
186 "   . :         Pattern operators
187 syntax match mmaOperator "\%(@\{1,3}\|//[.@]\=\)"
188 syntax match mmaOperator "\%(/[;:@.]\=\|\^\=:\==\)"
189 syntax match mmaOperator "\%([-:=]\=>\|<=\=\)"
190 "syntax match mmaOperator "\%(++\=\|--\=\|[/+-*]=\|[^*]\)"
191 syntax match mmaOperator "[*+=^.:?-]"
192 syntax match mmaOperator "\%(\~\~\=\)"
193 syntax match mmaOperator "\%(=\{2,3}\|=\=!=\|||\=\|&&\|!\)" contains=ALLBUT,mmaPureFunction
195 " Symbol Tags:
196 "   "SymbolName::item"
197 "syntax match mmaSymbol "`\=[a-zA-Z$]\+[0-9a-zA-Z$]*\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*" contained
198 syntax match mmaMessage "`\=\([a-zA-Z$]\+[0-9a-zA-Z$]*\)\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*::\a\+" contains=mmaMessageType
199 syntax match mmaMessageType "::\a\+"hs=s+2 contained
201 " Pure Functions:
202 syntax match mmaPureFunction "#\%(#\|\d\+\)\="
203 syntax match mmaPureFunction "&"
205 " Named Functions:
206 " Since everything is pretty much a function, get this straight
207 " from context
208 syntax match mmaGenericFunction "[A-Za-z0-9`]\+\s*\%([@[]\|/:\|/\=/@\)\@=" contains=mmaOperator
209 syntax match mmaGenericFunction "\~\s*[^~]\+\s*\~"hs=s+1,he=e-1 contains=mmaOperator,mmaBoring
210 syntax match mmaGenericFunction "//\s*[A-Za-z0-9`]\+"hs=s+2 contains=mmaOperator
212 " Numbers:
213 syntax match mmaNumber "\<\%(\d\+\.\=\d*\|\d*\.\=\d\+\)\>"
214 syntax match mmaNumber "`\d\+\%(\d\@!\.\|\>\)"
216 " Special Characters:
217 "   \[Name]     named character
218 "   \ooo        octal
219 "   \.xx        2 digit hex
220 "   \:xxxx      4 digit hex (multibyte unicode)
221 syntax match mmaUnicode "\\\[\w\+\d*\]"
222 syntax match mmaUnicode "\\\%(\x\{3}\|\.\x\{2}\|:\x\{4}\)"
224 " Syntax Errors:
225 syntax match mmaError "\*)" containedin=ALLBUT,@mmaComments,@mmaStrings
226 syntax match mmaError "\%([/]{3,}\|[&:|+*?~-]\{3,}\|[.=]\{4,}\|_\@<=\.\{2,}\|`\{2,}\)" containedin=ALLBUT,@mmaComments,@mmaStrings
228 " Punctuation:
229 " things that shouldn't really be highlighted, or highlighted
230 " in they're own group if you _really_ want. :)
231 "  ( ) { }
232 " TODO - use Delimiter group?
233 syntax match mmaBoring "[(){}]" contained
235 " ------------------------------------
236 "    future explorations...
237 " ------------------------------------
238 " Function Arguments:
239 "   anything between brackets []
240 "   (fold)
241 "syntax region mmaArgument start="\[" end="\]" containedin=ALLBUT,@mmaComments,@mmaStrings transparent fold
243 " Lists:
244 "   (fold)
245 "syntax region mmaLists start="{" end="}" containedin=ALLBUT,@mmaComments,@mmaStrings transparent fold
247 " Regions:
248 "   (fold)
249 "syntax region mmaRegion start="(\*\+[^<]*<!--[^>]*\*\+)" end="--> \*)" containedin=ALLBUT,@mmaStrings transparent fold keepend
251 " show fold text
252 set commentstring='(*%s*)'
253 "set foldtext=MmaFoldText()
255 "function MmaFoldText()
256 "    let line = getline(v:foldstart)
258 "    let lines = v:foldend-v:foldstart+1
260 "    let sub = substitute(line, '(\*\+|\*\+)|[-*_]\+', '', 'g')
262 "    if match(line, '(\*') != -1
263 "        let lines = lines.' line comment'
264 "    else
265 "        let lines = lines.' lines'
266 "    endif
268 "    return v:folddashes.' '.lines.' '.sub
269 "endf
271 "this is slow for computing folds, but it does so accurately
272 syntax sync fromstart
274 " but this seems to do alright for non fold syntax coloring.
275 " for folding, however, it doesn't get the nesting right.
276 " TODO - find sync group for multiline modules? ick...
278 " sync multi line comments
279 "syntax sync match syncComments groupthere NONE "\*)"
280 "syntax sync match syncComments groupthere mmaComment "(\*"
282 "set foldmethod=syntax
283 "set foldnestmax=1
284 "set foldminlines=15
286 if version >= 508 || !exists("did_mma_syn_inits")
287         if version < 508
288                 let did_mma_syn_inits = 1
289                 command -nargs=+ HiLink hi link <args>
290         else
291                 command -nargs=+ HiLink hi def link <args>
292         endif
294     " NOTE - the following links are not guaranteed to
295     " look good under all colorschemes.  You might need to
296     " :so $VIMRUNTIME/syntax/hitest.vim and tweak these to
297     " look good in yours
300     HiLink mmaComment           Comment
301     HiLink mmaCommentStar       Comment
302     HiLink mmaFunctionComment   Comment
303     HiLink mmaLooseQuote        Comment
304         HiLink mmaGenericFunction   Function
305         HiLink mmaVariable          Identifier
306 "    HiLink mmaSymbol            Identifier
307         HiLink mmaOperator          Operator
308     HiLink mmaPatternOp         Operator
309         HiLink mmaPureFunction      Operator
310         HiLink mmaString            String
311     HiLink mmaCommentString     String
312         HiLink mmaUnicode           String
313         HiLink mmaMessage           Type
314     HiLink mmaNumber            Type
315         HiLink mmaPattern           Type
316         HiLink mmaError             Error
317         HiLink mmaFixme             Error
318     HiLink mmaPatternError      Error
319     HiLink mmaTodo              Todo
320     HiLink mmaemPHAsis          Special
321     HiLink mmaFunctionTitle     Special
322     HiLink mmaMessageType       Special
323     HiLink mmaItem              Preproc
325         delcommand HiLink
326 endif
328 let b:current_syntax = "mma"
330 let &cpo = s:cpo_save
331 unlet s:cpo_save