lilypond-devel
[Top][All Lists]
Advanced

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

Re: Shortcut for \repeat unfold


From: Jean Abou Samra
Subject: Re: Shortcut for \repeat unfold
Date: Wed, 29 Sep 2021 08:33:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

Le 29/09/2021 à 01:50, Dan Eble a écrit :
On Sep 24, 2021, at 19:32, Jean Abou Samra <jean@abou-samra.fr> wrote:

Other possibilities:

- "\rep n music", not as self-telling (and I think Lukas
   only calls his shortcut \rep because redefining \repeat
   is not syntactically valid);
- "music * n", attractive but the difference between c1*5
   and { c1 } * 5 would be confusing; also, for longer passages
   one would rather state the number of repetitions from the
   start than having to remember to put it at the end;
- "\* n music", very short but doesn't read as nicely I think,
   and I don't view repeats as special enough to warrant
   this kind of syntax with many special characters.
Thoughts?
28x { d a b fs | g d g a }

https://gitlab.com/lilypond/lilypond/-/merge_requests/937

That is a clever proposal. I am already fond of it.
Thank you.


I like that, thanks!  Carl's concerns w.r.t. whitespace are valid,
though.  Would it be possible to make the invalid syntax '28 x'
produce a nice error message like

   invalid <whatever>,  did you mean '28x'?


It's not unconceivable to build whitespace into the
lexer pattern and have { 5 x c'1 } work.

diff --git a/lily/lexer.ll b/lily/lexer.ll
index a1556480d3..f13211cde1 100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -178,7 +178,7 @@ COMMAND             \\{SYMBOL}
 SPECIAL                [-+*/=<>{}!?_^'',.:]
 SHORTHAND      (.|\\.)
 UNSIGNED       {N}+
-REPEAT_COUNT    {UNSIGNED}x
+REPEAT_COUNT    {UNSIGNED}{WHITE}*x
 E_UNSIGNED     \\{N}+
 FRACTION       {N}+\/{N}+
 INT            -?{UNSIGNED}
@@ -582,7 +582,7 @@ FIG_ALT_EXPR {WHITE}*{FIG_ALT_SYMB}({FIG_ALT_SYMB}|{WHITE})*
                return UNSIGNED;
        }
        {REPEAT_COUNT}  {
-               yylval = scm_c_read_string (YYText ());
+               yylval = scan_repeat_count (YYText ());
                return REPEAT_COUNT;
        }
        \\\"    {
@@ -642,7 +642,7 @@ FIG_ALT_EXPR {WHITE}*{FIG_ALT_SYMB}({FIG_ALT_SYMB}|{WHITE})*
                return UNSIGNED;
        }
        {REPEAT_COUNT}  {
-               yylval = scm_c_read_string (YYText ());
+               yylval = scan_repeat_count (YYText ());
                return REPEAT_COUNT;
        }
        -  {
@@ -818,7 +818,7 @@ FIG_ALT_EXPR {WHITE}*{FIG_ALT_SYMB}({FIG_ALT_SYMB}|{WHITE})*
 }

 {REPEAT_COUNT} {
-       yylval = scm_c_read_string (YYText ());
+       yylval = scan_repeat_count (YYText ());
        return REPEAT_COUNT;
 }

@@ -1398,7 +1398,8 @@ scan_fraction (string frac)
 SCM
 scan_repeat_count (string s)
 {
-       s.pop_back (); // remove the 'x'
+       while (!isdigit (s.back ()))
+               s.pop_back (); // remove the 'x' and whitespace
        return scm_c_read_string (s.c_str ());
 }


What this means is that if you create a custom note
name language (with the undocumented not-yet-having-interface
#(set! language-pitch-names (acons 'mylang my-pitch-alist
language-pitch-names))), you won't be able to call a
note 'x', because

{ c4 x4 }

will be understood as

{ c 4x 4 }

I don't see that as a big deal. Using 'r' or 'R' or 'q'
as a note name is already not supported. To me, the
addition of this shorthand is worth a new element on
this list.

Thanks,
Jean



reply via email to

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