]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
Eliminate MARKUP_IDENTIFIER and MARKUPLIST_IDENTIFIER
[lilypond.git] / lily / parser.yy
index a50957fa8bb07ba2f07bf3ab0daa1f1133f229ca..13f071a2881286008e95e752b23fa638698ed9f9 100644 (file)
@@ -225,6 +225,7 @@ SCM get_next_unique_lyrics_context_id ();
 static Music *make_music_with_input (SCM name, Input where);
 SCM check_scheme_arg (Lily_parser *parser, Input loc,
                      SCM arg, SCM args, SCM pred);
+SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
 SCM loc_on_music (Input loc, SCM arg);
 SCM make_chord_elements (Input loc, SCM pitch, SCM dur, SCM modification_list);
 SCM make_chord_step (SCM step, Rational alter);
@@ -232,7 +233,6 @@ SCM make_simple_markup (SCM a);
 bool is_duration (int t);
 bool is_regular_identifier (SCM id);
 int yylex (YYSTYPE *s, YYLTYPE *loc, Lily_parser *parser);
-void set_music_properties (Music *p, SCM a);
 
 %}
 
@@ -363,7 +363,6 @@ If we give names, Bison complains.
 %token FRACTION
 %token LYRICS_STRING
 %token LYRIC_ELEMENT
-%token LYRIC_MARKUP_IDENTIFIER
 %token MARKUP_FUNCTION
 %token MARKUP_LIST_FUNCTION
 %token MARKUP_IDENTIFIER
@@ -446,6 +445,24 @@ toplevel_expression:
                SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
                scm_call_2 (proc, parser->self_scm (), $1);
        }
+       | SCM_TOKEN {
+               // Evaluate and ignore #xxx, as opposed to \xxx
+               parser->lexer_->eval_scm_token ($1);
+       }
+       | embedded_scm_active
+       {
+               SCM out = SCM_UNDEFINED;
+               if (Text_interface::is_markup ($1))
+                       out = scm_list_1 ($1);
+               else if (Text_interface::is_markup_list ($1))
+                       out = $1;
+               if (scm_is_pair (out))
+               {
+                       SCM proc = parser->lexer_->lookup_identifier ("toplevel-text-handler");
+                       scm_call_2 (proc, parser->self_scm (), out);
+               } else if (!scm_is_eq ($1, SCM_UNSPECIFIED))
+                       parser->parser_error (@1, _("bad expression type"));
+       }
        | output_def {
                SCM id = SCM_EOL;
                Output_def * od = unsmob_output_def ($1);
@@ -469,6 +486,11 @@ embedded_scm_bare:
        | SCM_IDENTIFIER
        ;
 
+embedded_scm_active:
+       SCM_IDENTIFIER
+       | scm_function_call
+       ;
+
 embedded_scm_bare_arg:
        embedded_scm_bare
        | STRING
@@ -531,6 +553,9 @@ lilypond_header_body:
        /* empty */ { $$ = SCM_UNSPECIFIED; }
        | lilypond_header_body assignment  {
 
+       }
+       | lilypond_header_body embedded_scm  {
+
        }
        ;
 
@@ -558,7 +583,6 @@ assignment:
                parser->lexer_->set_identifier (path, $4);
                 $$ = SCM_UNSPECIFIED;
        }
-       | embedded_scm { $$ = SCM_UNSPECIFIED; }
        ;
 
 
@@ -687,11 +711,28 @@ book_body:
                SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
                scm_call_2 (proc, $1, $2);
        }
+       | book_body SCM_TOKEN {
+               // Evaluate and ignore #xxx, as opposed to \xxx
+               parser->lexer_->eval_scm_token ($2);
+       }
+       | book_body embedded_scm_active
+       {
+               SCM out = SCM_UNDEFINED;
+               if (Text_interface::is_markup ($2))
+                       out = scm_list_1 ($2);
+               else if (Text_interface::is_markup_list ($2))
+                       out = $2;
+               if (scm_is_pair (out))
+               {
+                       SCM proc = parser->lexer_->lookup_identifier ("book-text-handler");
+                       scm_call_2 (proc, $1, out);
+               } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
+                       parser->parser_error (@2, _("bad expression type"));
+       }
        | book_body
        {
                parser->lexer_->add_scope (unsmob_book ($1)->header_);
        } lilypond_header
-       | book_body embedded_scm { }
        | book_body error {
                 Book *book = unsmob_book ($1);
                book->paper_ = 0;
@@ -737,6 +778,24 @@ bookpart_body:
                SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
                scm_call_2 (proc, $1, $2);
        }
