]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 5113/1: Reorganize Lily_lexer::scan_bare_word
authorDavid Kastrup <dak@gnu.org>
Sat, 1 Apr 2017 12:54:05 +0000 (14:54 +0200)
committerDavid Kastrup <dak@gnu.org>
Sun, 9 Apr 2017 15:53:32 +0000 (17:53 +0200)
This also redefines LilyPond's manners of converting simple
expressions into music, most notably checking drum types for being
defined before accepting them as note values.

lily/include/lily-lexer.hh
lily/lexer.ll
lily/parser.yy

index 626d24efa64ba2242afe7a1a5ab697941a3043e4..eb26403b006d428ef96242893fc70e64c833bab1 100644 (file)
@@ -38,6 +38,7 @@ public:
   SCM mark_smob () const;
   static const char * const type_p_name_;
   virtual ~Lily_lexer ();
+  int scan_word (SCM & output, SCM sym);
 private:
   int lookup_keyword (const string&);
   int scan_bare_word (const string&);
index 534823118034810f182efae2f71898f1f70d74cf..6bf0084c70707c0e116929ee189a508cfc51df86 100644 (file)
@@ -1004,16 +1004,15 @@ Lily_lexer::scan_scm_id (SCM sid)
 }
 
 int
-Lily_lexer::scan_bare_word (const string &str)
+Lily_lexer::scan_word (SCM & output, SCM sym)
 {
-       SCM sym = ly_symbol2scm (str.c_str ());
        if ((YYSTATE == notes) || (YYSTATE == chords)) {
                SCM handle = SCM_BOOL_F;
                if (scm_is_pair (pitchname_tab_stack_))
                        handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_stack_), sym);
 
                if (scm_is_pair (handle)) {
-                       yylval = scm_cdr (handle);
+                       output = scm_cdr (handle);
                        if (unsmob<Pitch> (yylval))
                            return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
                        else if (scm_is_symbol (yylval))
@@ -1022,10 +1021,22 @@ Lily_lexer::scan_bare_word (const string &str)
                else if ((YYSTATE == chords)
                        && scm_is_true (handle = scm_hashq_get_handle (chordmodifier_tab_, sym)))
                {
-                   yylval = scm_cdr (handle);
+                   output = scm_cdr (handle);
                    return CHORD_MODIFIER;
                }
        }
+       output = SCM_UNDEFINED;
+       return -1;
+}
+
+int
+Lily_lexer::scan_bare_word (const string &str)
+{
+       int state = scan_word (yylval, ly_symbol2scm (str.c_str ()));
+       if (state >= 0)
+       {
+               return state;
+       }
        yylval = ly_string2scm (str);
        return STRING;
 }
index d4ab27c2bb320b804e4b16862e2910da59298aa6..43037e404f67ff9d6a1fc64bd747d6e51eeda34e 100644 (file)
@@ -4262,13 +4262,29 @@ make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
 {
        if (unsmob<Music> (simple))
                return simple;
-       if (parser->lexer_->is_note_state ()) {
-               if (scm_is_symbol (simple)) {
+
+       if (scm_is_symbol (simple))
+       {
+               SCM out = SCM_UNDEFINED;
+               switch (parser->lexer_->scan_word (out, simple))
+               {
+               case DRUM_PITCH:
+               {
                        Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
                        n->set_property ("duration", parser->default_duration_.smobbed_copy ());
-                       n->set_property ("drum-type", simple);
+                       n->set_property ("drum-type", out);
                        return n->unprotect ();
                }
+               case NOTENAME_PITCH:
+               case TONICNAME_PITCH:
+                       // Take the parsed pitch
+                       simple = out;
+                       break;
+               // Don't scan CHORD_MODIFIER etc.
+               }
+       }
+
+       if (parser->lexer_->is_note_state ()) {
                if (unsmob<Pitch> (simple)) {
                        Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
                        n->set_property ("duration", parser->default_duration_.smobbed_copy ());