]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
Let make_music_from_simple accept numbers/durations
[lilypond.git] / lily / parser.yy
index cadcd898698ef56b245eed44df0091f0c2a2b9e1..1cbb98f35f8860efd2fda3416212df5b3186e547 100644 (file)
@@ -141,7 +141,7 @@ using namespace std;
 #include "lily-imports.hh"
 
 void
-Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const std::string &s)
+Lily_parser::parser_error (Input const *i, Lily_parser *parser, SCM *, const string &s)
 {
        parser->parser_error (*i, s);
 }
@@ -223,13 +223,12 @@ SCM get_next_unique_lyrics_context_id ();
 #define _(x) gettext (x)
 #endif
 
-using std::string;
 
 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 disp = SCM_UNDEFINED);
 SCM make_music_from_simple (Lily_parser *parser, Input loc, SCM pitch);
-SCM loc_on_music (Input loc, SCM arg);
+SCM loc_on_music (Lily_parser *parser, 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);
 SCM make_simple_markup (SCM a);
@@ -693,7 +692,7 @@ identifier_init_nonumber:
        | pitch_or_music
        | FRACTION
        | string
-        | embedded_scm
+       | embedded_scm
        | partial_markup
        | full_markup_list
         | context_modification
@@ -1283,10 +1282,10 @@ tempo_event:
        TEMPO steno_duration '=' tempo_range    {
                $$ = MAKE_SYNTAX (tempo, @$, SCM_EOL, $2, $4);
        }
-       | TEMPO scalar steno_duration '=' tempo_range   {
+       | TEMPO text steno_duration '=' tempo_range     {
                $$ = MAKE_SYNTAX (tempo, @$, $2, $3, $5);
        }
-       | TEMPO scalar {
+       | TEMPO text {
                $$ = MAKE_SYNTAX (tempo, @$, $2);
        } %prec ':'
        ;
@@ -1757,7 +1756,7 @@ function_arglist_nonbackup:
                                               (parser, @3, $3),
                                               $1, $2);
        }
-       | function_arglist_nonbackup_reparse REPARSE duration_length
+       | function_arglist_nonbackup_reparse REPARSE multiplied_duration
        {
                $$ = check_scheme_arg (parser, @3, $3, $1, $2);
        }
@@ -1883,7 +1882,7 @@ function_arglist_backup:
                                $$ = scm_cons ($$, $3);
                        else
                        {
-                               $$ = scm_cons (loc_on_music (@3, $1), $3);
+                               $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                                MYBACKUP (SCM_ARG, $4, @4);
                        }
                }
@@ -1894,7 +1893,7 @@ function_arglist_backup:
                {
                        $$ = scm_cons ($4, $3);
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (EVENT_IDENTIFIER, $4, @4);
                }
        }
@@ -1910,7 +1909,7 @@ function_arglist_backup:
                } else if (scm_is_true (scm_call_1 ($2, $4)))
                        $$ = scm_cons ($4, $3);
                else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (PITCH_IDENTIFIER, $4, @4);
                }
        }
@@ -1926,7 +1925,7 @@ function_arglist_backup:
                } else if (scm_is_true (scm_call_1 ($2, $4)))
                        $$ = scm_cons ($4, $3);
                else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (TONICNAME_PITCH, $4, @4);
                }
        }
@@ -1935,7 +1934,7 @@ function_arglist_backup:
                if (scm_is_true (scm_call_1 ($2, $4)))
                        $$ = scm_cons ($4, $3);
                else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (SCM_IDENTIFIER, $4, @4);
                }
        }
@@ -1949,7 +1948,7 @@ function_arglist_backup:
                        SCM d = make_duration ($4);
                        if (SCM_UNBNDP (d) || scm_is_false (scm_call_1 ($2, d)))
                        {
-                               $$ = scm_cons (loc_on_music (@3, $1), $3);
+                               $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                                MYBACKUP (UNSIGNED, $4, @4);
                        } else {
                                MYREPARSE (@4, $2, DURATION_IDENTIFIER, d);
@@ -1964,7 +1963,7 @@ function_arglist_backup:
                        $$ = $3;
                        MYREPARSE (@4, $2, REAL, $4);
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (REAL, $4, @4);
                }
        }
@@ -1974,7 +1973,7 @@ function_arglist_backup:
                {
                        $$ = scm_cons ($4, $3);
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (NUMBER_IDENTIFIER, $4, @4);
                }
        }
@@ -1991,7 +1990,7 @@ function_arglist_backup:
                        if (scm_is_true (scm_call_1 ($2, $$)))
                                $$ = scm_cons ($$, $3);
                        else {
-                               $$ = scm_cons (loc_on_music (@3, $1), $3);
+                               $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                                MYBACKUP (UNSIGNED, $5, @5);
                                parser->lexer_->push_extra_token (@4, '-');
                        }
