codekingpro/portable-devtools
114k
1" Vim syntax file2" Language: Mathematica3" Maintainer: steve layland <layland@wolfram.com>4" Last Change: 2012 Feb 03 by Thilo Six5" 2024 May 24 by Riley Bruins <ribru17@gmail.com> (remove 'commentstring')6" Source: http://members.wri.com/layland/vim/syntax/mma.vim7" http://vim.sourceforge.net/scripts/script.php?script_id=12738" Id: $Id: mma.vim,v 1.4 2006/04/14 20:40:38 vimboss Exp $9" NOTE:10"11" Empty .m files will automatically be presumed as Matlab files12" unless you have the following in your .vimrc:13"14" let filetype_m="mma"15"16" I also recommend setting the default 'Comment' highlighting to something17" other than the color used for 'Function', since both are plentiful in18" most mathematica files, and they are often the same color (when using19" background=dark).20"21" Credits:22" o Original Mathematica syntax version written by23" Wolfgang Waltenberger <wwalten@ben.tuwien.ac.at>24" o Some ideas like the CommentStar,CommentTitle were adapted25" from the Java vim syntax file by Claudio Fleiner. Thanks!26" o Everything else written by steve <layland@wolfram.com>27"28" Bugs:29" o Vim 6.1 didn't really have support for character classes30" of other named character classes. For example, [\a\d]31" didn't work. Therefore, a lot of this code uses explicit32" character classes instead: [0-9a-zA-Z]33"34" TODO:35" folding36" fix nesting37" finish populating popular symbols38 39" quit when a syntax file was already loaded40if exists("b:current_syntax")41 finish42endif43 44let s:cpo_save = &cpo45set cpo&vim46 47" Group Definitions:48syntax cluster mmaNotes contains=mmaTodo,mmaFixme49syntax cluster mmaComments contains=mmaComment,mmaFunctionComment,mmaItem,mmaFunctionTitle,mmaCommentStar50syntax cluster mmaCommentStrings contains=mmaLooseQuote,mmaCommentString,mmaUnicode51syntax cluster mmaStrings contains=@mmaCommentStrings,mmaString52syntax cluster mmaTop contains=mmaOperator,mmaGenericFunction,mmaPureFunction,mmaVariable53 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 from57" context if absolutely necessary.58" TODO - populate this with other often used Symbols59 60" standard fixed symbols:61syntax keyword mmaVariable True False None Automatic All Null C General62 63" mathematical constants:64syntax keyword mmaVariable Pi I E Infinity ComplexInfinity Indeterminate GoldenRatio EulerGamma Degree Catalan Khinchin Glaisher65 66" stream data / atomic heads:67syntax keyword mmaVariable Byte Character Expression Number Real String Word EndOfFile Integer Symbol68 69" sets:70syntax keyword mmaVariable Integers Complexes Reals Booleans Rationals71 72" character classes:73syntax keyword mmaPattern DigitCharacter LetterCharacter WhitespaceCharacter WordCharacter EndOfString StartOfString EndOfLine StartOfLine WordBoundary74 75" SelectionMove directions/units:76syntax keyword mmaVariable Next Previous After Before Character Word Expression TextLine CellContents Cell CellGroup EvaluationCell ButtonCell GeneratedCell Notebook77syntax keyword mmaVariable CellTags CellStyle CellLabel78 79" TableForm positions:80syntax keyword mmaVariable Above Below Left Right81 82" colors:83syntax keyword mmaVariable Black Blue Brown Cyan Gray Green Magenta Orange Pink Purple Red White Yellow84 85" function attributes86syntax keyword mmaVariable Protected Listable OneIdentity Orderless Flat Constant NumericFunction Locked ReadProtected HoldFirst HoldRest HoldAll HoldAllComplete SequenceHold NHoldFirst NHoldRest NHoldAll Temporary Stub87 88" Comment Sections:89" this:90" :that:91syntax match mmaItem "\%(^[( |*\t]*\)\@<=\%(:\+\|\w\)\w\+\%( \w\+\)\{0,3}:" contained contains=@mmaNotes92 93" Comment Keywords:94syntax keyword mmaTodo TODO NOTE HEY contained95syntax match mmaTodo "X\{3,}" contained96syntax keyword mmaFixme FIX[ME] FIXTHIS BROKEN contained97syntax match mmaFixme "BUG\%( *\#\=[0-9]\+\)\=" contained98" yay pirates...99syntax match mmaFixme "\%(Y\=A\+R\+G\+\|GRR\+\|CR\+A\+P\+\)\%(!\+\)\=" contained100 101" EmPHAsis:102" this unnecessary, but whatever :)103syntax match mmaemPHAsis "\%(^\|\s\)\([_/]\)[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*\1\%(\s\|$\)" contained contains=mmaemPHAsis104syntax match mmaemPHAsis "\%(^\|\s\)(\@<!\*[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]\+\)*)\@!\*\%(\s\|$\)" contained contains=mmaemPHAsis105 106" Regular Comments:107" (* *)108" allow nesting (* (* *) *) even though the frontend109" won't always like it.110syntax region mmaComment start=+(\*+ end=+\*)+ skipempty contains=@mmaNotes,mmaItem,@mmaCommentStrings,mmaemPHAsis,mmaComment111 112" Function Comments:113" just like a normal comment except the first sentence is Special ala Java114" (** *)115" TODO - fix this for nesting, or not...116syntax region mmaFunctionComment start="(\*\*\+" end="\*\+)" contains=@mmaNotes,mmaItem,mmaFunctionTitle,@mmaCommentStrings,mmaemPHAsis,mmaComment117syntax region mmaFunctionTitle contained matchgroup=mmaFunctionComment start="\%((\*\*[ *]*\)" matchgroup=mmaFunctionTitle keepend end=".[.!-]\=\s*$" end="[.!-][ \t\r<&]"me=e-1 end="\%(\*\+)\)\@=" contained contains=@mmaNotes,mmaItem,mmaCommentStar118 119" catch remaining (**********)'s120syntax match mmaComment "(\*\*\+)"121" catch preceding *122syntax match mmaCommentStar "^\s*\*\+" contained123 124" Variables:125" Dollar sign variables126syntax match mmaVariable "\$\a\+[0-9a-zA-Z$]*"127 128" Preceding and Following Contexts129syntax match mmaVariable "`[a-zA-Z$]\+[0-9a-zA-Z$]*" contains=mmaVariable130syntax match mmaVariable "[a-zA-Z$]\+[0-9a-zA-Z$]*`" contains=mmaVariable131 132" Strings:133" "string"134" 'string' is not accepted (until literal strings are supported!)135syntax region mmaString start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+136syntax region mmaCommentString oneline start=+\\\@<!"+ skip=+\\\@<!\\\%(\\\\\)*"+ end=+"+ contained137 138 139" Patterns:140" Each pattern marker below can be Blank[] (_), BlankSequence[] (__)141" or BlankNullSequence[] (___). Most examples below can also be142" combined, for example Pattern tests with Default values.143"144" _Head Anonymous patterns145" name_Head146" name:(_Head|_Head2) Named patterns147"148" _Head : val149" name:_Head:val Default values150"151" _Head?testQ,152" _Head?(test[#]&) Pattern tests153"154" name_Head/;test[name] Conditionals155"156" _Head:. Predefined Default157"158" .. ... Pattern Repeat159 160syntax match mmaPatternError "\%(_\{4,}\|)\s*&\s*)\@!\)" contained161 162"pattern name:163syntax match mmaPattern "[A-Za-z0-9`]\+\s*:\+[=>]\@!" contains=mmaOperator164"pattern default:165syntax match mmaPattern ": *[^ ,]\+[\], ]\@=" contains=@mmaCommentStrings,@mmaTop,mmaOperator166"pattern head/test:167syntax match mmaPattern "[A-Za-z0-9`]*_\+\%(\a\+\)\=\%(?([^)]\+)\|?[^\]},]\+\)\=" contains=@mmaTop,@mmaCommentStrings,mmaPatternError168 169" Operators:170" /: ^= ^:= UpValue171" /; Conditional172" := = DownValue173" == === ||174" != =!= && Logic175" >= <= < >176" += -= *=177" /= ++ -- Math178" ^*179" -> :> Rules180" @@ @@@ Apply181" /@ //@ Map182" /. //. Replace183" // @ Function application184" <> ~~ String/Pattern join185" ~ infix operator186" . : Pattern operators187syntax match mmaOperator "\%(@\{1,3}\|//[.@]\=\)"188syntax match mmaOperator "\%(/[;:@.]\=\|\^\=:\==\)"189syntax match mmaOperator "\%([-:=]\=>\|<=\=\)"190"syntax match mmaOperator "\%(++\=\|--\=\|[/+-*]=\|[^*]\)"191syntax match mmaOperator "[*+=^.:?-]"192syntax match mmaOperator "\%(\~\~\=\)"193syntax match mmaOperator "\%(=\{2,3}\|=\=!=\|||\=\|&&\|!\)" contains=ALLBUT,mmaPureFunction194 195" Symbol Tags:196" "SymbolName::item"197"syntax match mmaSymbol "`\=[a-zA-Z$]\+[0-9a-zA-Z$]*\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*" contained198syntax match mmaMessage "`\=\([a-zA-Z$]\+[0-9a-zA-Z$]*\)\%(`\%([a-zA-Z$]\+[0-9a-zA-Z$]*\)\=\)*::\a\+" contains=mmaMessageType199syntax match mmaMessageType "::\a\+"hs=s+2 contained200 201" Pure Functions:202syntax match mmaPureFunction "#\%(#\|\d\+\)\="203syntax match mmaPureFunction "&"204 205" Named Functions:206" Since everything is pretty much a function, get this straight207" from context208syntax match mmaGenericFunction "[A-Za-z0-9`]\+\s*\%([@[]\|/:\|/\=/@\)\@=" contains=mmaOperator209syntax match mmaGenericFunction "\~\s*[^~]\+\s*\~"hs=s+1,he=e-1 contains=mmaOperator,mmaBoring210syntax match mmaGenericFunction "//\s*[A-Za-z0-9`]\+"hs=s+2 contains=mmaOperator211 212" Numbers:213syntax match mmaNumber "\<\%(\d\+\.\=\d*\|\d*\.\=\d\+\)\>"214syntax match mmaNumber "`\d\+\%(\d\@!\.\|\>\)"215 216" Special Characters:217" \[Name] named character218" \ooo octal219" \.xx 2 digit hex220" \:xxxx 4 digit hex (multibyte unicode)221syntax match mmaUnicode "\\\[\w\+\d*\]"222syntax match mmaUnicode "\\\%(\x\{3}\|\.\x\{2}\|:\x\{4}\)"223 224" Syntax Errors:225syntax match mmaError "\*)" containedin=ALLBUT,@mmaComments,@mmaStrings226syntax match mmaError "\%([/]{3,}\|[&:|+*?~-]\{3,}\|[.=]\{4,}\|_\@<=\.\{2,}\|`\{2,}\)" containedin=ALLBUT,@mmaComments,@mmaStrings227 228" Punctuation:229" things that shouldn't really be highlighted, or highlighted230" in they're own group if you _really_ want. :)231" ( ) { }232" TODO - use Delimiter group?233syntax match mmaBoring "[(){}]" contained234 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 fold242 243" Lists:244" (fold)245"syntax region mmaLists start="{" end="}" containedin=ALLBUT,@mmaComments,@mmaStrings transparent fold246 247" Regions:248" (fold)249"syntax region mmaRegion start="(\*\+[^<]*<!--[^>]*\*\+)" end="--> \*)" containedin=ALLBUT,@mmaStrings transparent fold keepend250 251" show fold text252"set foldtext=MmaFoldText()253 254"function MmaFoldText()255" let line = getline(v:foldstart)256"257" let lines = v:foldend-v:foldstart+1258"259" let sub = substitute(line, '(\*\+|\*\+)|[-*_]\+', '', 'g')260"261" if match(line, '(\*') != -1262" let lines = lines.' line comment'263" else264" let lines = lines.' lines'265" endif266"267" return v:folddashes.' '.lines.' '.sub268"endf269 270"this is slow for computing folds, but it does so accurately271syntax sync fromstart272 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 comments278"syntax sync match syncComments groupthere NONE "\*)"279"syntax sync match syncComments groupthere mmaComment "(\*"280 281"set foldmethod=syntax282"set foldnestmax=1283"set foldminlines=15284 285 286" NOTE - the following links are not guaranteed to287" look good under all colorschemes. You might need to288" :so $VIMRUNTIME/syntax/hitest.vim and tweak these to289" look good in yours290 291 292hi def link mmaComment Comment293hi def link mmaCommentStar Comment294hi def link mmaFunctionComment Comment295hi def link mmaLooseQuote Comment296hi def link mmaGenericFunction Function297hi def link mmaVariable Identifier298" hi def link mmaSymbol Identifier299hi def link mmaOperator Operator300hi def link mmaPatternOp Operator301hi def link mmaPureFunction Operator302hi def link mmaString String303hi def link mmaCommentString String304hi def link mmaUnicode String305hi def link mmaMessage Type306hi def link mmaNumber Type307hi def link mmaPattern Type308hi def link mmaError Error309hi def link mmaFixme Error310hi def link mmaPatternError Error311hi def link mmaTodo Todo312hi def link mmaemPHAsis Special313hi def link mmaFunctionTitle Special314hi def link mmaMessageType Special315hi def link mmaItem Preproc316 317 318let b:current_syntax = "mma"319 320let &cpo = s:cpo_save321unlet s:cpo_save322 