Re: regexp for scheme blocks in lilypond language

Federico Bruni <[email protected]> Thu, 02 Feb 2012 17:19:28 +0100
Newsgroups gmane.comp.gnu.source-highlight.general
Message-ID <[email protected]>
Il 31/01/2012 10:20, Lorenzo Bettini ha scritto:
> Sorry, I've been busy these days
>
> `#'?\((\(*)` @{1} + ")"
>
> the @{1} will refer to the grouped expression of the previous matched
> string, i.e., (\(*) which looks wrong to me...
>
> thus, the ending delimiter would try to match
>
> "()"
>
> which looks wrong to me...
>
Yyes, to me too :)
That's why I surprised it was working.

I think it was working because @{1} was useless.
I've found out that I don't need dynamic backreference. The following 
rule works fine (I think it's final):

environment scheme delim '#\'?\(' ")" multiline nested begin
   environment scheme delim "(" ")" multiline nested begin
     include "url.lang"
   end
end

Also, I've realized that the environment matches also single line 
strings. I need to add just this to cover all the cases:

scheme_value = '##(t|f)',
                '#\'?[[:alnum:]\.-]+'


> again, could you please provide some examples of strings that you need
> to match?

Yes, see example below (commented with %, as in LilyPond syntax):


%% Scheme big block: #(......)
#(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))))


%% Multiline scheme block in \paper: #'(.......)
\paper {
   score-system-spacing =
     #'((basic-distance . 12)
        (minimum-distance . 6)
        (padding . 1)
        (stretchability . 12))
}

%% Scheme strings (no multiline): #'(.......)
tagline =
     \markup {
       \override #'(box-padding . 1.0) \override #'(baseline-skip . 2.7) 
\box
       \center-column {
         \small \line { Sheet music from \with-url 
#"http://www.MutopiaProject.org"
           \line { \teeny www. \hspace #-0.5 MutopiaProject \hspace 
#-0.5 \teeny .org \hspace #0.5 }
         }
       }
     }

%% Scheme values
\hspace #0.5
ragged-right = ##t
print-page-number = ##f
\applyMusic #unfold-repeats