@@ -2004,7 +2003,7 @@ function_arglist_backup:
                        MYREPARSE (@5, $2, REAL, n);
                        $$ = $3;
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (REAL, n, @5);
                }
        }
@@ -2014,7 +2013,7 @@ function_arglist_backup:
                if (scm_is_true (scm_call_1 ($2, n))) {
                        $$ = scm_cons (n, $3);
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (NUMBER_IDENTIFIER, n, @5);
                }
        }
@@ -2025,7 +2024,7 @@ function_arglist_backup:
                        MYREPARSE (@4, $2, DURATION_IDENTIFIER, $4);
                        $$ = $3;
                } else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (DURATION_IDENTIFIER, $4, @4);
                }
        }
@@ -2040,7 +2039,7 @@ function_arglist_backup:
                        else
                                $$ = scm_cons (res, $3);
                else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (SCM_IDENTIFIER, $4, @4);
                }
        }
@@ -2055,7 +2054,7 @@ function_arglist_backup:
                        else
                                $$ = scm_cons (res, $3);
                else {
-                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
                        MYBACKUP (STRING, $4, @4);
                }
        }
@@ -2074,7 +2073,7 @@ function_arglist_backup:
                $$ = check_scheme_arg (parser, @3,
                                       $3, $1, $2);
        }
-       | function_arglist_backup REPARSE duration_length
+       | function_arglist_backup REPARSE multiplied_duration
        {
                $$ = check_scheme_arg (parser, @3,
                                       $3, $1, $2);
@@ -2089,7 +2088,7 @@ function_arglist:
        function_arglist_nonbackup
        | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup DEFAULT
        {
-               $$ = scm_cons (loc_on_music (@4, $1), $3);
+               $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
        }
        ;
 
@@ -2097,7 +2096,7 @@ function_arglist_skip_nonbackup:
        function_arglist_nonbackup
        | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_nonbackup
        {
-               $$ = scm_cons (loc_on_music (@3, $1), $3);
+               $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
        }
        ;
 
@@ -2205,7 +2204,7 @@ function_arglist_common:
                $$ = check_scheme_arg (parser, @3,
                                       $3, $1, $2);
        }
-       | function_arglist_common_reparse REPARSE duration_length
+       | function_arglist_common_reparse REPARSE multiplied_duration
        {
                $$ = check_scheme_arg (parser, @3,
                                       $3, $1, $2);
@@ -2335,7 +2334,7 @@ function_arglist_optional:
        function_arglist_backup
        | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup DEFAULT
        {
-               $$ = scm_cons (loc_on_music (@4, $1), $3);
+               $$ = scm_cons (loc_on_music (parser, @4, $1), $3);
        }
        | function_arglist_skip_backup BACKUP
        ;
@@ -2344,7 +2343,7 @@ function_arglist_skip_backup:
        function_arglist_backup
        | EXPECT_OPTIONAL EXPECT_SCM function_arglist_skip_backup
        {
-               $$ = scm_cons (loc_on_music (@3, $1), $3);
+               $$ = scm_cons (loc_on_music (parser, @3, $1), $3);
        }
        ;
 
@@ -2717,15 +2716,25 @@ music_property_def:
        ;
 
 string:
-       STRING {
-               $$ = $1;
-       }
+       STRING
        | full_markup
        ;
 
-simple_string: STRING {
-               $$ = $1;
+text:
+       STRING
+       | full_markup
+       | embedded_scm_bare
+       {
+               if (Text_interface::is_markup ($1)) {
+                       $$ = $1;
+               } else {
+                       parser->parser_error (@1, (_ ("markup expected")));
+                       $$ = scm_string (SCM_EOL);
+               }
        }
+       ;
+
+simple_string: STRING
        | embedded_scm_bare
        {
                if (scm_is_string ($1)) {
@@ -2812,8 +2821,8 @@ note_chord_element:
                  unsmob<Music> (scm_car (s))->set_property ("duration", dur);
                es = ly_append2 (es, postevs);
 
-               m-> set_property ("elements", es);
-               m->set_spot (@$);
+               m->set_property ("elements", es);
+               m->set_spot (parser->lexer_->override_input (@$));
                $$ = m->self_scm ();
        } %prec ':'
        ;
@@ -2920,7 +2929,7 @@ post_events:
                                        $$ = scm_cons (scm_car (p), $$);
                                }
                        } else {
-                               m->set_spot (@2);
+                               m->set_spot (parser->lexer_->override_input (@2));
                                $$ = scm_cons ($2, $$);
                        }
                }
@@ -3170,12 +3179,6 @@ script_dir:
        | '-'   { $$ = SCM_UNDEFINED; }
        ;
 
