]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
Merge branch 'master' into lilypond/translation
[lilypond.git] / lily / lexer.ll
index aaa95d79807454ffccf058d6790563b622493574..5743f44964d9e7ba99a393903d53dcd5a0faaeeb 100644 (file)
@@ -2,7 +2,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 1996--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 1996--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
                  Jan Nieuwenhuizen <janneke@gnu.org>
 
   LilyPond is free software: you can redistribute it and/or modify
 using namespace std;
 
 #include "context-def.hh"
+#include "duration.hh"
 #include "identifier-smob.hh"
 #include "international.hh"
 #include "interval.hh"
 #include "lily-guile.hh"
 #include "lily-lexer.hh"
+#include "lily-parser.hh"
 #include "lilypond-version.hh"
 #include "main.hh"
 #include "music.hh"
 #include "music-function.hh"
 #include "parse-scm.hh"
 #include "parser.hh"
+#include "pitch.hh"
 #include "source-file.hh"
 #include "std-string.hh"
 #include "string-convert.hh"
@@ -132,7 +135,6 @@ PUNCT               [?!:'`]
 ACCENT         \\[`'"^]
 NATIONAL       [\001-\006\021-\027\031\036]
 TEX            {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
-WORD           {A}{AN}*
 DASHED_WORD            {A}({AN}|-)*
 DASHED_KEY_WORD                \\{DASHED_WORD}
 
@@ -145,7 +147,6 @@ E_UNSIGNED  \\{N}+
 FRACTION       {N}+\/{N}+
 INT            -?{UNSIGNED}
 REAL           ({INT}\.{N}*)|(-?\.{N}+)
-KEYWORD                \\{WORD}
 WHITE          [ \n\t\f\r]
 HORIZONTALWHITE                [ \t]
 BLACK          [^ \n\t\f\r]
@@ -162,7 +163,7 @@ BOM_UTF8    \357\273\277
 
 
 <*>\r          {
-       // windows-suck-suck-suck
+       // swallow and ignore carriage returns
 }
 
 <extratoken>{ANY_CHAR} {
@@ -189,21 +190,20 @@ BOM_UTF8  \357\273\277
       LexerError (_ ("stray UTF-8 BOM encountered").c_str ());
       exit (1);
     }
-  if (be_verbose_global)
-     message (_ ("Skipping UTF-8 BOM"));
+  debug_output (_ ("Skipping UTF-8 BOM"));
 }
 
 <INITIAL,chords,figures,incl,lyrics,markup,notes>{
   "%{" {
        yy_push_state (longcomment);
   }
-  %[^{\n\r].*[\n\r]    {
+  %[^{\n\r][^\n\r]*[\n\r]      {
   }
   %[^{\n\r]    { // backup rule
   }
   %[\n\r]      {
   }
-  %[^{\n\r].*  {
+  %[^{\n\r][^\n\r]*    {
   }
   {WHITE}+     {
 
@@ -261,15 +261,15 @@ BOM_UTF8  \357\273\277
        this->here_input ().get_source_file ()->set_line (here_input ().start (), i);
 }
 
-<version>    {
+<version>{ANY_CHAR}    {
        LexerError (_ ("quoted string expected after \\version").c_str ());
        yy_pop_state ();
 }
-<sourcefilename>     {
+<sourcefilename>{ANY_CHAR}     {
        LexerError (_ ("quoted string expected after \\sourcefilename").c_str ());
        yy_pop_state ();
 }
-<sourcefileline>     {
+<sourcefileline>{ANY_CHAR}     {
        LexerError (_ ("integer expected after \\sourcefileline").c_str ());
        yy_pop_state ();
 }
@@ -282,12 +282,6 @@ BOM_UTF8   \357\273\277
        "%"+"}"         {
                yy_pop_state ();
        }
-       <<EOF>>         {
-               LexerError (_ ("EOF found inside a comment").c_str ());
-               is_main_input_ = false; // should be safe , can't have \include in --safe.
-               if (! close_input ()) 
-                 yyterminate (); // can't move this, since it actually rets a YY_NULL
-       }
 }
 
 
@@ -311,7 +305,7 @@ BOM_UTF8    \357\273\277
        new_input (s, sources_);
        yy_pop_state ();
 }
-<incl>\\{BLACK}*{WHITE} { /* got the include identifier */
+<incl>\\{BLACK}*{WHITE}? { /* got the include identifier */
        string s = YYText () + 1;
        strip_trailing_white (s);
        if (s.length () && (s[s.length () - 1] == ';'))
@@ -330,7 +324,7 @@ BOM_UTF8    \357\273\277
            scm_display (sid, err);
          }
 }
-<incl>\"[^"]*   { // backup rule
+<incl,version,sourcefilename>\"[^"]*   { // backup rule
        error (_ ("end quote missing"));
        exit (1);
 }
@@ -366,6 +360,11 @@ BOM_UTF8   \357\273\277
                yylval.scm = unpack_identifier(sval);
                return identifier_type (yylval.scm);
        }
+
+       for (size_t i = 0; i < pending_string_includes_.size (); i++)
+               new_input ("<included string>", pending_string_includes_[i],
+                          parser_->sources_);
+       pending_string_includes_.clear ();
                
        yylval.scm = sval;
        return SCM_TOKEN;
@@ -412,11 +411,15 @@ BOM_UTF8  \357\273\277
                yylval.scm =  scan_fraction (YYText ());
                return FRACTION;
        }
-
        {DIGIT}         {
                yylval.i = String_convert::dec2int (string (YYText ()));
                return DIGIT;
        }
+       {UNSIGNED}/\/[^0-9] { // backup rule
+               yylval.i = String_convert::dec2int (string (YYText ()));
+               return UNSIGNED;
+       }
+       {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
                yylval.i = String_convert::dec2int (string (YYText ()));
                return UNSIGNED;
@@ -457,6 +460,11 @@ BOM_UTF8   \357\273\277
                yylval.scm =  scan_fraction (YYText ());
                return FRACTION;
        }
+       {UNSIGNED}/\/[^0-9] { // backup rule
+               yylval.i = String_convert::dec2int (string (YYText ()));
+               return UNSIGNED;
+       }
+       {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
                yylval.i = String_convert::dec2int (string (YYText ()));
                return UNSIGNED;
@@ -497,6 +505,11 @@ BOM_UTF8   \357\273\277
                yylval.scm =  scan_fraction (YYText ());
                return FRACTION;
        }
+       {UNSIGNED}/\/[^0-9] { // backup rule
+               yylval.i = String_convert::dec2int (string (YYText ()));
+               return UNSIGNED;
+       }
+       {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
                yylval.i = String_convert::dec2int (string (YYText ()));
                return UNSIGNED;
@@ -598,7 +611,14 @@ BOM_UTF8   \357\273\277
 }
 
 <*><<EOF>> {
-       if (is_main_input_)
+       if (YY_START == longcomment)
+       {
+               LexerError (_ ("EOF found inside a comment").c_str ());
+               is_main_input_ = false; // should be safe , can't have \include in --safe.
+               if (!close_input ())
+                 yyterminate (); // can't move this, since it actually rets a YY_NULL
+       }
+       else if (is_main_input_)
        {
                /* 2 = init.ly + current file.
                   > because we're before closing, but is_main_input_ should
@@ -623,12 +643,7 @@ BOM_UTF8   \357\273\277
        }
 }
 
-{WORD} {
-       return scan_bare_word (YYText ());
-}
-{KEYWORD}      {
-       return scan_escaped_word (YYText () + 1);
-}
+-{UNSIGNED}    | // backup rule
 {REAL}         {
        Real r;
        int cnv = sscanf (YYText (), "%lf", &r);
@@ -638,6 +653,10 @@ BOM_UTF8   \357\273\277
        yylval.scm = scm_from_double (r);
        return REAL;
 }
+-\.    { // backup rule
+       yylval.scm = scm_from_double (0.0);
+       return REAL;
+}
 
 {UNSIGNED}     {
        yylval.i = String_convert::dec2int (string (YYText ()));
@@ -788,11 +807,17 @@ Lily_lexer::scan_escaped_word (string str)
                push_extra_token (EXPECT_NO_MORE_ARGS);
                for (; scm_is_pair (s); s = scm_cdr (s))
                {
-                       if (scm_car (s) == ly_music_p_proc)
+                       SCM cs = scm_car (s);
+                       
+                       if (cs == ly_music_p_proc)
                                push_extra_token (EXPECT_MUSIC);
-                       else if (scm_car (s) == ly_lily_module_constant ("markup?"))
+                       else if (cs == Pitch_type_p_proc)
+                               push_extra_token (EXPECT_PITCH);
+                       else if (cs == Duration_type_p_proc)
+                               push_extra_token (EXPECT_DURATION);
+                       else if (cs == ly_lily_module_constant ("markup?"))
                                push_extra_token (EXPECT_MARKUP);
-                       else if (ly_is_procedure (scm_car (s)))
+                       else if (ly_is_procedure (cs))
                                push_extra_token (EXPECT_SCM);
                        else programming_error ("Function parameter without type-checking predicate");
                }