]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/parser.yy
* Documentation/user/point-and-click.itely: simplify p&c
[lilypond.git] / lily / parser.yy
index 3b72ec290b2d4674412423b4bfd87c362f3f08ac..70f35f500000a3fb516bd9541d17c17bef939723 100644 (file)
@@ -5,7 +5,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
                  Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
@@ -20,10 +20,10 @@ FIXME:
 
 #include "config.hh"
 
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdio.h>
-
+#include <cctype>
+#include <cstdlib>
+#include <cstdio>
+using namespace std;
 
 #include "book.hh"
 #include "context-def.hh"
@@ -212,7 +212,9 @@ make_lyric_combine_music (SCM name, Music *music)
 deleting them.  Let's hope that a stack overflow doesnt trigger a move
 of the parse stack onto the heap. */
 
+%left PREC_TOP
 %left ADDLYRICS
+%left PREC_BOT
 
 %union {
        Book *book;
@@ -348,15 +350,12 @@ or
 %token E_OPEN "\\("
 %token E_BRACKET_CLOSE "\\]"
 %token E_ANGLE_OPEN "\\<"
+%token E_PLUS "\\+"
 %token E_TILDE "\\~"
 %token EXTENDER "__"
-/*  These used at all?
-  %token FIGURE_BRACKET_CLOSE 
-  %token FIGURE_BRACKET_OPEN
-
-parser.yy:348.8-25: warning: symbol `"\\>"' used more than once as a literal string
-parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal string
 
+/*
+If we give names, Bison complains.
 */
 %token FIGURE_CLOSE /* "\\>" */
 %token FIGURE_OPEN /* "\\<" */
@@ -373,8 +372,7 @@ parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal str
 %token <i> E_UNSIGNED
 %token <i> UNSIGNED
 
-%token <id> IDENTIFIER
-
+%token <scm> BOOK_IDENTIFIER
 %token <scm> CHORDMODIFIER_PITCH
 %token <scm> CHORD_MODIFIER
 %token <scm> CONTEXT_DEF_IDENTIFIER
@@ -407,6 +405,7 @@ parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal str
 %token <scm> MUSIC_FUNCTION_SCM_MUSIC_MUSIC 
 %token <scm> MUSIC_FUNCTION_SCM_SCM 
 %token <scm> MUSIC_FUNCTION_SCM_SCM_MUSIC 
+%token <scm> MUSIC_FUNCTION_SCM_SCM_SCM 
 %token <scm> MUSIC_IDENTIFIER
 %token <scm> NOTENAME_PITCH
 %token <scm> NUMBER_IDENTIFIER
@@ -425,7 +424,7 @@ parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal str
 %type <book> book_body
 
 %type <i> bare_unsigned
-%type <i> bass_mod
+%type <i> figured_bass_alteration
 %type <i> dots
 %type <i> exclamations
 %type <i> optional_rest
@@ -476,8 +475,9 @@ parser.yy:352.8-24: warning: symbol `"\\<"' used more than once as a literal str
 %type <scm> assignment_id
 %type <scm> bare_number
 %type <scm> bass_figure
-%type <scm> bass_number
+%type <scm> figured_bass_modification
 %type <scm> br_bass_figure
+%type <scm> bass_number
 %type <scm> chord_body_elements
 %type <scm> chord_item
 %type <scm> chord_items
@@ -673,6 +673,10 @@ identifier_init:
                $$ = $1->self_scm ();
                $1->unprotect ();
        }
+       | book_block {
+               $$ = $1->self_scm ();
+               $1->unprotect ();
+       }
        | output_def {
                $$ = $1->self_scm ();
                $1->unprotect ();
@@ -756,6 +760,10 @@ book_body:
                $$->paper_->unprotect ();
                $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader"); 
        }
+       | BOOK_IDENTIFIER {
+               $$ = unsmob_book ($1);
+               $$->set_spot (@$);
+       }
        | book_body paper_block {
                $$->paper_ = $2;
                $2->unprotect ();
@@ -1116,6 +1124,9 @@ Generic_prefix_music_scm:
        | MUSIC_FUNCTION_SCM_SCM embedded_scm embedded_scm {
                $$ = scm_list_4 ($1, make_input (@$), $2, $3);
        }
+       | MUSIC_FUNCTION_SCM_SCM_SCM embedded_scm embedded_scm embedded_scm {
+               $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4);
+       }
        | MUSIC_FUNCTION_SCM_SCM_MUSIC embedded_scm embedded_scm Music {
                $$ = scm_list_5 ($1, make_input (@$), $2, $3, $4->self_scm ());
        }
@@ -1412,7 +1423,11 @@ property_operation:
        }
        | OVERRIDE simple_string embedded_scm '=' embedded_scm {
                $$ = scm_list_4 (ly_symbol2scm ("push"),
-                       scm_string_to_symbol ($2), $3, $5);
+                       scm_string_to_symbol ($2), $5, $3);
+       }
+       | OVERRIDE simple_string embedded_scm embedded_scm '=' embedded_scm {
+               $$ = scm_list_5 (ly_symbol2scm ("push"),
+                               scm_string_to_symbol ($2), $6, $4, $3);
        }
        | REVERT simple_string embedded_scm {
                $$ = scm_list_3 (ly_symbol2scm ("pop"),
@@ -1460,10 +1475,17 @@ context_prop_spec:
 music_property_def:
        OVERRIDE context_prop_spec embedded_scm '=' scalar {
                $$ = property_op_to_music (scm_list_4 (
-                       ly_symbol2scm ("poppush"),
+                       ly_symbol2scm ("push"),
                        scm_cadr ($2),
-                       $3, $5));
-               $$= context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+                       $5, $3));
+               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
+       }
+       | OVERRIDE context_prop_spec embedded_scm  embedded_scm '=' scalar {
+               $$ = property_op_to_music (scm_list_5 (
+                       ly_symbol2scm ("push"),
+                       scm_cadr ($2),
+                       $6, $4, $3));
+               $$ = context_spec_music (scm_car ($2), SCM_UNDEFINED, $$, SCM_EOL);
        }
        | REVERT context_prop_spec embedded_scm {
                $$ = property_op_to_music (scm_list_3 (
@@ -2161,20 +2183,16 @@ tremolo_type:
 
 bass_number:
        DIGIT   {
-               $$ = scm_number_to_string (scm_from_int ($1), scm_from_int (10));
-               $$ = scm_list_2 (ly_lily_module_constant ("number-markup"),
-                               $$);
+               $$ = scm_from_int ($1);
        }
        | UNSIGNED {
-               $$ = scm_number_to_string (scm_from_int ($1), scm_from_int (10));
-               $$ = scm_list_2 (ly_lily_module_constant ("number-markup"),
-                               $$);
+               $$ = scm_from_int ($1);
        }
        | STRING { $$ = $1; }
        | full_markup { $$ = $1; }
        ;
 
-bass_mod:
+figured_bass_alteration:
        '-'     { $$ = -2; }
        | '+'   { $$ = 2; }
        | '!'   { $$ = 0; }
@@ -2190,10 +2208,18 @@ bass_figure:
                Music *bfr = MY_MAKE_MUSIC ("BassFigureEvent");
                $$ = bfr->self_scm ();
 
-               bfr->set_property ("figure", $1);
+               if (scm_is_number ($1))
+                       bfr->set_property ("figure", $1);
+               else if (Text_interface::is_markup ($1))
+                       bfr->set_property ("text", $1);
+
                bfr->unprotect ();
        }
-       | bass_figure bass_mod {
+       | bass_figure ']' {
+               $$ = $1;
+               unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
+       }
+       | bass_figure figured_bass_alteration {
                Music *m = unsmob_music ($1);
                if ($2) {
                        SCM salter = m->get_property ("alteration");
@@ -2204,19 +2230,43 @@ bass_figure:
                        m->set_property ("alteration", scm_from_int (0));
                }
        }
+       | bass_figure figured_bass_modification  {
+               Music *m = unsmob_music ($1);
+               if ($2 == ly_symbol2scm ("plus"))
+                       {
+                       m->set_property ("augmented", SCM_BOOL_T);
+                       }
+               else if ($2 == ly_symbol2scm ("slash"))
+                       {
+                       m->set_property ("diminished", SCM_BOOL_T);
+                       }
+               else if ($2 == ly_symbol2scm ("exclamation"))
+                       {
+                       m->set_property ("no-continuation", SCM_BOOL_T);
+                       }
+       }
        ;
 
-br_bass_figure:
-       '[' bass_figure {
-               $$ = $2;
-               unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
+
+figured_bass_modification:
+       E_PLUS          {
+               $$ = ly_symbol2scm ("plus");
        }
-       | bass_figure   {
-               $$ = $1;
+       | E_EXCLAMATION {
+               $$ = ly_symbol2scm ("exclamation");
        }
-       | br_bass_figure ']' {
+       | '/'           {
+               $$ = ly_symbol2scm ("slash");
+       }
+       ;
+
+br_bass_figure:
+       bass_figure {
                $$ = $1;
-               unsmob_music ($1)->set_property ("bracket-stop", SCM_BOOL_T);
+       }
+       | '[' bass_figure {
+               $$ = $2;
+               unsmob_music ($$)->set_property ("bracket-start", SCM_BOOL_T);
        }
        ;
 
@@ -2671,6 +2721,9 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid)
        if (scm_is_string (sid)) {
                *destination = sid;
                return STRING_IDENTIFIER;
+       } else if (unsmob_book (sid)) {
+               *destination = unsmob_book (sid)->clone ()->self_scm ();
+               return BOOK_IDENTIFIER;
        } else if (scm_is_number (sid)) {
                *destination = sid;
                return NUMBER_IDENTIFIER;
@@ -2718,7 +2771,7 @@ property_op_to_music (SCM op)
        SCM symbol = scm_cadr (op);
        SCM args = scm_cddr (op);
        SCM grob_val = SCM_UNDEFINED;
-       SCM grob_sym = SCM_UNDEFINED;
+       SCM grob_path = SCM_UNDEFINED;
        SCM val = SCM_UNDEFINED;
        
        if (tag == ly_symbol2scm ("assign"))
@@ -2728,16 +2781,16 @@ property_op_to_music (SCM op)
                }
        else if (tag == ly_symbol2scm ("unset"))
                m = MY_MAKE_MUSIC ("PropertyUnset");
-       else if (tag == ly_symbol2scm ("poppush")
-                || tag == ly_symbol2scm ("push"))
+       else if (tag == ly_symbol2scm ("push"))
                {
                m = MY_MAKE_MUSIC ("OverrideProperty");
-               grob_sym = scm_car (args);
-               grob_val = scm_cadr (args);
+               grob_val = scm_car (args);
+               grob_path = scm_cdr (args);
+               m->set_property ("pop-first", SCM_BOOL_T);
                }
        else if (tag == ly_symbol2scm ("pop")) {
                m = MY_MAKE_MUSIC ("RevertProperty");
-               grob_sym = scm_car (args);
+               grob_path = args;
                }
 
        m->set_property ("symbol", symbol);
@@ -2746,23 +2799,8 @@ property_op_to_music (SCM op)
                m->set_property ("value", val);
        if (grob_val != SCM_UNDEFINED)
                m->set_property ("grob-value", grob_val);
-
-       if (grob_sym != SCM_UNDEFINED)
-               {
-               bool itc = do_internal_type_checking_global;
-               /* UGH.
-               */
-               bool autobeam = ly_is_equal (symbol, ly_symbol2scm ("autoBeamSettings"));
-               if (autobeam)
-                       do_internal_type_checking_global = false;
-               m->set_property ("grob-property", grob_sym);
-               if (autobeam)
-                       do_internal_type_checking_global = itc;
-               }
-
-       if (tag == ly_symbol2scm ("poppush"))
-               m->set_property ("pop-first", SCM_BOOL_T);
-
+       if (grob_path != SCM_UNDEFINED)
+               m->set_property ("grob-property-path", grob_path);
 
        return m;
 }