regexp for scheme blocks in lilypond language
Federico Bruni <[email protected]> Wed, 18 Jan 2012 09:54:31 +0100
| Newsgroups | gmane.comp.gnu.source-highlight.general |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------040604080305080206040902
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
Hi,
lilypond files can contain blocks of scheme code in several ways.
The main challenge is handling conflicts between single and multiline
and especially blocks where the number of parentheses cannot be known in
advance (there's a way to match balanced parentheses?).
Scheme strings can be single line. 4 examples:
\applyMusic #unfold-repeats \bottom
\Score tempoWholesPerMinute = #(ly:make-moment 120 4)
system-system-spacing #'padding = #8
tagline = \markup { \override #'(box-padding . 1.0) \override
#'(baseline-skip . 2.7) { "Hello" } }
Strings that should be highlighted:
#unfold-repeats
#(ly:make-moment 120 4)
#'padding
any #'(\.) occurence in that single line
There are also two kinds of scheme blocks (I can match the first not the
second, because I cannot guess the number of parentheses):
#'((basic-distance . 12)
(minimum-distance . 6)
(padding . 1)
(stretchability . 12))
#(define (naturalize-pitch p)
(let ((o (ly:pitch-octave p))
(a (* 4 (ly:pitch-alteration p)))
;; alteration, a, in quarter tone steps,
;; for historical reasons
(n (ly:pitch-notename p)))
(cond
((and (> a 1) (or (eq? n 6) (eq? n 2)))
(set! a (- a 2))
(set! n (+ n 1)))
((and (< a -1) (or (eq? n 0) (eq? n 3)))
(set! a (+ a 2))
(set! n (- n 1))))
(cond
((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
(if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
(if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
(ly:make-pitch o n (/ a 4))))
This is very problematic because this kind of block is placed at the
beginning of a lilypond file and many snippets in the LilyPond
documentation have such blocks.
My current lilypond.lang can't handle it and all the highlighting gets
messed, see:
http://lists.gnu.org/archive/html/lilypond-user/2012-01/msg00013.html
(see also my reply to that email)
I attach also an example file.
Sorry for the confusion, I'm in a hurry.
Thanks in advance for your help,
Federico
--------------040604080305080206040902
Content-Type: text/plain;
name="test.ly"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="test.ly"
\version "2.14.2"
% Scheme big block: currently commented out because lilypond.lang
% can't handle it.
%{#(define (naturalize-pitch p)
(let ((o (ly:pitch-octave p))
(a (* 4 (ly:pitch-alteration p)))
;; alteration, a, in quarter tone steps,
;; for historical reasons
(n (ly:pitch-notename p)))
(cond
((and (> a 1) (or (eq? n 6) (eq? n 2)))
(set! a (- a 2))
(set! n (+ n 1)))
((and (< a -1) (or (eq? n 0) (eq? n 3)))
(set! a (+ a 2))
(set! n (- n 1))))
(cond
((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
(if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
(if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
(ly:make-pitch o n (/ a 4))))
%}
\header {
title = "Maple Leaf Rag"
composer = "Scott Joplin"
piece = "Tempo di marcia"
}
\paper {
top-margin = 15
bottom-margin = 10
system-system-spacing #'padding = #8
score-system-spacing =
#'((basic-distance . 12)
(minimum-distance . 6)
(padding . 1)
(stretchability . 12))
}
top = \relative c' {
\override TextScript #'padding = #2
\key as \major
\time 2/4
\clef treble
\partial 8
r8 \f |
\repeat volta 2 {
r16 as' <es' es,> as, c <es es,>8 g,16 |
<es' es,>16 g, bes <es es,> ~ <es es,>4 |
r16 as, <es' es,> as, c <es es,>8 g,16 |
<es' es,>16 g, bes <es es,> ~ <es es,>8 r16 <es es,> |
r16 as, ces <fes fes,> r16 <es es,> r16 <es es,> |
r16 as, ces <fes fes,> r16 <es es,> r8 |
\change Staff = "down"
\stemUp r16^\p as,,,-( ces as'-) r as-( ces as'-) \stemNeutral |
\change Staff = "up"
r16 as-( ces as'-) r as-( ces as'-) |
}
}
bottom = \relative c {
\key as \major
\time 2/4
\clef bass
\partial 8
<es es,>8 |
\repeat volta 2 {
<as as,> <c as es> <c as es> <a a,> |
<bes bes,> <des g, es> <des g, es> <es, es,> |
<as as,> <c as es> <c as es> <a a,> |
<bes bes,> <des g, es> <des g, es> <es, es,> |
<fes fes,>4 <es es,>8 <es es,> |
<fes fes,>4 <es es,>8 r |
\stemDown as,, r as' r \stemNeutral |
as' r as' r \clef treble |
}
}
\score {
\context PianoStaff <<
\context Staff = "up"
\applyMusic #unfold-repeats \top
\context Staff = "down"
\applyMusic #unfold-repeats \bottom
>>
\midi {
\context {
\Score tempoWholesPerMinute = #(ly:make-moment 120 4)
}
\context {
\Voice
\remove Dynamic_performer
}
}
\layout{}
}
--------------040604080305080206040902
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Help-source-highlight mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-source-highlight
--------------040604080305080206040902--