]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
Warnings: Move all warning-as-error handling to warn.cc
[lilypond.git] / lily / lexer.ll
index a9b1d3980ebb4866967996a8c7ec108614aa45b7..59284d07c39be8b50715bb54f85a847c5fb58e0e 100644 (file)
@@ -133,15 +133,15 @@ AN                {AA}|{N}
 ANY_CHAR       (.|\n)
 PUNCT          [?!:'`]
 ACCENT         \\[`'"^]
+SPECIAL_CHAR           [&@]
 NATIONAL       [\001-\006\021-\027\031\036]
-TEX            {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}
+TEX            {AA}|-|{PUNCT}|{ACCENT}|{NATIONAL}|{SPECIAL_CHAR}
 DASHED_WORD            {A}({AN}|-)*
 DASHED_KEY_WORD                \\{DASHED_WORD}
 
 
 
 ALPHAWORD      {A}+
-DIGIT          {N}
 UNSIGNED       {N}+
 E_UNSIGNED     \\{N}+
 FRACTION       {N}+\/{N}+
@@ -174,9 +174,10 @@ BOM_UTF8   \357\273\277
   yyless (0);
 
   /* produce requested token */
-  int type = extra_token_types_.back ();
-  extra_token_types_.pop_back ();
-  if (extra_token_types_.empty ())
+  int type = scm_to_int (scm_caar (extra_tokens_));
+  yylval.scm = scm_cdar (extra_tokens_);
+  extra_tokens_ = scm_cdr (extra_tokens_);
+  if (scm_is_null (extra_tokens_))
     yy_pop_state ();
 
   return type;
@@ -186,9 +187,10 @@ BOM_UTF8   \357\273\277
   /* Generate a token without swallowing anything */
 
   /* produce requested token */
-  int type = extra_token_types_.back ();
-  extra_token_types_.pop_back ();
-  if (extra_token_types_.empty ())
+  int type = scm_to_int (scm_caar (extra_tokens_));
+  yylval.scm = scm_cdar (extra_tokens_);
+  extra_tokens_ = scm_cdr (extra_tokens_);
+  if (scm_is_null (extra_tokens_))
     yy_pop_state ();
 
   return type;
@@ -199,8 +201,8 @@ BOM_UTF8    \357\273\277
 <INITIAL,chords,lyrics,figures,notes>{BOM_UTF8}/.* {
   if (this->lexloc_->line_number () != 1 || this->lexloc_->column_number () != 0)
     {
-      LexerError (_ ("stray UTF-8 BOM encountered").c_str ());
-      exit (1);
+      LexerWarning (_ ("stray UTF-8 BOM encountered").c_str ());
+      // exit (1);
     }
   debug_output (_ ("Skipping UTF-8 BOM"));
 }
@@ -381,6 +383,32 @@ BOM_UTF8   \357\273\277
        yylval.scm = sval;
        return SCM_TOKEN;
 }
+
+<INITIAL,chords,figures,lyrics,markup,notes>\$ { //immediate scm
+       int n = 0;
+       Input hi = here_input();
+       hi.step_forward ();
+       SCM sval = ly_parse_scm (hi.start (), &n, hi,
+               be_safe_global && is_main_input_, parser_);
+
+       for (int i = 0; i < n; i++)
+       {
+               yyinput ();
+       }
+       char_count_stack_.back () += n;
+
+       if (sval == SCM_UNDEFINED)
+       {
+               yylval.scm = SCM_UNSPECIFIED;
+               error_level_ = 1;
+
+               LexerError (_ ("bad Scheme expression").c_str ());
+               return SCM_IDENTIFIER;
+       }
+
+       return scan_scm_id (sval);
+}
+
 <INITIAL,notes,lyrics>{ 
        \<\<    {
                return DOUBLE_ANGLE_OPEN;
@@ -423,17 +451,9 @@ 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 ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {E_UNSIGNED}    {
@@ -473,12 +493,12 @@ BOM_UTF8  \357\273\277
                return FRACTION;
        }
        {UNSIGNED}/\/[^0-9] { // backup rule
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {NOTECOMMAND}   {
@@ -518,12 +538,12 @@ BOM_UTF8  \357\273\277
                return FRACTION;
        }
        {UNSIGNED}/\/[^0-9] { // backup rule
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        {UNSIGNED}/\/   | // backup rule
        {UNSIGNED}              {
-               yylval.i = String_convert::dec2int (string (YYText ()));
+               yylval.scm = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
        -  {
@@ -597,14 +617,14 @@ BOM_UTF8  \357\273\277
                  else if (predicate == ly_lily_module_constant ("markup?"))
                    push_extra_token(EXPECT_MARKUP);
                  else
-                   push_extra_token(EXPECT_SCM);
+                   push_extra_token(EXPECT_SCM, predicate);
                }
                return token_type;
        }
        [{}]    {
                return YYText ()[0];
        }
-       [^#{}"\\ \t\n\r\f]+ {
+       [^$#{}\"\\ \t\n\r\f]+ {
                string s (YYText ()); 
 
                char c = s[s.length () - 1];
@@ -656,12 +676,7 @@ BOM_UTF8   \357\273\277
 
 -{UNSIGNED}    | // backup rule
 {REAL}         {
-       Real r;
-       int cnv = sscanf (YYText (), "%lf", &r);
-       assert (cnv == 1);
-       (void) cnv;
-
-       yylval.scm = scm_from_double (r);
+       yylval.scm = scm_c_read_string (YYText ());
        return REAL;
 }
 -\.    { // backup rule
@@ -670,7 +685,7 @@ BOM_UTF8    \357\273\277
 }
 
 {UNSIGNED}     {
-       yylval.i = String_convert::dec2int (string (YYText ()));
+       yylval.scm = scm_c_read_string (YYText ());
        return UNSIGNED;
 }
 
@@ -730,21 +745,15 @@ BOM_UTF8  \357\273\277
 /* Make the lexer generate a token of the given type as the next token. 
  TODO: make it possible to define a value for the token as well */
 void
-Lily_lexer::push_extra_token (int token_type)
+Lily_lexer::push_extra_token (int token_type, SCM scm)
 {
-       if (extra_token_types_.empty ())
+       if (scm_is_null (extra_tokens_))
        {
                if (YY_START != extratoken)
                        hidden_state_ = YY_START;
                yy_push_state (extratoken);
        }
-       extra_token_types_.push_back (token_type);
-}
-
-void
-Lily_lexer::push_embedded_token ()
-{
-       push_extra_token (EMBEDDED_LILY);
+       extra_tokens_ = scm_acons (scm_from_int (token_type), scm, extra_tokens_);
 }
 
 void
@@ -816,43 +825,72 @@ Lily_lexer::scan_escaped_word (string str)
                return i;
 
        SCM sid = lookup_identifier (str);
+       if (sid != SCM_UNDEFINED)
+               return scan_scm_id (sid);
+
+       string msg (_f ("unknown escaped string: `\\%s'", str));        
+       LexerError (msg.c_str ());
+
+       yylval.scm = ly_string2scm (str);
+
+       return STRING;
+}
+
+int
+Lily_lexer::scan_scm_id (SCM sid)
+{
        if (is_music_function (sid))
        {
+               int funtype = SCM_FUNCTION;
+
                yylval.scm = get_music_function_transform (sid);
 
                SCM s = scm_object_property (yylval.scm, ly_symbol2scm ("music-function-signature"));
+               SCM cs = scm_car (s);
+
+               if (scm_is_pair (cs))
+               {
+                       cs = SCM_CAR (cs);
+               }
+
+               if (scm_is_eq (cs, ly_lily_module_constant ("ly:music?")))
+                       funtype = MUSIC_FUNCTION;
+               else if (scm_is_eq (cs, ly_lily_module_constant ("ly:event?")))
+                       funtype = EVENT_FUNCTION;
+               else if (ly_is_procedure (cs))
+                       funtype = SCM_FUNCTION;
+               else programming_error ("Bad syntax function predicate");
+
                push_extra_token (EXPECT_NO_MORE_ARGS);
-               for (; scm_is_pair (s); s = scm_cdr (s))
+               for (s = scm_cdr (s); scm_is_pair (s); s = scm_cdr (s))
                {
-                       SCM cs = scm_car (s);
+                       SCM optional = SCM_UNDEFINED;
+                       cs = scm_car (s);
+
+                       if (scm_is_pair (cs))
+                       {
+                               optional = SCM_CDR (cs);
+                               cs = SCM_CAR (cs);
+                       }
                        
-                       if (cs == ly_music_p_proc)
-                               push_extra_token (EXPECT_MUSIC);
-                       else if (cs == Pitch_type_p_proc)
+                       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 (cs))
-                               push_extra_token (EXPECT_SCM);
-                       else programming_error ("Function parameter without type-checking predicate");
+                               push_extra_token (EXPECT_SCM, cs);
+                       else
+                       {
+                               programming_error ("Function parameter without type-checking predicate");
+                               continue;
+                       }
+                       if (!scm_is_eq (optional, SCM_UNDEFINED))
+                               push_extra_token (EXPECT_OPTIONAL, optional);
                }
-               return MUSIC_FUNCTION;
-       }
-
-       if (sid != SCM_UNDEFINED)
-       {
-               yylval.scm = sid;
-               return identifier_type (sid);
+               return funtype;
        }
-
-       string msg (_f ("unknown escaped string: `\\%s'", str));        
-       LexerError (msg.c_str ());
-
-       yylval.scm = ly_string2scm (str);
-
-       return STRING;
+       yylval.scm = sid;
+       return identifier_type (sid);
 }
 
 int