]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2931: Allow non-LilyPond identifiers like "violin1" to be called as \"violin1"
authorDavid Kastrup <dak@gnu.org>
Fri, 26 Oct 2012 12:34:43 +0000 (14:34 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 4 Oct 2013 10:07:55 +0000 (12:07 +0200)
A frequent complaint is the absence of identifiers with numbers in
them, like violin1.

Defining such identifiers has always been possible with

    "violin1" = { c''4 c c c }

This patch lets one actually use them by calling them as

    \"violin1"

lily/lexer.ll

index e896de3d638bc14a34c20037d7f72dfa4a9fae89..9a859e5a6a9f4852442eb9b98c7f3355017e35aa 100644 (file)
@@ -91,6 +91,15 @@ bool is_valid_version (string s);
                 yylval = SCM_EOL;               \
         } while (0)
 
+/*
+  The inside of \"violin1" is marked by commandquote mode
+*/
+
+#define start_command_quote() do {             \
+                yy_push_state (commandquote);  \
+                yylval = SCM_EOL;               \
+        } while (0)
+
 #define yylval (*lexval_)
 
 #define yylloc (*lexloc_)
@@ -124,6 +133,7 @@ SCM (* scm_parse_error_handler) (void *);
 %x markup
 %x notes
 %x quote
+%x commandquote
 %x sourcefileline
 %x sourcefilename
 %x version
@@ -503,7 +513,9 @@ BOM_UTF8    \357\273\277
        {WORD}  {
                return scan_bare_word (YYText_utf8 ());
        }
-
+       \\\"    {
+               start_command_quote ();
+       }
        {COMMAND}/[-_]  | // backup rule
        {COMMAND}       {
                return scan_escaped_word (YYText_utf8 () + 1); 
@@ -527,7 +539,7 @@ BOM_UTF8    \357\273\277
        }
 }
 
-<quote>{
+<quote,commandquote>{
        \\{ESCAPED}     {
                 char c = escaped_char (YYText ()[1]);
                yylval = scm_cons (scm_from_locale_stringn (&c, 1),
@@ -539,14 +551,19 @@ BOM_UTF8  \357\273\277
        }
        \"      {
 
-               yy_pop_state ();
-
                /* yylval is union. Must remember STRING before setting SCM*/
 
                 yylval = scm_string_concatenate_reverse (yylval,
                                                          SCM_UNDEFINED,
                                                          SCM_UNDEFINED);
 
+               if (get_state () == commandquote) {
+                       yy_pop_state ();
+                       return scan_escaped_word (ly_scm2string (yylval));
+               }
+
+               yy_pop_state ();
+
                return STRING;
        }
        \\      {
@@ -572,6 +589,9 @@ BOM_UTF8    \357\273\277
                yylval = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
+       \\\"    {
+               start_command_quote ();
+       }
        {COMMAND}/[-_]  | // backup rule
        {COMMAND}       {
                return scan_escaped_word (YYText_utf8 () + 1);
@@ -609,6 +629,9 @@ BOM_UTF8    \357\273\277
        {WORD}  {
                return scan_bare_word (YYText_utf8 ());
        }
+       \\\"    {
+               start_command_quote ();
+       }
        {COMMAND}/[-_]  | // backup rule
        {COMMAND}       {
                return scan_escaped_word (YYText_utf8 () + 1);
@@ -650,6 +673,9 @@ BOM_UTF8    \357\273\277
                 yylval = SCM_UNSPECIFIED;
                return SCORE;
        }
+       \\\"    {
+               start_command_quote ();
+       }
        {COMMAND}/[-_]  | // backup rule
        {COMMAND} {
                string str (YYText_utf8 () + 1);
@@ -718,7 +744,7 @@ BOM_UTF8    \357\273\277
                yy_pop_state ();
        }
 
-<quote><<EOF>> {
+<quote,commandquote><<EOF>> {
        LexerError (_ ("EOF found inside string").c_str ());
        yy_pop_state ();
 }
@@ -763,6 +789,9 @@ BOM_UTF8    \357\273\277
        {WORD}  {
                return scan_bare_word (YYText_utf8 ());
        }
+       \\\"    {
+               start_command_quote ();
+       }
        {COMMAND}/[-_]  | // backup rule
        {COMMAND}       {
                return scan_escaped_word (YYText_utf8 () + 1);