[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-source-highlight] regexp for scheme blocks in lilypond language

From: Federico Bruni
Subject: [Help-source-highlight] regexp for scheme blocks in lilypond language
Date: Wed, 18 Jan 2012 09:54:31 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:9.0) Gecko/20111222 Thunderbird/9.0.1


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:

#(ly:make-moment 120 4)

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)))
      ((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))))
      ((> 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:

(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,

Description: Text document

reply via email to

[Prev in Thread] Current Thread [Next in Thread]