]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
release: 1.2.13
[lilypond.git] / lily / lexer.ll
index e9a0c10371b4a4058317ea1056693b3e0dee2d5c..42e4996c580bfd0e4d995864ea7d6bd836943947 100644 (file)
 #include "interval.hh"
 #include "parser.hh"
 #include "debug.hh"
-#include "parseconstruct.hh"
 #include "main.hh"
 #include "musical-request.hh"
 #include "identifier.hh"
+#include "mudela-version.hh"
+#include "version.hh"
+
 void strip_trailing_white (String&);
 void strip_leading_white (String&);
 
+
+bool
+valid_version_b (String s);
+
+
+
 #define start_quote()  \
        yy_push_state (quote);\
        yylval.string = new String
@@ -62,6 +70,7 @@ LYRICS                ({AA}|{TEX})[^0-9 \t\n\f]*
 %option never-interactive 
 %option warn
 
+%x version
 %x chords
 %x incl
 %x lyrics
@@ -93,7 +102,7 @@ NOTECOMMAND  \\{A}+
 LYRICS         ({AA}|{TEX})[^0-9 \t\n\f]*
 ESCAPED                [nt\\'"]
 EXTENDER       __
-
+HYPHEN         --
 %%
 
 
@@ -118,6 +127,21 @@ EXTENDER   __
   }
 }
 
+<INITIAL,chords,lyrics,notes>\\version{WHITE}* {
+       yy_push_state (version);
+}
+<version>\"[^"]*\";?   { /* got the include file name */
+       String s (YYText ()+1);
+       s = s.left_str (s.index_last_i ('"'));
+       DEBUG_OUT << "#version `" << s << "'\n";
+       if (!valid_version_b (s))
+               return INVALID;
+       yy_pop_state ();
+}
+<version>.     {
+       LexerError ("No quoted string found after \\version");
+       yy_pop_state ();
+}
 <longcomment>{
        [^\%]*          {
        }
@@ -142,7 +166,7 @@ EXTENDER    __
                main_input_b_ = true;
        }
        else
-               error ("\\maininput disallowed outside init files.");
+               error (_ ("\\maininput disallowed outside init files"));
 }
 
 <INITIAL,chords,lyrics,notes>\\include           {
@@ -151,7 +175,7 @@ EXTENDER    __
 <incl>\"[^"]*\";?   { /* got the include file name */
        String s (YYText ()+1);
        s = s.left_str (s.index_last_i ('"'));
-       DOUT << "#include `" << s << "\'\n";
+       DEBUG_OUT << "#include `" << s << "'\n";
        new_input (s,source_global_l);
        yy_pop_state ();
 }
@@ -160,30 +184,30 @@ EXTENDER  __
        strip_trailing_white (s);
        if (s.length_i () && (s[s.length_i () - 1] == ';'))
          s = s.left_str (s.length_i () - 1);
-       DOUT << "#include `\\" << s << "'\n";
+       DEBUG_OUT << "#include `\\" << s << "'\n";
        Identifier * id = lookup_identifier (s);
        if (id) 
          {
            String* s_l = id->access_content_String (false);
-           DOUT << "#include `" << *s_l << "\'\n";
+           DEBUG_OUT << "#include `" << *s_l << "'\n";
            new_input (*s_l, source_global_l);
 
            yy_pop_state ();
          }
        else
          {
-           String msg (_f ("undefined identifier: `%s\'", s ));        
+           String msg (_f ("undefined identifier: `%s'", s )); 
            LexerError (msg.ch_C ());
          }
 }
 <incl>\"[^"]*   { // backup rule
-       cerr << _ ("missing end quote") << endl;
+       cerr << _ ("Missing end quote") << endl;
        exit (1);
 }
 <chords,notes>{RESTNAME}       {
        const char *s = YYText ();
        yylval.string = new String (s); 
-       DOUT << "rest:"<< yylval.string;
+       DEBUG_OUT << "rest:"<< yylval.string;
        return RESTNAME;
 }
 <chords,notes>R                {
@@ -220,7 +244,6 @@ EXTENDER    __
                yylval.i = String_convert::dec2_i (String (YYText ()));
                return DIGIT;
        }
-
        {UNSIGNED}              {
                yylval.i = String_convert::dec2_i (String (YYText ()));
                return UNSIGNED;
@@ -242,7 +265,7 @@ EXTENDER    __
                *yylval.string += YYText ();
        }
        \"      {
-               DOUT << "quoted string: `" << *yylval.string << "'\n";
+               DEBUG_OUT << "quoted string: `" << *yylval.string << "'\n";
                yy_pop_state ();
                return STRING;
        }
@@ -267,6 +290,8 @@ EXTENDER    __
                String s (YYText ()); 
                if (s == "__")
                        return yylval.i = EXTENDER;
+               if (s == "--")
+                       return yylval.i = HYPHEN;
                int i = 0;
                        while ((i=s.index_i ("_")) != -1) // change word binding "_" to " "
                        *(s.ch_l () + i) = ' ';
