lilypond-user
[Top][All Lists]
Advanced

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

Re: Regexp Functions


From: Freeman Gilmore
Subject: Re: Regexp Functions
Date: Tue, 16 Jun 2020 10:17:23 -0400

On Tue, Jun 16, 2020 at 4:41 AM Aaron Hill <lilypond@hillvisions.com> wrote:
>
> On 2020-06-15 11:16 pm, Freeman Gilmore wrote:
> > "y" could represent  one of my accidentals, "-y" inverted.   "-ax3" ,
> > one of my accidentals ,
> > "-a" used 3 times; like a flag, but needs to be inverted to "-x3".
> > "+rx2" needs a space like "+r x2".   "t" standard accidental. All "+"
> > removed.
> > "-y -ax3 +rx2 -stx2 t" becomes "-y -a -x3 r x2 -st -x2 t" , then
> > convert to list
> >  ("-y" "-a" "-x3" "r" "x2" "-st" "-x2" "t").
>
> This is sounding much more like you have invented a language/grammar
> that needs to be parsed rather than simply wanting to apply some
> arbitrary text transformation.  The interest in string manipulation
> stems from wanting to support a form of shorthand within the microtonal
> ligature notation.
>
> To that end, allow me to present an alternate way to attack the problem.
>   Consider:
>
> ;;;;
> (apply append
>    (map (lambda (m)
>           (let ((inv (or (match:substring m 2) "")))
>             (map (lambda (s) (string-append inv s))
>                  (filter
>                    (lambda (s) (not (string-null? s)))
>                    (map (lambda (n) (or (match:substring m n) ""))
>                         '(3 4))))))
>         (list-matches
>           "((-)|\\+?)([a-z]*)(x[0-9]+)?"
>           "-y -ax3 +rx2 -stx2 t")))
> ;;;;
> ====
> ("-y" "-a" "-x3" "r" "x2" "-st" "-x2" "t")
> ====

\version "2.20.0"
 #(use-modules (ice-9 regex))

#(define V "-6 -ax3 +rx2 -31x2 t" )        %  note change, numbers as
well used for  names of accidentals

#(define W (apply append
   (map (lambda (m)
          (let ((inv (or (match:substring m 2) "")))
            (map (lambda (s) (string-append inv s))
                 (filter
                   (lambda (s) (not (string-null? s)))
                   (map (lambda (n) (or (match:substring m n) ""))
                        '(3 4))))))
     (list-matches
          "((-)|\\+?)([0-9]*|[a-z]*)(x[0-9]+)?"           %  do not
that this fool you, this chang is about
          V))))
%        the only thing I think i understand here

 #(write W)
==================
("-6" "-a" "-x3" "r" "x2" "-31" "-x2" "t")
==================
I am running out of time, but the mapping may be extended to include a
ruffer input that i have already
converted to the  form like V above using 4 steps.   May take awhile
to get back.

Thank you, ƒg

>
> Several assumptions are being made within the core regular expression
> above; but what is important to note is that we are not doing any text
> substitution of the original input.  Rather, we are using a regular
> expression to identify the valid "words" and extract the key parts of
> those words.  While you can certainly act upon the information right
> away, I am showing a way to build a list of strings that should meet
> your specification.
>
>
> -- Aaron Hill



reply via email to

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