]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
patch::: 1.3.135.jcn3
[lilypond.git] / lily / lexer.ll
index 8d95d0e42e6bb7a20f6d17d6421df038f12b3dbf..c86168a224e5c4b59ff9ba20a44058edbf420faf 100644 (file)
@@ -4,7 +4,7 @@
 
   source file of the LilyPond music typesetter
 
-  (c) 1996--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
            Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <ctype.h>
 
+#include "score.hh"
 #include "lily-guile.hh"
 #include "string.hh"
 #include "string-convert.hh"
 #include "debug.hh"
 #include "main.hh"
 #include "musical-request.hh"
-#include "identifier.hh"
-#include "mudela-version.hh"
 #include "version.hh"
+#include "lilypond-input-version.hh"
+#include "translator-def.hh"
+#include "music-output-def.hh"
+
+/*
+RH 7 fix (?)
+*/
+#define isatty HORRIBLEKLUDGE
 
 void strip_trailing_white (String&);
 void strip_leading_white (String&);
@@ -137,9 +144,9 @@ HYPHEN              --
        String s (YYText ()+1);
        s = s.left_str (s.index_last_i ('"'));
        DEBUG_OUT << "#version `" << s << "'\n";
+       yy_pop_state ();
        if (!valid_version_b (s))
                return INVALID;
-       yy_pop_state ();
 }
 <version>.     {
        LexerError ("No quoted string found after \\version");
@@ -188,18 +195,12 @@ HYPHEN            --
        if (s.length_i () && (s[s.length_i () - 1] == ';'))
          s = s.left_str (s.length_i () - 1);
        DEBUG_OUT << "#include `\\" << s << "'\n";
-       Identifier * id = lookup_identifier (s);
-       if (id) 
-         {
-           String* s_l = id->access_content_String (false);
-           DEBUG_OUT << "#include `" << *s_l << "'\n";
-           new_input (*s_l, source_global_l);
-
-           yy_pop_state ();
-         }
-       else
-         {
-           String msg (_f ("undefined identifier: `%s'", s )); 
+       SCM sid = lookup_identifier (s);
+       if (gh_string_p (sid)) {
+               new_input (ly_scm2string (sid), source_global_l);
+               yy_pop_state ();
+       } else { 
+           String msg (_f ("wrong or undefined identifier: `%s'", s ));        
            LexerError (msg.ch_C ());
          }
 }
@@ -209,7 +210,7 @@ HYPHEN              --
 }
 <chords,notes>{RESTNAME}       {
        const char *s = YYText ();
-       yylval.scm = ly_ch_C_to_scm (s);
+       yylval.scm = ly_str02scm (s);
        return RESTNAME;
 }
 <chords,notes>R                {
@@ -233,18 +234,17 @@ HYPHEN            --
        cerr << _ ("white expected") << endl;
        exit (1);
 }
+
 <INITIAL,chords,lyrics,notes># { //embedded scm
        //char const* s = YYText () + 1;
        char const* s = here_ch_C ();
        int n = 0;
        if (main_input_b_ && safe_global_b) {
                error (_ ("Can't evaluate Scheme in safe mode"));
-               return SCM_EOL;
+               yylval.scm =  SCM_EOL;
+               return SCM_T;
        }
        yylval.scm = ly_parse_scm (s, &n);
-       DEBUG_OUT << "Scheme: ";
-       if (flower_dstream)
-               ly_display_scm (yylval.scm);
        
        for (int i=0; i < n; i++)
        {
@@ -293,7 +293,7 @@ HYPHEN              --
 
                /* yylval is union. Must remember STRING before setting SCM*/
                String *sp = yylval.string;
-               yylval.scm = ly_ch_C_to_scm  (sp->ch_C ());
+               yylval.scm = ly_str02scm  (sp->ch_C ());
                delete sp;
                return STRING;
        }
@@ -330,16 +330,16 @@ HYPHEN            --
                        }
 
                char c = s[s.length_i () - 1];
-               if (c == '{' &&  c == '}') // brace open is for not confusing dumb tools.
+               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.scm = ly_ch_C_to_scm (s.ch_C ());
+                               _("Brace found at end of lyric. Did you forget a space?"));
+               yylval.scm = ly_str02scm (s.ch_C ());
 
                DEBUG_OUT << "lyric : `" << s << "'\n";
                return STRING;
        }
        . {
-               return yylval.c = YYText ()[0];
+               return YYText ()[0];
        }
 }
 <chords>{
@@ -359,11 +359,17 @@ HYPHEN            --
        -  {
                return CHORD_MINUS;
        }
+       :  {
+               return CHORD_COLON;
+       }
+       \/\+ {
+               return CHORD_BASS;
+       }
        \^  {
                return CHORD_CARET;
        }
        . {
-               return yylval.c = YYText ()[0];
+               return YYText ()[0];
        }
 }
 
@@ -397,7 +403,6 @@ HYPHEN              --
 }
 
 [{}]   {
-
        DEBUG_OUT << "parens\n";
        return YYText ()[0];
 }