+       | bookpart_body SCM_TOKEN {
+               // Evaluate and ignore #xxx, as opposed to \xxx
+               parser->lexer_->eval_scm_token ($2);
+       }
+       | bookpart_body embedded_scm_active
+       {
+               SCM out = SCM_UNDEFINED;
+               if (Text_interface::is_markup ($2))
+                       out = scm_list_1 ($2);
+               else if (Text_interface::is_markup_list ($2))
+                       out = $2;
+               if (scm_is_pair (out))
+               {
+                       SCM proc = parser->lexer_->lookup_identifier ("bookpart-text-handler");
+                       scm_call_2 (proc, $1, out);
+               } else if (!scm_is_eq ($2, SCM_UNSPECIFIED))
+                       parser->parser_error (@2, _("bad expression type"));
+       }
        | bookpart_body
        {
                 Book *book = unsmob_book ($1);
@@ -744,7 +803,6 @@ bookpart_body:
                        book->header_ = ly_make_module (false);
                parser->lexer_->add_scope (book->header_);
        } lilypond_header
-       | bookpart_body embedded_scm { }
        | bookpart_body error {
                 Book *book = unsmob_book ($1);
                book->paper_ = 0;
@@ -879,6 +937,9 @@ output_def_body:
        }
        | output_def_body assignment  {
 
+       }
+       | output_def_body embedded_scm  {
+
        }
        | output_def_body
        {
@@ -962,13 +1023,9 @@ music_embedded:
 music_arg:
        simple_music
        {
-               if (unsmob_pitch ($1)) {
-                       Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
-                       n->set_property ("pitch", $1);
-                       n->set_property ("duration",
-                                        parser->default_duration_.smobbed_copy ());
-                       $$ = n->unprotect ();
-               }
+               $$ = make_music_from_simple (parser, @1, $1);
+                if (!unsmob_music ($$))
+                        parser->parser_error (@1, _ ("music expected"));
        }
        | composite_music %prec COMPOSITE
        ;
@@ -1876,16 +1933,7 @@ simple_string: STRING {
        | LYRICS_STRING {
                $$ = $1;
        }
-       | MARKUP_IDENTIFIER
-       {
-               if (scm_is_string ($1)) {
-                       $$ = $1;
-               } else {
-                       parser->parser_error (@1, (_ ("simple string expected")));
-                       $$ = scm_string (SCM_EOL);
-               }
-       }
-       | LYRIC_MARKUP_IDENTIFIER
+       | embedded_scm_bare
        {
                if (scm_is_string ($1)) {
                        $$ = $1;
@@ -1915,15 +1963,12 @@ event_chord:
        simple_element post_events {
                // Let the rhythmic music iterator sort this mess out.
                if (scm_is_pair ($2)) {
-                       if (unsmob_pitch ($1)) {
-                               Music *n = MY_MAKE_MUSIC ("NoteEvent", @1);
-                               n->set_property ("pitch", $1);
-                               n->set_property ("duration",
-                                                parser->default_duration_.smobbed_copy ());
-                               $$ = n->unprotect ();
-                       }
-                       unsmob_music ($$)->set_property ("articulations",
-                                                        scm_reverse_x ($2, SCM_EOL));
+                       $$ = make_music_from_simple (parser, @1, $1);
+                       if (unsmob_music ($$))
+                                unsmob_music ($$)->set_property ("articulations",
+                                                                 scm_reverse_x ($2, SCM_EOL));
+                        else
+                                parser->parser_error (@1, _("music expected"));
                }
        }
        | simple_chord_elements post_events     {
@@ -2339,6 +2384,18 @@ gen_text_def:
                        make_simple_markup ($1));
                $$ = t->unprotect ();
        }
+       | embedded_scm_bare
+       {
+               Music *m = unsmob_music ($1);
+               if (m && m->is_mus_type ("post-event"))
+                       $$ = $1;
+               else if (Text_interface::is_markup ($1)) {
+                       Music *t = MY_MAKE_MUSIC ("TextScriptEvent", @$);
+                       t->set_property ("text", $1);
+                       $$ = t->unprotect ();
+               } else
+                       parser->parser_error (@1, _ ("not an articulation"));
+       }
        ;
 
 fingering:
@@ -2464,6 +2521,18 @@ bass_number:
        UNSIGNED { $$ = $1; }
        | STRING { $$ = $1; }
        | full_markup { $$ = $1; }
+       | embedded_scm_bare
+       {
+               // as an integer, it needs to be non-negative, and otherwise
+               // it needs to be suitable as a markup.
+               if (scm_is_integer ($1)
+                   ? scm_is_true (scm_negative_p ($1))
+                   : !Text_interface::is_markup ($1))
+               {
+                       parser->parser_error (@1, _ ("bass number expected"));
+                       $$ = SCM_INUM0;
+               }
+       }
        ;
 
 figured_bass_alteration:
@@ -2844,10 +2913,7 @@ This should be done more dynamically if possible.
 */
 
 lyric_markup:
-       LYRIC_MARKUP_IDENTIFIER {
-               $$ = $1;
-       }
-       | LYRIC_MARKUP
+       LYRIC_MARKUP
                { parser->lexer_->push_markup_state (); }
        markup_top {
                $$ = $3;
@@ -2856,10 +2922,7 @@ lyric_markup:
        ;
 
 full_markup_list:
-       MARKUPLIST_IDENTIFIER {
-               $$ = $1;
-       }
-       | MARKUPLIST
+       MARKUPLIST
                { parser->lexer_->push_markup_state (); }
        markup_list {
                $$ = $3;
@@ -2868,10 +2931,7 @@ full_markup_list:
        ;
 
 full_markup:
-       MARKUP_IDENTIFIER {
-               $$ = $1;
-       }
-       | MARKUP
+       MARKUP
                { parser->lexer_->push_markup_state (); }
        markup_top {
                $$ = $3;
@@ -2907,10 +2967,7 @@ markup_scm:
                        
 
 markup_list:
-       MARKUPLIST_IDENTIFIER {
-               $$ = $1;
-       }
-       | markup_composed_list {
+       markup_composed_list {
                $$ = $1;
        }
        | markup_braced_list {
@@ -2992,12 +3049,6 @@ simple_markup:
        STRING {
                $$ = make_simple_markup ($1);
        }
-       | MARKUP_IDENTIFIER {
-               $$ = $1;
-       }
-       | LYRIC_MARKUP_IDENTIFIER {
-               $$ = $1;
-       }
        | SCORE {
                SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
                parser->lexer_->push_note_state (nn);
@@ -3101,14 +3152,6 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
                *destination = p->self_scm ();
                p->unprotect ();
                return OUTPUT_DEF_IDENTIFIER;
-       } else if (Text_interface::is_markup (sid)) {
-               *destination = sid;
-               if (is_lyric_state ())
-                       return LYRIC_MARKUP_IDENTIFIER;
-               return MARKUP_IDENTIFIER;
-       } else if (Text_interface::is_markup_list (sid)) {
-               *destination = sid;
-               return MARKUPLIST_IDENTIFIER;
        }
 
        return -1;
@@ -3172,6 +3215,36 @@ is_regular_identifier (SCM id)
   return v;
 }
 
+SCM
+make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
+{
+       if (unsmob_music (simple))
+               return simple;
+       if (parser->lexer_->is_note_state ()) {
+               Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
+               n->set_property ("duration", parser->default_duration_.smobbed_copy ());
+               if (scm_is_symbol (simple))
+                       n->set_property ("drum-type", simple);
+               else if (unsmob_pitch (simple))
+                       n->set_property ("pitch", simple);
+               else {
+                       n->unprotect ();
+                       return simple;
+               }
+               return n->unprotect ();
+       } else if (parser->lexer_->is_lyric_state ()) {
+               if (Text_interface::is_markup (simple))
+                       return MAKE_SYNTAX ("lyric-event", loc, simple,
+                                           parser->default_duration_.smobbed_copy ());
+       } else if (parser->lexer_->is_chord_state ()) {
+               if (unsmob_pitch (simple))
+                       return make_chord_elements (loc, simple,
+                                                   parser->default_duration_.smobbed_copy (),
+                                                   SCM_EOL);
+       }
+       return simple;
+}
+
 Music *
 make_music_with_input (SCM name, Input where)
 {
@@ -3192,14 +3265,6 @@ is_duration (int t)
   return t && t == 1 << intlog2 (t);
 }
 
-void
-set_music_properties (Music *p, SCM a)
-{
-  for (SCM k = a; scm_is_pair (k); k = scm_cdr (k))
-       p->set_property (scm_caar (k), scm_cdar (k));
-}
-
-
 SCM
 make_chord_step (SCM step_scm, Rational alter)
 {