Source

abc-vim / src / syntax / abc.vim

Full commit
" Vim syntax file
" Language: abc music notation
" Maintainer: Lee Savide <laughingman182@yahoo.com>
" License: http://apache.org/licenses/LICENSE-2.0.txt

if version < 600
    syntax clear
elseif exists('b:current_syntax')
    finish
endif

syn include @PS <sfile>:p:h/postscr.vim

syn case ignore
syn match abcInteger '\<[+-]\=\d\+\>' contained
syn match abcFloat '\<[+-]\=\d\+\.\>' contained
syn match abcFloat '\<[+-]\=\d\+\.\d*\(e[+-]\=\d\+\)\=\>' contained
syn match abcFloat '\<[+-]\=\.\d\+\(e[+-]\=\d\+\)\=\>' contained
syn match abcFloat '\<[+-]\=\d\+e[+-]\=\d\+\>' contained
syn cluster abcNumber contains=abcInteger,abcFloat

syn keyword abcMode maj[or] m[inor] ion[ian] aeo[lian] mix[olydian] dor[ian] phr[ygian] lyd[ian] loc[rian]
syn case match

syn region abcFreeText excludenl start='^\s*$' skip='\%(\)\@<!' excludenl end='^\s*$' transparent

syn keyword abcDirectiveKeyword contained abc2pscompat alignbars aligncomposer
            \ annotationfont autoclef barnumbers barsperstaff breakoneoln
            \ bgcolor botmargin bstemdown cancelkey comball combinevoices
            \ composerfont composerspace contbarnb continueall custos dateformat
            \ deco decoration dynalign dynamic encoding flatbeams font footer
            \ footerfont format gchord gchordbox gchordfont graceslurs
            \ gracespace gstemdir header headerfont historyfont hyphenfont
            \ indent infofont infoline infoname infospace landscape leftmargin
            \ linebreak lineskipfac linewarn maxshrink maxstaffsep
            \ maxsysstaffsep measurebox measurefirst measurefont measurenb
            \ micronewps musiconly musicspace notespacingfactor oneperpage
            \ ornament pageheight pagewidth pango parskipfac partsbox partsfont
            \ partsspace pdfmark repeatfont rightmargin scale setdefl setfont-1
            \ setfont-2 setfont-3 setfont-4 shiftunisson slurheight splittune
            \ squarebreve staffnonote staffsep staffwidth stemdir stemheight
            \ straightflags stretchlast stretchstaff subtitlefont subtitlespace
            \ sysstaffsep tempofont textfont textoption textspace timewarn
            \ titlecaps titlefont titleformat titleleft titlespace titletrim
            \ topmargin tuplets vocal vocalabove vocalfont voicefont volume
            \ wordsfont writefields break clip select tune voice clef newpage
            \ repbra repeat score sep setbarnb staff staffbreak staves tablature
            \ transpose vskip EPS multicol MIDI
syn match abcDirective excludenl '%%postscript\s\+.*$' contains=@PS
syn match abcDirective excludenl '%%\K\k*\s\+.*$' contains=abcDirective.*
syn keyword abcMIDIGlobalKeyword contained C nobarlines barlines fermatafixed
            \ fermataproportional ratio chordname deltaloudness
syn keyword abcMIDIKeyword contained bassprog beat beataccents beatmod
            \ beatstring chordattack chordprogram control droneon droneoff drum
            \ drumon drumoff drumbars drummap gchord grace gracedivider
            \ makechordchannels nobeataccents pitchblend portamento program
            \ ptstress randomchordattack ratio stressmodel snt tfranspose
            \ temperament temperamentlinear termperamentnormal
            \ transpose trim
syn match abcMIDIDirective excludenl '%%MIDI\s\+\K\k*\%(\s\+.*\)\=$' contains=abcMIDI.*

syn match abcRegexIgnore contained transparent
            \ '\\^\|\\$\|\\|\|\\.\|\\*\|\\?\|\\+\|\\\[\|\\\]\|\\(\|\\)'
syn match abcRegexOperator contained '^\|$\||\|.\|*\|?\|+\|\[^\=\|\]\|(\|)'
syn match abcRegexCharacter contained '\\x\x\{,2}'
syn region abcRegex start='%%\%(select\|tune\|voice\)\s\+' excludenl end='$' contains=abcRegex.* contained

