Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: Mathematica |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 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 |
| 17 | " background=dark). I use |
| 18 | " |
| 19 | " hi Comment ctermfg=darkcyan |
| 20 | " |
| 21 | " darkgreen also looks good on my terminal. |
| 22 | " |
| 23 | " Credits: |
| 24 | " o Original Mathematica syntax version written by |
| 25 | " Wolfgang Waltenberger <wwalten@ben.tuwien.ac.at> |
| 26 | " o Some ideas like the CommentStar,CommentTitle were adapted |
| 27 | " from the Java vim syntax file by Claudio Fleiner. Thanks! |
| 28 | " o Everything else written by steve <layland@wolfram.com> |
| 29 | " |
| 30 | " TODO: |
| 31 | " folding |
| 32 | " fix nesting |
| 33 | " finish populating popular symbols |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | |
| 35 | if version < 600 |
| 36 | syntax clear |
| 37 | elseif exists("b:current_syntax") |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 38 | finish |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 39 | endif |
| 40 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 41 | " Group Definitions: |
| 42 | syntax cluster mmaNotes contains=mmaTodo,mmaFixme |
| 43 | syntax cluster mmaComments contains=mmaComment,mmaFunctionComment,mmaItem,mmaFunctionTitle,mmaCommentStar |
| 44 | syntax cluster mmaCommentStrings contains=mmaLooseQuote,mmaCommentString,mmaUnicode |
| 45 | syntax cluster mmaStrings contains=@mmaCommentStrings,mmaString |
| 46 | syntax cluster mmaTop contains=mmaOperator,mmaGenericFunction,mmaPureFunction,mmaVariable |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 48 | " Variables: |
| 49 | " Dollar sign variables |
| 50 | syntax match mmaVariable "$\a\+\d*" |
| 51 | " Preceding contexts |
| 52 | syntax match mmaVariable "`\=\a\+\d*`" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 53 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 54 | " Numbers: |
| 55 | syntax match mmaNumber "\<\%(\d\+\.\=\d*\|\d*\.\=\d\+\)\>" |
| 56 | syntax match mmaNumber "`\d\+\>" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 57 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 58 | " Predefined Constants: |
| 59 | " to list all predefined Symbols would be too insane... |
| 60 | " it's probably smarter to define a select few, and get the rest from |
| 61 | " context if absolutely necessary. |
| 62 | " TODO - populate this with other often used Symbols |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 63 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 64 | " standard fixed symbols: |
| 65 | syntax keyword mmaVariable True False None Automatic All Null C General |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 66 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 67 | " mathematical constants: |
| 68 | syntax keyword mmaVariable Pi I E Infinity ComplexInfinity Indeterminate GoldenRatio EulerGamma Degree Catalan Khinchin Glaisher |
| 69 | |
| 70 | " stream data / atomic heads: |
| 71 | syntax keyword mmaVariable Byte Character Expression Number Real String Word EndOfFile Integer Symbol |
| 72 | |
| 73 | " sets: |
| 74 | syntax keyword mmaVariable Integers Complexes Reals Booleans Rationals |
| 75 | |
| 76 | " character classes: |
| 77 | syntax keyword mmaPattern DigitCharacter LetterCharacter WhitespaceCharacter WordCharacter EndOfString StartOfString EndOfLine StartOfLine WordBoundary |
| 78 | |
| 79 | " SelectionMove directions/units: |
| 80 | syntax keyword mmaVariable Next Previous After Before Character Word Expression TextLine CellContents Cell CellGroup EvaluationCell ButtonCell GeneratedCell Notebook |
| 81 | syntax keyword mmaVariable CellTags CellStyle CellLabel |
| 82 | |
| 83 | " TableForm positions: |
| 84 | syntax keyword mmaVariable Above Below Left Right |
| 85 | |
| 86 | " colors: |
| 87 | syntax keyword mmaVariable Black Blue Brown Cyan Gray Green Magenta Orange Pink Purple Red White Yellow |
| 88 | |
| 89 | " function attributes |
| 90 | syntax keyword mmaVariable Protected Listable OneIdentity Orderless Flat Constant NumericFunction Locked ReadProtected HoldFirst HoldRest HoldAll HoldAllComplete SequenceHold NHoldFirst NHoldRest NHoldAll Temporary Stub |
| 91 | |
| 92 | " Strings: |
| 93 | " "string" |
| 94 | " 'string' is not accepted (until literal strings are supported!) |
| 95 | syntax region mmaString start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+ |
| 96 | syntax region mmaCommentString oneline start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+ contained |
| 97 | |
| 98 | " Function Usage Messages: |
| 99 | " "SymbolName::item" |
| 100 | syntax match mmaMessage "$\=\a\+\d*::\a\+\d*" |
| 101 | |
| 102 | " Pure Functions: |
| 103 | syntax match mmaPureFunction "#\%(#\|\d\+\)\=" |
| 104 | syntax match mmaPureFunction "&" |
| 105 | |
| 106 | " Named Functions: |
| 107 | " Since everything is pretty much a function, get this straight |
| 108 | " from context |
| 109 | syntax match mmaGenericFunction "[A-Za-z0-9`]\+\s*\%([@[]\|/:\|/\=/@\)\@=" contains=mmaOperator |
| 110 | syntax match mmaGenericFunction "\~\s*[^~]\+\s*\~"hs=s+1,he=e-1 contains=mmaOperator,mmaBoring |
| 111 | syntax match mmaGenericFunction "//\s*[A-Za-z0-9`]\+"hs=s+2 contains=mmaOperator |
| 112 | |
| 113 | " Comment Keywords: |
| 114 | syntax keyword mmaTodo TODO NOTE HEY contained |
| 115 | syntax match mmaTodo "X\{3,}" contained |
| 116 | syntax keyword mmaFixme FIX[ME] FIXTHIS BROKEN contained |
| 117 | " yay pirates... |
| 118 | syntax match mmaFixme "\%(Y\=A\+R\+G\+\|GRR\+\|CR\+A\+P\+\)\%(!\+\)\=" contained |
| 119 | syntax match mmaemPHAsis "\(_\+\)[ a-zA-Z0-9]\+\1" contained |
| 120 | |
| 121 | " Comment Sections: |
| 122 | " this: |
| 123 | " :that: |
| 124 | syntax match mmaItem "\%(^[( |*\t]*\)\@<=\%(:\+\|\a\)[a-zA-Z0-9 ]\+:" contained contains=@mmaNotes |
| 125 | |
| 126 | " Actual Mathematica Comments: |
| 127 | " (* *) |
| 128 | " allow nesting (* (* *) *) even though the frontend |
| 129 | " won't always like it. |
| 130 | syntax region mmaComment start=+(\*+ end=+\*)+ skipempty contains=@mmaNotes,mmaItem,@mmaCommentStrings,mmaemPHAsis,mmaComment |
| 131 | |
| 132 | " Function Comments: |
| 133 | " just like a normal comment except the first sentance is Special ala Java |
| 134 | " (** *) |
| 135 | " TODO - fix this for nesting, or not... |
| 136 | syntax region mmaFunctionComment start="(\*\*\+" end="\*\+)" contains=@mmaNotes,mmaItem,mmaFunctionTitle,@mmaCommentStrings,mmaemPHAsis,mmaComment |
| 137 | syntax region mmaFunctionTitle contained matchgroup=mmaFunctionComment start="\%((\*\*[ *]*\)" matchgroup=mmaFunctionTitle keepend end=".[.!-]\=\s*$" end="[.!-][ \t\r<&]"me=e-1 end="\%(\*\+)\)\@=" contained contains=@mmaNotes,mmaItem,mmaCommentStar |
| 138 | |
| 139 | " catch remaining (**********)'s |
| 140 | syntax match mmaComment "(\*\*\+)" |
| 141 | " catch preceding * |
| 142 | syntax match mmaCommentStar "^\s*\*\+" contained |
| 143 | |
| 144 | " Patterns: |
| 145 | " Each pattern marker below can be Blank[] (_), BlankSequence[] (__) |
| 146 | " or BlankNullSequence[] (___). Most examples below can also be |
| 147 | " combined, for example Pattern tests with Default values. |
| 148 | " |
| 149 | " _Head Anonymous patterns |
| 150 | " name_Head |
| 151 | " name:(_Head|_Head2) Named patterns |
| 152 | " |
| 153 | " _Head : val |
| 154 | " name:_Head:val Default values |
| 155 | " |
| 156 | " _Head?testQ, |
| 157 | " _Head?(test[#]&) Pattern tests |
| 158 | " |
| 159 | " name_Head/;test[name] Conditionals |
| 160 | " |
| 161 | " _Head:. Predefined Default |
| 162 | " |
| 163 | " .. ... Pattern Repeat |
| 164 | |
| 165 | syntax match mmaPatternError "\%(_\{4,}\|)\s*&\s*)\@!\)" contained |
| 166 | |
| 167 | "pattern name: |
| 168 | syntax match mmaPattern "[A-Za-z0-9`]\+\s*:\+[=>]\@!" contains=mmaOperator |
| 169 | "pattern default: |
| 170 | syntax match mmaPattern ": *[^ ,]\+[\], ]\@=" contains=@mmaCommentStrings,@mmaTop,mmaOperator |
| 171 | "pattern head/test: |
| 172 | syntax match mmaPattern "[A-Za-z0-9`]*_\+\%(\a\+\)\=\%(?([^)]\+)\|?[^\]},]\+\)\=" contains=@mmaTop,@mmaCommentStrings,mmaPatternError |
| 173 | |
| 174 | " Operators: |
| 175 | " /: ^= ^:= UpValue |
| 176 | " /; Conditional |
| 177 | " := = DownValue |
| 178 | " == === || |
| 179 | " != =!= && Logic |
| 180 | " >= <= < > |
| 181 | " += -= *= |
| 182 | " /= ++ -- Math |
| 183 | " ^* |
| 184 | " -> :> Rules |
| 185 | " @@ @@@ Apply |
| 186 | " /@ //@ Map |
| 187 | " /. //. Replace |
| 188 | " // @ Function application |
| 189 | " <> ~~ String/Pattern join |
| 190 | " ~ infix operator |
| 191 | " . : Pattern operators |
| 192 | syntax match mmaOperator "\%(@\{1,3}\|//[.@]\=\)" |
| 193 | syntax match mmaOperator "\%(/[;:@.]\=\|\^\=:\==\)" |
| 194 | syntax match mmaOperator "\%([-:=]\=>\|<=\=\)" |
| 195 | "syntax match mmaOperator "\%(++\=\|--\=\|[/+-*]=\|[^*]\)" |
| 196 | syntax match mmaOperator "[*+=^.:?-]" |
| 197 | syntax match mmaOperator "\%(\~\~\=\)" |
| 198 | syntax match mmaOperator "\%(=\{2,3}\|=\=!=\|||\=\|&&\|!\)" contains=ALLBUT,mmaPureFunction |
| 199 | |
| 200 | |
| 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 |
| 212 | |
| 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | |
Bram Moolenaar | 34cdc3e | 2005-05-18 22:24:46 +0000 | [diff] [blame] | 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 |
| 246 | HiLink mmaOperator Operator |
| 247 | HiLink mmaPatternOp Operator |
| 248 | HiLink mmaPureFunction Operator |
| 249 | HiLink mmaVariable Identifier |
| 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 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 263 | |
| 264 | delcommand HiLink |
| 265 | endif |
| 266 | |
| 267 | let b:current_syntax = "mma" |