]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lexer.ll
changes: mention that decimal numbers can be written without #
[lilypond.git] / lily / lexer.ll
index c1a6e4b0f43665380e51fca28eec4d19895725ab..50b79a848810b57e7500764ae22029b11799ddce 100644 (file)
@@ -150,12 +150,16 @@ N         [0-9]
 ANY_CHAR       (.|\n)
 WORD           {A}([-_]{A}|{A})*
 COMMAND                \\{WORD}
-
+/* SPECIAL category is for every letter that needs to get passed to
+ * the parser rather than being redefinable by the user */
+SPECIAL                [-+*/=<>{}!?_^'',.:]
+SHORTHAND      (.|\\.)
 UNSIGNED       {N}+
 E_UNSIGNED     \\{N}+
 FRACTION       {N}+\/{N}+
 INT            -?{UNSIGNED}
 REAL           ({INT}\.{N}*)|(-?\.{N}+)
+STRICTREAL      {UNSIGNED}\.{UNSIGNED}
 WHITE          [ \n\t\f\r]
 HORIZONTALWHITE                [ \t]
 BLACK          [^ \n\t\f\r]
@@ -476,6 +480,22 @@ BOM_UTF8   \357\273\277
                 yylval = SCM_UNSPECIFIED;
                return FIGURE_OPEN;
        }
+       \\\+    {
+               yylval = SCM_UNSPECIFIED;
+               return E_PLUS;
+       }
+       \\!     {
+               yylval = SCM_UNSPECIFIED;
+               return E_EXCLAMATION;
+       }
+       \\\\    {
+               yylval = SCM_UNSPECIFIED;
+               return E_BACKSLASH;
+       }
+       [][]    {
+               yylval = SCM_UNSPECIFIED;
+               return  YYText ()[0];
+       }
 }
 
 <notes,figures>{
@@ -492,8 +512,12 @@ BOM_UTF8   \357\273\277
                yylval =  scan_fraction (YYText ());
                return FRACTION;
        }
-       {UNSIGNED}/\/   | // backup rule
-       {UNSIGNED}              {
+       {STRICTREAL}    {
+               yylval = scm_c_read_string (YYText ());
+               return REAL;
+       }
+       {UNSIGNED}/[/.] | // backup rule
+       {UNSIGNED}      {
                yylval = scm_c_read_string (YYText ());
                return UNSIGNED;
        }
@@ -539,7 +563,11 @@ BOM_UTF8   \357\273\277
                yylval =  scan_fraction (YYText ());
                return FRACTION;
        }
-       {UNSIGNED}/\/   | // backup rule
+       {STRICTREAL}    {
+               yylval = scm_c_read_string (YYText ());
+               return REAL;
+       }
+       {UNSIGNED}/[/.] | // backup rule
        {UNSIGNED}              {
                yylval = scm_c_read_string (YYText ());
                return UNSIGNED;
@@ -548,8 +576,12 @@ BOM_UTF8   \357\273\277
        {COMMAND}       {
                return scan_escaped_word (YYText_utf8 () + 1);
        }
-       /* Characters needed to express durations, assignments, barchecks */
-       [*.=|]  {
+       \\.|\|  {
+               // UTF-8 already covered by COMMAND
+               return scan_shorthand (YYText ());
+       }
+       /* Characters needed to express durations, assignments */
+       [*.=]   {
                 yylval = SCM_UNSPECIFIED;
                return YYText ()[0];
        }
@@ -567,9 +599,9 @@ BOM_UTF8    \357\273\277
                return STRING;
        }
        /* This should really just cover {} */
-       . {
+       [{}] {
                 yylval = SCM_UNSPECIFIED;
-               return YYText ()[0]; // above catches all multibytes.
+               return YYText ()[0];
        }
 }
 <chords>{
@@ -610,10 +642,6 @@ BOM_UTF8   \357\273\277
                 yylval = SCM_UNSPECIFIED;
                return CHORD_CARET;
        }
-       . {
-                yylval = SCM_UNSPECIFIED;
-               return YYText ()[0]; // WORD catches all multibyte.
-       }
 }
 
 
@@ -679,9 +707,9 @@ BOM_UTF8    \357\273\277
                yylval = ly_string2scm (s);
                return STRING;
        }
-       .  {
+       [{}]  {
                 yylval = SCM_UNSPECIFIED;
-               return YYText ()[0];  // Above is catchall for multibyte
+               return YYText ()[0];
        }
 }
 
@@ -758,51 +786,18 @@ BOM_UTF8  \357\273\277
 }
 
 
-[{}]   {
-        yylval = SCM_UNSPECIFIED;
-       return YYText ()[0];
-}
-
--/\.   | // backup rule
-[*:=]          {
+-/\.   { // backup rule
         yylval = SCM_UNSPECIFIED;
        return YYText ()[0];
 }
 
-<INITIAL,notes,figures>.       {
+<INITIAL,chords,lyrics,figures,notes>{SPECIAL} {
         yylval = SCM_UNSPECIFIED;
        return YYText ()[0];
 }
 
-<INITIAL,lyrics,notes,figures>\\. {
-    yylval = SCM_UNSPECIFIED;
-    char c = YYText ()[1];
-
-    switch (c) {
-    case '>':
-       return E_ANGLE_CLOSE;
-    case '<':
-       return E_ANGLE_OPEN;
-    case '!':
-       return E_EXCLAMATION;
-    case '(':
-       return E_OPEN;
-    case ')':
-       return E_CLOSE;
-    case '[':
-       return E_BRACKET_OPEN;
-    case '+':
-       return E_PLUS;
-    case ']':
-       return E_BRACKET_CLOSE;
-    case '~':
-       return E_TILDE;
-    case '\\':
-       return E_BACKSLASH;
-
-    default:
-       return E_CHAR;
-    }
+<INITIAL,chords,lyrics,figures,notes>{SHORTHAND}       {
+       return scan_shorthand (YYText_utf8 ()); // should not be utf-8
 }
 
 <*>.[\200-\277]*       {
@@ -941,6 +936,26 @@ Lily_lexer::scan_escaped_word (string str)
        return STRING;
 }
 
+int
+Lily_lexer::scan_shorthand (string str)
+{
+       SCM sid = lookup_identifier (str);
+       if (Music *m = unsmob_music (sid))
+       {
+               m->set_spot (override_input (last_input_));
+       }
+
+       if (sid != SCM_UNDEFINED)
+               return scan_scm_id (sid);
+
+       string msg (_f ("undefined character or shorthand: %s", str));  
+       LexerError (msg.c_str ());
+
+       yylval = ly_string2scm (str);
+
+       return STRING;
+}
+
 int
 Lily_lexer::scan_scm_id (SCM sid)
 {