]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.1.9
authorfred <fred>
Sun, 24 Mar 2002 19:54:21 +0000 (19:54 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:54:21 +0000 (19:54 +0000)
init/symbol.ly
input/toccata-fuga-E.ly
lily/lexer.l
lily/my-lily-lexer.cc
lily/parser.y

index 8d84256d94e0a0e23f779864e0001ceccf87f166..65bced4151d4122d6a5d92534bedb4faf582c0bf 100644 (file)
@@ -1,7 +1,12 @@
 \version "0.1.1";
 
+breve = \duration { -1 0 }
+longa = \duration { -2 0 }
+
 \include "dynamic.ly"
 \include "dutch.ly" 
+
+
 \include "script.ly"
 \include "paper16.ly"
 
index 828796f9d0631d4df0d4d4455016ece5c5f3ee0b..4e75271f8fdfc4f2d1bb36587fd795ac0a715736 100644 (file)
@@ -1,22 +1,23 @@
-%{MudelaHeader
+\header{
 
- filename: toccata-fuga-E.ly
- title: toccata and fuga in E-major 
- opus: BWV 566
toccata: 3 bar excerpt
2nd fuga: transposed subject --- 4 bar excerpt
+filename       toccata-fuga-E.ly
+title  toccata and fuga in E-major 
+opus   BWV 566
      toccata         3 bar excerpt
      2nd fuga        transposed subject --- 4 bar excerpt
 
- composers: Johann Sebastian Bach (1685-1750)
- entered-by: JCN
- copyright: public domain
+composers      Johann Sebastian Bach (1685-1750)
+enteredby      JCN
+copyright      public domain
 
+}
+
+%{
  Tested Features:
  purpose of this file is testing: 
      * real-life collisions
      * multi-voice input --- splitting?
      * organ staff...
-
-EndMudelaHeader
 %}
 
 
index 0372e75e98aa83c0008db3738e98198af95adfa3..8e702b7c793d00b52041edad18b5473f1d298d2f 100644 (file)
@@ -22,6 +22,7 @@
 
 
 #include <stdio.h>
+#include <ctype.h>
 
 #include "string.hh"
 #include "string-convert.hh"
@@ -32,6 +33,9 @@
 #include "parseconstruct.hh"
 #include "main.hh"
 #include "identifier.hh"
+void strip_trailing_white(String&);
+void strip_leading_white(String&);
+
 
 #define start_quote()  \
        yy_push_state(quote);\
@@ -52,6 +56,7 @@
 %option warn
 
 %x incl
+%x header
 %x lyrics
 %x notes
 %x quote
@@ -73,6 +78,7 @@ INT           -?{N}+
 REAL           ({INT}\.{N}*)|(-?\.{N}+)
 KEYWORD                \\{WORD}
 WHITE          [ \n\t\f]
+HORIZONTALWHITE                [ \t]
 BLACK          [^ \n\t\f]
 RESTNAME       [rs]
 NOTECOMMAND    \\{A}+
@@ -94,7 +100,7 @@ LYRICS               ({AA}|{NATIONAL})[^0-9 \t\n\f]*
   %[^{\n].*    {
   }
   {WHITE}+     {
-       
+
   }
 }
 
@@ -107,13 +113,37 @@ LYRICS            ({AA}|{NATIONAL})[^0-9 \t\n\f]*
        "%"+"}"         {
                yy_pop_state();
        }
+       <<EOF>>         {
+               LexerError("EOF found inside a comment");
+               if (! close_input()) 
+                 yyterminate(); // can't move this, since it actually rets a YY_NULL
+       }
 }
-<longcomment><<EOF>> {
-       LexerError("EOF found inside a comment");
-       if (! close_input()) { 
-         yyterminate(); // can't move this, since it actually rets a YY_NULL
+<header>{
+       [\{\}]  {
+               return YYText()[0];
+       }
+       ^{WORD}         {
+               String s=YYText();
+               yylval.string = new String(s);
+               return FIELDNAME;
+       }
+       {HORIZONTALWHITE}+{BLACK}.*\n           {
+               String s=YYText();
+               strip_leading_white(s);
+               strip_trailing_white(s);
+               yylval.string = new String(s);
+               return RECORDLINE;
+       }
+       {WHITE}*        {
+       }
+
+       .               {
+               return YYText()[0];
        }
 }
+
+
 <notes,INITIAL,lyrics>\\include           {
        yy_push_state(incl);
 }
@@ -375,3 +405,29 @@ My_lily_lexer::lyric_state_b() const
 {
        return YY_START == lyrics;
 }
+
+void 
+My_lily_lexer::push_header_state() 
+{
+       yy_push_state(header);
+}
+
+void strip_trailing_white(String&s)
+{
+       int i=0;
+       for (;  i < s.length_i(); i++) 
+               if (!isspace(s[i]))
+                       break;
+
+       s = s.nomid_str(0, i);
+}
+void strip_leading_white(String&s)
+{
+       int i=s.length_i();     
+       while (i--) 
+               if (!isspace(s[i]))
+                       break;
+
+       s = s.left_str(i+1);
+
+}
index 1160b86af148ea0625f1ca443f478e5f9713f2da..857d364ede06983728cef17f530f3e72070876db 100644 (file)
 #include "parseconstruct.hh"
 
 static Keyword_ent the_key_tab[]={
-    {"accepts", ACCEPTS},
-    {"alias", ALIAS},
-    {"bar", BAR},
-    {"cadenza", CADENZA},
-    {"clear", CLEAR},
-    {"clef", CLEF},
-    {"cm", CM_T},
-    {"consists", CONSISTS},
-    {"contains", CONTAINS},
-    {"duration", DURATIONCOMMAND},
-    {"absdynamic", ABSDYNAMIC},
-    {"group", GROUP},
-    {"hshift", HSHIFT},
-    {"id", ID},
-    {"in", IN_T},
-    {"requesttranslator", REQUESTTRANSLATOR},
-    {"lyric", LYRIC},
-    {"key", KEY},
-    {"melodic" , MELODIC},
-    {"melodic_request", MELODIC_REQUEST},
-    {"meter", METER},
-    {"midi", MIDI},
-    {"mm", MM_T},
-    {"multi", MULTI},
-    {"notenames", NOTENAMES},
-    {"octave", OCTAVECOMMAND},
-    {"output", OUTPUT},
-    {"partial", PARTIAL},
-    {"paper", PAPER},
-    {"plet", PLET},
-    {"pt", PT_T},
-    {"score", SCORE},
-    {"script", SCRIPT},
-    {"skip", SKIP},
-    {"staff", STAFF},
-    {"stem", STEM},
-    {"table", TABLE},
-    {"spandynamic", SPANDYNAMIC}, 
-    {"symboltables", SYMBOLTABLES},
-    {"tempo", TEMPO},
-    {"texid", TEXID},
-    {"textstyle", TEXTSTYLE},
-    {"transpose", TRANSPOSE},
-    {"version", VERSION},
-    {"grouping", GROUPING},
-    {0,0}
+  {"accepts", ACCEPTS},
+  {"alias", ALIAS},
+  {"bar", BAR},
+  {"cadenza", CADENZA},
+  {"clear", CLEAR},
+  {"clef", CLEF},
+  {"cm", CM_T},
+  {"consists", CONSISTS},
+  {"contains", CONTAINS},
+  {"duration", DURATION},
+  {"absdynamic", ABSDYNAMIC},
+  {"group", GROUP},
+  {"hshift", HSHIFT},
+  {"id", ID},
+  {"in", IN_T},
+  {"requesttranslator", REQUESTTRANSLATOR},
+  {"lyric", LYRIC},
+  {"key", KEY},
+  {"melodic" , MELODIC},
+  {"melodic_request", MELODIC_REQUEST},
+  {"meter", METER},
+  {"midi", MIDI},
+  {"mm", MM_T},
+  {"multi", MULTI},
+  {"header", HEADER},
+  {"notenames", NOTENAMES},
+  {"octave", OCTAVE},
+  {"output", OUTPUT},
+  {"partial", PARTIAL},
+  {"paper", PAPER},
+  {"plet", PLET},
+  {"pt", PT_T},
+  {"score", SCORE},
+  {"script", SCRIPT},
+  {"skip", SKIP},
+  {"staff", STAFF},
+  {"stem", STEM},
+  {"table", TABLE},
+  {"spandynamic", SPANDYNAMIC}, 
+  {"symboltables", SYMBOLTABLES},
+  {"tempo", TEMPO},
+  {"texid", TEXID},
+  {"textstyle", TEXTSTYLE},
+  {"transpose", TRANSPOSE},
+  {"version", VERSION},
+  {"grouping", GROUPING},
+  {0,0}
 };
 
 My_lily_lexer::My_lily_lexer()
 {
-    keytable_p_ = new Keyword_table (the_key_tab);
-    identifier_assoc_p_ = new Assoc<String, Identifier*>;
-    errorlevel_i_ = 0;
-    post_quotes_b_ = false;
-    note_tab_p_ = new Notename_table;
+  keytable_p_ = new Keyword_table (the_key_tab);
+  identifier_assoc_p_ = new Assoc<String, Identifier*>;
+  errorlevel_i_ = 0;
+  post_quotes_b_ = false;
+  note_tab_p_ = new Notename_table;
 }
 
 int
 My_lily_lexer::lookup_keyword (String s)
 {
-    return keytable_p_->lookup (s);
+  return keytable_p_->lookup (s);
 }
 
 Identifier*
 My_lily_lexer::lookup_identifier (String s)
 {
-    if (!identifier_assoc_p_->elt_b (s))
+  if (!identifier_assoc_p_->elt_b (s))
        return 0;
-    
-    return (*identifier_assoc_p_)[s];
+  
+  return (*identifier_assoc_p_)[s];
 }
 
 
 void
 My_lily_lexer::set_identifier (String name_str, Identifier*i)
 {
-    Identifier *old = lookup_identifier (name_str);
-    if  (old) {
+  Identifier *old = lookup_identifier (name_str);
+  if  (old) 
+    {
        old->warning( "redeclaration of \\" + name_str);
        delete old;
     }
-    (*identifier_assoc_p_)[name_str] = i;
+  (*identifier_assoc_p_)[name_str] = i;
 }
 
 My_lily_lexer::~My_lily_lexer()
 {
-    delete keytable_p_;
+  delete keytable_p_;
 
-    for (Assoc_iter<String,Identifier*>
-            ai (*identifier_assoc_p_); ai.ok(); ai++) {
+  for (Assoc_iter<String,Identifier*>
+            ai (*identifier_assoc_p_); ai.ok(); ai++) 
+              {
        DOUT << "deleting: " << ai.key()<<'\n';
        delete ai.val();
     }
-    delete note_tab_p_;
-    delete identifier_assoc_p_;
+  delete note_tab_p_;
+  delete identifier_assoc_p_;
 }
 void
 My_lily_lexer::print_declarations (bool init_b)const
 {
-    for (Assoc_iter<String,Identifier*> ai (*identifier_assoc_p_); ai.ok(); 
-        ai++) {
-       if (ai.val()->init_b_ == init_b) {
+  for (Assoc_iter<String,Identifier*> ai (*identifier_assoc_p_); ai.ok(); 
+        ai++) 
+          {
+       if (ai.val()->init_b_ == init_b) 
+         {
            DOUT << ai.key() << '=';
            ai.val()->print ();
-       }
+         }
     }
 }
 
 void
 My_lily_lexer::LexerError (char const *s)
 {
-    if (include_stack_.empty()) {
+  if (include_stack_.empty()) 
+    {
        *mlog << "error at EOF" << s << '\n';
-    } else {
+    }
+  else 
+    {
        errorlevel_i_ |= 1;
  
        Input spot (source_file_l(),here_ch_C());
@@ -146,18 +154,18 @@ My_lily_lexer::LexerError (char const *s)
 Melodic_req*
 My_lily_lexer::lookup_melodic_req_l (String s)
 {
-    return note_tab_p_->get_l (s);
+  return note_tab_p_->get_l (s);
 }
 
 void
 My_lily_lexer::add_notename (String s, Melodic_req *p)
 {
-    note_tab_p_->add (s,p);
+  note_tab_p_->add (s,p);
 }
 
 void
 My_lily_lexer::clear_notenames()
 {
-    delete note_tab_p_;
-    note_tab_p_ = new Notename_table;
+  delete note_tab_p_;
+  note_tab_p_ = new Notename_table;
 }
index 8722ffb133c0bed1d6b8e1e3aea7fdbba97b18dd..b72857d0d2e10d183a02d1c3ea3f923f212bd44f 100644 (file)
@@ -1,7 +1,7 @@
 %{ // -*-Fundamental-*-
 
 /*
-  parser.y -- lily parser
+  parser.y -- YACC parser for mudela
 
   source file of the GNU LilyPond music typesetter
 
@@ -34,6 +34,8 @@
 #include "input-translator.hh"
 #include "score.hh"
 #include "music-list.hh"
+#include "header.hh"
+#include "duration-convert.hh"
 
 #ifndef NDEBUG
 #define YYDEBUG 1
@@ -62,6 +64,7 @@
     Music *music;
     Music_list *musiclist;
     Score *score;
+    Header *header;
     Interval *interval;
     Lookup*lookup;
     Melodic_req * melreq;
@@ -111,13 +114,14 @@ yylex(YYSTYPE *s,  void * v_l)
 %token CONSISTS
 %token ACCEPTS
 %token CM_T
-%token DURATIONCOMMAND
+%token DURATION
 %token ABSDYNAMIC
 %token END
 %token GROUPING
 %token GROUP
 %token REQUESTTRANSLATOR
 %token HSHIFT
+%token HEADER
 %token IN_T
 %token ID
 %token LYRIC
@@ -129,7 +133,7 @@ yylex(YYSTYPE *s,  void * v_l)
 %token MM_T
 %token MULTI
 %token NOTENAMES
-%token OCTAVECOMMAND
+%token OCTAVE
 %token OUTPUT
 %token PAPER
 %token PARTIAL
@@ -157,6 +161,7 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <i>      dots
 %token <i>     INT
 %token <melreq>        NOTENAME_ID
+%token <id>    DURATION_IDENTIFIER
 %token <id>    IDENTIFIER
 %token <id>    MELODIC_REQUEST_IDENTIFIER 
 %token <id>    MUSIC_IDENTIFIER
@@ -173,11 +178,13 @@ yylex(YYSTYPE *s,  void * v_l)
 %token <id>    REQUEST_IDENTIFIER
 %token <real>  REAL 
 %token <string>        DURATION RESTNAME
-%token <string>        STRING
+%token <string>        STRING 
+%token <string> FIELDNAME RECORDLINE
 %token <i>     POST_QUOTES 
 %token <i>     PRE_QUOTES
 
 
+%type <header>         mudela_header mudela_header_body
 %type <box>    box
 %type <c>      open_request_parens close_request_parens
 %type <c>      open_plet_parens close_plet_parens
@@ -185,7 +192,8 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <i>      int
 %type <i>      script_dir
 %type <id>     identifier_init
-%type <duration>       explicit_duration notemode_duration entered_notemode_duration
+%type <duration> explicit_steno_duration notemode_duration 
+%type <duration> entered_notemode_duration explicit_duration
 %type <interval>       dinterval
 %type <intvec> intastint_list
 %type <lookup> symtables symtables_body
@@ -201,7 +209,8 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <paper>  paper_block paper_body
 %type <real>   dim real
 %type <real>   unit
-%type <request>        post_request pre_request command_req verbose_command_req abbrev_command_req
+%type <request>        post_request pre_request command_req verbose_command_req 
+%type <request> abbrev_command_req
 %type <request>        script_req  dynamic_req 
 %type <score>  score_block score_body
 %type <script> script_definition script_body mudela_script gen_script_def
@@ -211,12 +220,15 @@ yylex(YYSTYPE *s,  void * v_l)
 %type <symtable>       symtable symtable_body
 %type <itrans> input_translator_spec input_translator_spec_body
 %type <tempo>  tempo_request
+%type <string> header_record
 
 %left PRIORITY
 
 %%
 
 mudela:        /* empty */
+       | mudela mudela_header {
+       }
        | mudela score_block {
                add_score($2);          
        }
@@ -253,6 +265,40 @@ notenames_body:
                delete $2;
        }
        ;
+
+mudela_header_body:
+               {
+               $$ = new Header;
+       }
+       | mudela_header_body FIELDNAME header_record {
+               (*$$)[*$2] = *$3;
+               delete $2;
+               delete $3;
+       }
+       ;
+
+mudela_header:
+       HEADER  {
+               THIS->lexer_p_->push_header_state();
+       }
+       
+       '{' mudela_header_body '}'      {
+               $$ = $4;
+               THIS->lexer_p_->pop_state();
+       }
+       ;
+
+
+header_record:
+               {
+               $$ = new String;
+       }
+       | header_record RECORDLINE      {
+               *$$ += *$2;
+               delete $2;
+       }
+       ;
+
 /*
        DECLARATIONS
 */
@@ -311,6 +357,9 @@ identifier_init:
        | input_translator_spec {
                $$ = new Input_translator_id ( $1, INPUT_TRANS_IDENTIFIER);
        }
+       | explicit_duration {
+               $$ = new Duration_id( $1, DURATION_IDENTIFIER);
+       }
        ;
 
 
@@ -354,7 +403,9 @@ input_translator_spec_body:
        SCORE
 */
 score_block:
-       SCORE { THIS->remember_spot(); }
+       SCORE { THIS->remember_spot();
+               THIS->error_level_i_ =0;
+       }
        /*cont*/ '{' score_body '}'     {
                $$ = $4;
                $$->set_spot(THIS->pop_spot());
@@ -373,6 +424,9 @@ score_body:         {
        | SCORE_IDENTIFIER {
                $$ = $1->score();
        }
+       | score_body mudela_header      {
+               $$->header_p_ = $2;
+       }
        | score_body Music      {
                $$->music_p_ = $2;
        }
@@ -695,6 +749,14 @@ melodic_request:
        }
        ;
 
+explicit_duration:
+       DURATION '{' int int '}'        {
+               $$ = new Duration;
+               $$-> durlog_i_ = $3;
+               $$-> dots_i_ = $4;
+       }
+       ;
+
 dynamic_req:
        ABSDYNAMIC '{' int '}'  {
                Absolute_dynamic_req *ad_p = new Absolute_dynamic_req;
@@ -847,15 +909,15 @@ voice_command:
        PLET     INT '/' INT {
                THIS->default_duration_.set_plet($2,$4);
        }
-       | DURATIONCOMMAND STRING {
+       | DURATION STRING {
                THIS->set_duration_mode(*$2);
                delete $2;
        }
-       | DURATIONCOMMAND entered_notemode_duration {
+       | DURATION entered_notemode_duration {
                THIS->set_default_duration($2);
                delete $2;
        }
-       | OCTAVECOMMAND { 
+       | OCTAVE { 
                /*
                        This is weird, but default_octave_i_
                        is used in steno_note_req too
@@ -879,7 +941,7 @@ duration_length:
        {
                $$ = new Moment(0,1);
        }
-       | duration_length explicit_duration             {       
+       | duration_length explicit_steno_duration               {       
                *$$ += $2->length();
        }
        ;
@@ -897,7 +959,7 @@ entered_notemode_duration:
                $$ = new Duration(THIS->default_duration_);             
                $$->dots_i_  = $1;
        }
-       | explicit_duration     {
+       | explicit_steno_duration       {
                THIS->set_last_duration($1);
                $$ = $1;
        }
@@ -911,22 +973,25 @@ notemode_duration:
        }
        ;
 
-explicit_duration:
+explicit_steno_duration:
        int             {
                $$ = new Duration;
                if ( !Duration::duration_type_b($1) )
                        THIS->parser_error("Not a duration");
                else {
-                       $$->type_i_ = $1;
+                       $$->durlog_i_ = Duration_convert::i2_type($1);
                     }
        }
-       | explicit_duration '.'         {
+       | DURATION_IDENTIFIER   {
+               $$ = $1->duration();
+       }
+       | explicit_steno_duration '.'   {
                $$->dots_i_ ++;
        }
-       | explicit_duration '*' int  {
+       | explicit_steno_duration '*' int  {
                $$->plet_.iso_i_ *= $3; 
        }
-       | explicit_duration '/' int {
+       | explicit_steno_duration '/' int {
                $$->plet_.type_i_ *= $3; 
        }
        ;