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: Sat, 20 Jun 2020 11:51:21 -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")
> ====
>
> 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

Aaron:

I wish I had more time to stay on this, with the good help I am
getting.     Looks like mapping is the better way to go.    There is
some more information to be included if mapping is used that cannot be
pleased in as I am learning.    Simple string manipulation I can do;
but reading about regular expressions does not give me the intuitive
ability to manipulate them without a lot more study, with my wrote
memory a lot more time.    So help with this would be appreciated.

Input string:

1.  input example  \j "-y    -ax3    rex2 -31x2 es accidentalFlat+6 "

2.  “-“ is part of the name of the accidental and can represent the
name of an inverted accidental.

3.  size of white space is not important

4.  the accidentals are separated by “ “, “+”, “ +”; “-“, “  -“   (“-“
is part of the name of the accidental)

5.  accidentals are of the form “…” or “-…”  with rang [0 - 9]*|[a –
z]*|[A – Z]* (abbreviated or full name)

 6.  accidentals that are applied more than one time can be ligatures
“…xn”; “-…xn” , rang of n 2 – 5, (no “-x” or “-n”)


Output list of strings:

1.  order of accidentals to be maintained

2.  “+” are eliminated

3.  “-“ are retained   (part of name of accidental)

4.  accidentals are of the form “…” or “-…”  with rang [0 - 9]*|[a –
z]*|[A – Z]*

5.  “…xn” => “…” “xn”  (will form a true ligature)

6.  “-…xn” => “-…” “-xn”  (will form a true ligature)

7.  So far, each accidental has no space between them, add an “SP”
between each split

     except “…” “xn”  and “-…” “-xn”  (the true ligatures),  “Sp” is a
narrow blank glyph.

8.  Output example: ("-y” “Sp” “-a” “-x3 “Sp” “re” “x2” “Sp” “-st”
“-x2” “Sp” “es” “Sp” “accidentalFlat” “Sp” “6”)


Simple string manipulation does not get me what I also need to handle
the ligatures in the following.

"-y    -ax3    rx2 -31x2 es accidentalFlat+6"  => (-y (* -a 3) (* re
2) (* -v31 2) es accidentalFlat +v6) , here the “-“ is not part of the
name of the variable, but just give a negative value to it.  Note v’s
are added to string names that are numbers to create a variable, “+6”
=> +v6, or => v6,   Also +’s can be retained or not.

I will then ‘apply +’ to this list.   So would this work instead, =>
(+ -y (* -a 3) (* re 2) (* -v31 2) es accidentalFlat +v6)


I have developed a system of accidental that I want to try, and I want
the program to be usable for other systems as well.

I would be using short names for my accidentals (some numbers if I do
not have a problem with them, they work so far).   Inverted
accidentals have “-“ added to the name of the glyph.   An accidental
used more than one time is a ligature.    The input accidentals are
separated by “ “ or “+” and “-“ for inverted accidentals, being part
of the name.

Thank you, ƒg



reply via email to

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