-duration_length:
-       multiplied_duration {
-               $$ = $1;
-       }
-       ;
-
 maybe_notemode_duration:
        {
                $$ = SCM_UNDEFINED;
@@ -3215,16 +3218,12 @@ steno_duration:
        ;
 
 multiplied_duration:
-       steno_duration {
-               $$ = $1;
-       }
-       | multiplied_duration '*' UNSIGNED {
-               $$ = unsmob<Duration> ($$)->compressed (scm_to_int ($3)).smobbed_copy ();
-       }
-       | multiplied_duration '*' FRACTION {
-               Rational  m (scm_to_int (scm_car ($3)), scm_to_int (scm_cdr ($3)));
-
-               $$ = unsmob<Duration> ($$)->compressed (m).smobbed_copy ();
+       steno_duration multipliers {
+               if (scm_is_number ($2)) {
+                       Rational m (ly_scm2rational ($2));
+                       $$ = unsmob<Duration> ($1)->compressed (m).smobbed_copy ();
+               } else
+                       $$ = $1;
        }
        ;
 
@@ -3237,6 +3236,28 @@ dots:
        }
        ;
 
+multipliers:
+       /* empty */
+       {
+               $$ = SCM_UNDEFINED;
+       }
+       | multipliers '*' UNSIGNED
+       {
+               if (!SCM_UNBNDP ($1))
+                       $$ = scm_product ($1, $3);
+               else
+                       $$ = $3;
+       }
+       | multipliers '*' FRACTION
+       {
+               if (!SCM_UNBNDP ($1))
+                       $$ = scm_product ($1, scm_divide (scm_car ($3),
+                                                         scm_cdr ($3)));
+               else
+                       $$ = scm_divide (scm_car ($3), scm_cdr ($3));
+       }
+       ;
+
 tremolo_type:
        ':'     {
                $$ = scm_from_int (parser->default_tremolo_type_);
@@ -3662,7 +3683,7 @@ full_markup:
        ;
 
 partial_markup:
-       markup_mode markup_head_1_list ETC
+       markup_mode markup_partial_function ETC
        {
                $$ = MAKE_SYNTAX (partial_markup, @2, $2);
                parser->lexer_->pop_state ();
@@ -3684,7 +3705,7 @@ markup_top:
        ;
 
 markup_scm:
-       embedded_scm_bare
+       embedded_scm
        {
                if (Text_interface::is_markup ($1))
                        MYBACKUP (MARKUP_IDENTIFIER, $1, @1);
@@ -3780,6 +3801,37 @@ markup_command_list_arguments:
        }
        ;
 
+markup_partial_function:
+       MARKUP_FUNCTION markup_arglist_partial
+       {
+               $$ = scm_list_1 (scm_cons ($1, scm_reverse_x ($2, SCM_EOL)));
+       }
+       | markup_head_1_list MARKUP_FUNCTION markup_arglist_partial
+       {
+               $$ = scm_cons (scm_cons ($2, scm_reverse_x ($3, SCM_EOL)),
+                              $1);
+       }
+       ;
+
+markup_arglist_partial:
+       EXPECT_MARKUP markup_arglist_partial
+       {
+               $$ = $2;
+       }
+       | EXPECT_SCM markup_arglist_partial
+       {
+               $$= $2;
+       }
+       | EXPECT_MARKUP markup_command_list_arguments
+       {
+               $$ = $2;
+       }
+       | EXPECT_SCM markup_command_list_arguments
+       {
+               $$ = $2;
+       }
+       ;
+
 markup_head_1_item:
        MARKUP_FUNCTION EXPECT_MARKUP markup_command_list_arguments {
          $$ = scm_cons ($1, scm_reverse_x ($3, SCM_EOL));
@@ -3956,12 +4008,12 @@ SCM check_scheme_arg (Lily_parser *parser, Input loc,
        return args;
 }
 
-SCM loc_on_music (Input loc, SCM arg)
+SCM loc_on_music (Lily_parser *parser, Input loc, SCM arg)
 {
        if (Music *m = unsmob<Music> (arg))
        {
                m = m->clone ();
-               m->set_spot (loc);
+               m->set_spot (parser->lexer_->override_input (loc));
                return m->unprotect ();
        }
        return arg;
@@ -4052,6 +4104,14 @@ make_music_from_simple (Lily_parser *parser, Input loc, SCM simple)
                        n->set_property ("pitch", simple);
                        return n->unprotect ();
                }
+               SCM d = simple;
+               if (scm_is_integer (simple))
+                       d = make_duration (simple);
+               if (unsmob<Duration> (d)) {
+                       Music *n = MY_MAKE_MUSIC ("NoteEvent", loc);
+                       n->set_property ("duration", d);
+                       return n->unprotect ();
+               }
                return simple;
        } else if (parser->lexer_->is_lyric_state ()) {
                if (Text_interface::is_markup (simple))