Vim regex for bar lines and repeats?

For discussions about the abc notation standard
laughingman182
Posts: 18
Joined: Fri Oct 21, 2011 9:06 am
Humanity check: a real person
How many letters in "spam" (4)?: 3
Contact:

Vim regex for bar lines and repeats?

Postby laughingman182 » Tue May 22, 2012 8:46 pm

Hey everyone. I was wondering if there was a way to properly provide a regular expression match for bar lines and repeating measure regions for Vim to give an accurate syntax highlight for those sections. I'm trying to update the syntax file for abc, and I'd like to add features so it's easier to write code in abc. It's not like highlighting is the only thing Vim can do. Any help would be REALLY helpful; I'm trying to be constructive somehow; I really do want abc to grow Into something really powerful and be able to distinguish it as a programming language in it's own right(not that it isn't one already :>). Also, is it possible to get gettext support for the string values? It'd probably make internationalization easier. Just some food for thought.

Thanks in advance.
Last edited by laughingman182 on Fri May 25, 2012 4:43 pm, edited 1 time in total.
- Lee S.

laughingman182
Posts: 18
Joined: Fri Oct 21, 2011 9:06 am
Humanity check: a real person
How many letters in "spam" (4)?: 3
Contact:

Re: Vim regex for bar lines and repeats?

Postby laughingman182 » Wed May 23, 2012 9:26 pm

OH RIGHT; Some example code of what I've been doing might help:

Code: Select all

syntax match Bar '\.\=\(:*\[*|\{1}\]*\(:*\|[1-9]\{-1}\(\(,\|-\)*[1-9]\{-1}\)*\)\)\|\(\[|\=\]\)\|\(:\{1}\)' contained nextgroup=AbcElement skipwhite skipnl containedin=MusicCode,SimpleRepeat,ComplexRepeat
" For simple repeats, use the backreference to match the same number of ':' used at the beginning of the repeat
syntax region SimpleRepeat start='|\(:\+\)' skip='::' end='\1|' keepend contained nextgroup=AbcElement skipwhite skipnl contains=AbcElement,Bar containedin=MusicCode
syntax region ComplexRepeat start='|:' skip='::' end=':|\[\([1-9]\)\=' keepend contained nextgroup=AbcElement skipwhite skipnl contains=AbcElement,Bar,SimpleRepeat containedin=MusicCode

The regex I've given for matching bars is based off the BNF for abc 2.0 made by Henrik Norbeck.
- Lee S.

laughingman182
Posts: 18
Joined: Fri Oct 21, 2011 9:06 am
Humanity check: a real person
How many letters in "spam" (4)?: 3
Contact:

Re: Vim regex for bar lines and repeats?

Postby laughingman182 » Fri May 25, 2012 4:43 pm

I'll have to remember to read the documentation first before asking silly questions. ._. Oh well. Here's the code I've got now:
Bars:

Code: Select all

syntax match Bar '\(\(\[\||\)\|:*\)|\||\{1,2}' contained containedin=MusicCode nextgroup=AbcElement skipwhite

Repeats:

Code: Select all

syntax region Repeat start=':*|\||:*' skip='::\|:|:\|:||:\|\(\[\||\)[1-9]' end='||\|\[|\||\]\|:*\1' keepend contained containedin=MusicCode contains=AbcElement,Bar,Slur


If this interests you, I'm hosting this here.
- Lee S.


Return to “Standard”

Who is online

Users browsing this forum: No registered users and 1 guest