@@ -408,12 +413,12 @@ HYPHEN            --
 }
 
 <INITIAL,notes>.       {
-       return yylval.c = YYText ()[0];
+       return YYText ()[0];
 }
 
 <INITIAL,lyrics,notes>\\. {
     char c= YYText ()[1];
-    yylval.c = c;
+
     switch (c) {
     case '>':
        return E_BIGGER;
@@ -421,6 +426,10 @@ HYPHEN             --
        return E_SMALLER;
     case '!':
        return E_EXCLAMATION;
+    case '(':
+       return E_OPEN;
+    case ')':
+       return E_CLOSE;
     default:
        return E_CHAR;
     }
@@ -461,32 +470,57 @@ My_lily_lexer::pop_state ()
 int
 My_lily_lexer::scan_escaped_word (String str)
 {
-       DEBUG_OUT << "\\word: `" << str<<"'\n";
+       // use more SCM for this.
+
+       SCM sym = ly_symbol2scm (str.ch_C());
+
        int l = lookup_keyword (str);
        if (l != -1) {
-               DEBUG_OUT << "(keyword)\n";
                return l;
        }
-       Identifier * id = lookup_identifier (str);
-       if (id) {
-               DEBUG_OUT << "(identifier)\n";
-               yylval.id = id;
-               return id->token_code_i_;
+       SCM sid = lookup_identifier (str);
+       if (gh_string_p (sid)) {
+               yylval.scm = sid; 
+               return STRING_IDENTIFIER;
+       } else if (gh_number_p (sid)) {
+               yylval.scm = sid;
+               return NUMBER_IDENTIFIER;
+       } else if (unsmob_translator_def (sid)) {
+               yylval.scm = sid;
+               return TRANSLATOR_IDENTIFIER;
+       } else if (unsmob_score (sid)) {
+               yylval.scm =sid;
+               return SCORE_IDENTIFIER;
+       } else if (Music * mus =unsmob_music (sid)) {
+               yylval.scm = sid;
+               
+               return dynamic_cast<Request*> (mus) ? REQUEST_IDENTIFIER : MUSIC_IDENTIFIER;
+       } else if (unsmob_duration (sid)) {
+               yylval.scm = sid;
+               return DURATION_IDENTIFIER;
+       } else if (unsmob_music_output_def (sid)) {
+               yylval.scm = sid;
+               return MUSIC_OUTPUT_DEF_IDENTIFIER;
+       }
+
+       if (sid != SCM_UNDEFINED) {
+               yylval.scm = sid;
+               return SCM_IDENTIFIER;
        }
+
        if ((YYSTATE != notes) && (YYSTATE != chords)) {
-               if (notename_b (str)) {
-                       yylval.pitch = new Musical_pitch (lookup_notename (str));
-                       yylval.pitch->set_spot (Input (source_file_l (), 
-                         here_ch_C ()));
+               SCM pitch = scm_hashq_get_handle (pitchname_tab_, sym);
+               
+               if (gh_pair_p (pitch))
+               {
+                       yylval.scm = gh_cdr (pitch);
                        return NOTENAME_PITCH;
                }
        }
-       if (flower_dstream)
-               print_declarations (true);
        String msg (_f ("unknown escaped string: `\\%s'", str));        
        LexerError (msg.ch_C ());
-       DEBUG_OUT << "(string)";
-       yylval.scm = ly_ch_C_to_scm(str.ch_C());
+
+       yylval.scm = ly_str02scm(str.ch_C());
 
        return STRING;
 }
@@ -494,24 +528,20 @@ My_lily_lexer::scan_escaped_word (String str)
 int
 My_lily_lexer::scan_bare_word (String str)
 {
-       DEBUG_OUT << "word: `" << str<< "'\n";  
+       SCM sym = ly_symbol2scm (str.ch_C ());
        if ((YYSTATE == notes) || (YYSTATE == chords)) {
-               if (notename_b (str)) {
-                   DEBUG_OUT << "(notename)\n";
-                   yylval.pitch = new Musical_pitch (lookup_notename (str));
-                   yylval.pitch->set_spot (Input (source_file_l (), 
-                     here_ch_C ()));
+               SCM pitch = scm_hashq_get_handle (pitchname_tab_, sym);
+               if (gh_pair_p (pitch)) {
+                   yylval.scm = gh_cdr (pitch);
                     return (YYSTATE == notes) ? NOTENAME_PITCH : TONICNAME_PITCH;
-               } else if (chordmodifier_b (str)) {
-                   DEBUG_OUT << "(chordmodifier)\n";
-                   yylval.pitch = new Musical_pitch (lookup_chordmodifier (str));
-                   yylval.pitch->set_spot (Input (source_file_l (), 
-                     here_ch_C ()));
+               } else if ((pitch = scm_hashq_get_handle (chordmodifier_tab_, sym))!= SCM_BOOL_F)
+               {
+                   yylval.scm = gh_cdr (pitch);
                    return CHORDMODIFIER_PITCH;
                }
        }
 
-       yylval.scm = ly_ch_C_to_scm (str.ch_C());
+       yylval.scm = ly_str02scm (str.ch_C());
        return STRING;
 }
 
@@ -565,13 +595,13 @@ strip_trailing_white (String&s)
 bool
 valid_version_b (String s)
 {
-  Mudela_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
-  Mudela_version ver (s);
+  Lilypond_version current ( MAJOR_VERSION "." MINOR_VERSION "." PATCH_LEVEL );
+  Lilypond_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;
+               non_fatal_error (_f ("incorrect lilypond version: %s (%s, %s)", ver.str (), oldest_version.str (), current.str ()));
+               non_fatal_error (_("Consider converting the input with the convert-ly script")); 
+               return false;
     }
   return true;
 }