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