]> git.donarmstrong.com Git - lilypond.git/commitdiff
parser.yy: allow optional Scheme arguments to be skipped based on the predicate.
authorDavid Kastrup <dak@gnu.org>
Sun, 16 Oct 2011 15:10:06 +0000 (17:10 +0200)
committerDavid Kastrup <dak@gnu.org>
Sat, 22 Oct 2011 11:18:20 +0000 (13:18 +0200)
lily/parser.yy

index 3a51c7035c7908de60a6a886c9bbbe3ea75523dc..8d0573ff6f57d29bccc4dfab17fe612348b7da99 100644 (file)
@@ -117,6 +117,15 @@ using namespace std;
 #include "text-interface.hh"
 #include "warn.hh"
 
+#define MYBACKUP(Token, Value, Location)                               \
+       do                                                              \
+               if (yychar == YYEMPTY)                                  \
+                       PARSER->lexer_->push_extra_token (Token, Value); \
+               else                                                    \
+                       PARSER->parser_error                            \
+                               (Location, _("cannot backup token"));   \
+       while (0)
+
 %}
 
 
@@ -285,6 +294,7 @@ If we give names, Bison complains.
 %token <i> EXPECT_PITCH "ly:pitch?"
 %token <i> EXPECT_DURATION "ly:duration?"
 %token <scm> EXPECT_SCM "scheme?"
+%token <scm> SKIPPED_SCM "(scheme?)"
 %token <i> EXPECT_MARKUP_LIST "markup-list?"
 %token <scm> EXPECT_OPTIONAL "optional?"
 /* After the last argument. */
@@ -1193,19 +1203,31 @@ function_arglist_keep:
        | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length {
                $$ = scm_cons ($4, $3);
        }
-       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
-       {
-               $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
-       }
        | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_keep closed_music
        {
                $$ = scm_cons ($4, $3);
        }
-       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm
+       | function_arglist
+       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
+       {
+               if (scm_is_true (scm_call_1 ($2, $4)))
+               {
+                       $$ = scm_cons ($4, $3);
+               } else {
+                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       MYBACKUP (SKIPPED_SCM, $4, @4);
+               }
+       }
+       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_closed
        {
-               $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
+               if (scm_is_true (scm_call_1 ($2, $4)))
+               {
+                       $$ = scm_cons ($4, $3);
+               } else {
+                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       MYBACKUP (SKIPPED_SCM, $4, @4);
+               }
        }
-       | function_arglist
        ;
 
 
@@ -1258,17 +1280,29 @@ function_arglist_closed_keep:
        | EXPECT_OPTIONAL EXPECT_DURATION function_arglist_closed_keep duration_length {
                $$ = scm_cons ($4, $3);
        }
-       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
-       {
-               $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
-       }
        | EXPECT_OPTIONAL EXPECT_MUSIC function_arglist_keep closed_music
        {
                $$ = scm_cons ($4, $3);
        }
+       | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep simple_string
+       {
+               if (scm_is_true (scm_call_1 ($2, $4)))
+               {
+                       $$ = scm_cons ($4, $3);
+               } else {
+                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       MYBACKUP (SKIPPED_SCM, $4, @4);
+               }
+       }
        | EXPECT_OPTIONAL EXPECT_SCM function_arglist_keep embedded_scm_closed
        {
-               $$ = check_scheme_arg (PARSER, @4, $1, $4, $3, $2);
+               if (scm_is_true (scm_call_1 ($2, $4)))
+               {
+                       $$ = scm_cons ($4, $3);
+               } else {
+                       $$ = scm_cons (loc_on_music (@3, $1), $3);
+                       MYBACKUP (SKIPPED_SCM, $4, @4);
+               }
        }
        | function_arglist_closed
        ;
@@ -1304,6 +1338,10 @@ function_arglist_bare:
        | EXPECT_SCM function_arglist_optional simple_string {
                $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
        }
+       | EXPECT_SCM function_arglist_optional SKIPPED_SCM
+       {
+               $$ = check_scheme_arg (PARSER, @3, SCM_UNDEFINED, $3, $2, $1);
+       }
        ;
 
 music_function_call: