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