@@ -275,8 +300,13 @@ EXTENDER   __
                        *(s.ch_l () + i + 1) = 'c';
                        s = s.left_str (i+2) + " " + s.right_str (s.length_i ()-i-2);
                        }
+
+               char c = s[s.length_i () - 1];
+               if (c == '{' &&  c == '}') // brace open is for not confusing dumb tools.
+                       here_input ().warning (
+                               "Brace found at end of lyric. Did you forget a space?");
                yylval.string = new String (s);
-               DOUT << "lyric : `" << s << "'\n";
+               DEBUG_OUT << "lyric : `" << s << "'\n";
                return STRING;
        }
        . {
@@ -297,13 +327,19 @@ EXTENDER  __
        \" {
                start_quote ();
        }
+       -  {
+               return CHORD_MINUS;
+       }
+       \^  {
+               return CHORD_CARET;
+       }
        . {
                return yylval.c = YYText ()[0];
        }
 }
 
 <<EOF>> {
-       DOUT << "<<eof>>";
+       DEBUG_OUT << "<<eof>>";
 
        if (! close_input ()) { 
          yyterminate (); // can't move this, since it actually rets a YY_NULL
@@ -321,7 +357,7 @@ EXTENDER    __
        Real r;
        int cnv=sscanf (YYText (), "%lf", &r);
        assert (cnv == 1);
-       DOUT  << "REAL" << r<<'\n';
+       DEBUG_OUT  << "REAL" << r<<'\n';
        yylval.real = r;
        return REAL;
 }
@@ -333,12 +369,12 @@ EXTENDER  __
 
 [{}]   {
 
-       DOUT << "parens\n";
+       DEBUG_OUT << "parens\n";
        return YYText ()[0];
 }
 [*:=]          {
        char c = YYText ()[0];
-       DOUT << "misc char" <<c<<"\n";
+       DEBUG_OUT << "misc char" <<c<<"\n";
        return c;
 }
 
@@ -362,7 +398,7 @@ EXTENDER    __
 }
 
 <*>.           {
-       String msg = _f ("illegal character: `%c\'", YYText ()[0]);
+       String msg = _f ("invalid character: `%c'", YYText ()[0]);
        LexerError (msg.ch_C ());
        return YYText ()[0];
 }
@@ -395,16 +431,16 @@ My_lily_lexer::pop_state ()
 
 int
 My_lily_lexer::scan_escaped_word (String str)
-{      
-       DOUT << "\\word: `" << str<<"'\n";
+{
+       DEBUG_OUT << "\\word: `" << str<<"'\n";
        int l = lookup_keyword (str);
        if (l != -1) {
-               DOUT << "(keyword)\n";
+               DEBUG_OUT << "(keyword)\n";
                return l;
        }
        Identifier * id = lookup_identifier (str);
        if (id) {
-               DOUT << "(identifier)\n";
+               DEBUG_OUT << "(identifier)\n";
                yylval.id = id;
                return id->token_code_i_;
        }
@@ -416,11 +452,11 @@ My_lily_lexer::scan_escaped_word (String str)
                        return NOTENAME_PITCH;
                }
        }
-       if (check_debug)
+       if (flower_dstream)
                print_declarations (true);
-       String msg (_f ("unknown escaped string: `\\%s\'", str));       
+       String msg (_f ("unknown escaped string: `\\%s'", str));        
        LexerError (msg.ch_C ());
-       DOUT << "(string)";
+       DEBUG_OUT << "(string)";
        String *sp = new String (str);
        yylval.string=sp;
        return STRING;
@@ -429,16 +465,16 @@ My_lily_lexer::scan_escaped_word (String str)
 int
 My_lily_lexer::scan_bare_word (String str)
 {
-       DOUT << "word: `" << str<< "'\n";       
+       DEBUG_OUT << "word: `" << str<< "'\n";  
        if ((YYSTATE == notes) || (YYSTATE == chords)) {
                if (notename_b (str)) {
-                   DOUT << "(notename)\n";
+                   DEBUG_OUT << "(notename)\n";
                    yylval.pitch = new Musical_pitch (lookup_notename (str));
                    yylval.pitch->set_spot (Input (source_file_l (), 
                      here_ch_C ()));
                     return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
                } else if (chordmodifier_b (str)) {
-                   DOUT << "(chordmodifier)\n";
+                   DEBUG_OUT << "(chordmodifier)\n";
                    yylval.pitch = new Musical_pitch (lookup_chordmodifier (str));
                    yylval.pitch->set_spot (Input (source_file_l (), 
                      here_ch_C ()));
@@ -494,3 +530,20 @@ strip_trailing_white (String&s)
        s = s.left_str (i+1);
 }
 
+
+
+
+bool
+valid_version_b (String s)
+{
+  Mudela_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
+  Mudela_version ver (s);
+  if (!((ver >= oldest_version) && (ver <= current)))
+       {       
+               error (_f ("incorrect mudela version: %s (%s, %s)", ver.str (), oldest_version.str (), current.str ()));
+               if (!version_ignore_global_b)
+                       return false;
+    }
+  return true;
+}
+