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