syn match abcTypeSet excludenl '%%text .*$'
syn match abcTypeSet excludenl '%%center .*$'
syn region abcTypeSet excludenl keepend matchgroup=abcTypeSetKeyword
            \ start='%%begintext\s\+\%(obeylines\|align\|justify\|ragged\|fill\|center\|skip\|right\)\='
            \ end='%%endtext'
syn match abcTypeSet excludenl '%%endtext'
syn match abcTypeSetBegin excludenl '%%begin' contained
syn match abcTypeSetEnd '%%end' contained
syn region abcTypeSet matchgroup=abcTypeSetBegin start='%%begintext' skip='^\%(%%\)\=.*' matchgroup=abcTypeSetEnd end='%%endtext'
syn match abcTypeSetKeyword contained
            \ '%%\%(begintext\|endtext\|beginps\|endps\|beginsvg\|endsvg\)'

syn match abcDirectiveArgument excludenl '[^%]*$' contained
syn match abcDirectiveStatement '%%\K\k* ' nextgroup=abcDirectiveArgument skipwhite

syn match abcField '^\a:[^%]*' nextgroup=abcFieldContinue skipnl skipwhite
syn match abcFieldError '\%(^X:[^%]*\)\{2,}'
syn match abcFieldContinue '^+:[^%]*'

" Body {{{
syn match abcKeyIdentifier '[A-G][b#]\=' contained nextgroup=abcMode,abcExplicit skipwhite
syn region abcKeyExplicit start='\%(exp\)\=\( [_=^][a-g]\)*' contained

syn match abcRest 'z' contained nextgroup=abcNoteLength
syn match abcRest 'Z\%([1-9]*\d*\)\=' contained
syn match abcNote '[A-Ga-g][_=^]\{,2}' contained nextgroup=abcOctave
syn match abcOctave +[,']*+ contained nextgroup=abcNoteLength
syn match abcNoteLength '*[1-9]*\d*/[248]\=' contained
syn match abcTie +- \=+ contained
syn match abcSlur '(\|)' contained

syn match abcBar '|\|\]\|\['  contained
syn match abcRepeat '[:|][:|]' contained
syn match abcRepeat ':|[1-9]\%([,-][1-9]\d*\)\=' contained
syn match abcRepeat '|[1-9]\%([,-][1-9]\d*\)\=' contained
syn match abcRepeat '\[[1-9]\%([,-][1-9]\d*\)\=' contained








" }}}
" TopLevel {{{
syn match abcSpecialComment '^%abc\%(-[1-9]\.\d\)\='
syn region abcFileHeader start='\%(^[\a+]:\)' excludenl end='\^s*$' contained contains=abcComment
syn region abcTuneHeader start='\%(^X:.*\)\{1}\%(^T:.*\)*' end='^K:'
" Negative lookbehind is fine, since it looks for lines that aren't empty
syn match abcComment excludenl '%\{1}.*$'
syn match abcPreProc '%%\K\k*' contains=abcDirectiveKeyword

" }}}
" Syncing {{{
syn sync linecont '\\$'
syn sync match abcSlurSync grouphere abcSlur '([^\d]*'
syn sync match abcSlurSync groupthere abcSlur ')'
syn sync match abcTuneHeaderSync grouphere abcKeyField '^X:'
syn sync match abcTypeSetSync grouphere abcTypeSetBegin '%%end'
syn sync match abcTypeSetSync groupthere abcTypeSetEnd '%%begin'
syn sync match abcFileHeaderSync groupthere abcSpecialComment '\%(^\s*$\)\@<!'
" }}}

" Highlighting {{{
if version >= 508 || !exists('did_abc_syn_inits')
  if version < 508
    let did_abc_syn_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink abcComment           Comment
  HiLink abcInteger           Integer
  HiLink abcFloat             Float
  HiLink abcHeaderField       Type
  HiLink abcBodyField         Type
  HiLink abcBar               Operator
  HiLink abcTuple             Operator
  HiLink abcBroken            Operator
  HiLink abcTie               Operator
  HiLink abcChord             Operator
  HiLink abcNote              Statement

  delcommand HiLink
endif " }}}

let b:current_syntax = 'abc'
" vim: ts=4