Reviewers: ,
Message:
While we are cleaning up warnings, here is a patch for the lexer
warnings.
This is all code cleanup, no behavior change, so I don't think a tracker
issue is appropriate. Regression tests are unchanged.
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll
File lily/lexer.ll (right):
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll#newcode23
lily/lexer.ll:23: backup rules
This comment instruction was violated, so this patch brings the code
back in compliance, but it is awkward.
Why are we avoiding backup states?
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll#newcode265
lily/lexer.ll:265: <version>{ANY_CHAR} {
Include \n in the pattern, to avoid warning about fall back to the
default match. (The \n should never match, because the rules that leave
us in <version> never leave \n on the input stream.)
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll#newcode309
lily/lexer.ll:309: <incl>\\{BLACK}*{WHITE}? { /* got the include
identifier */
Accept \include foo<<EOF>> without backing up
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll#newcode621
lily/lexer.ll:621: if (YY_START == longcomment)
Error reporting moved from line 287, to avoid warning for two matching
rules for <<EOF>>
http://codereview.appspot.com/4871041/diff/3001/lily/lexer.ll#newcode653
lily/lexer.ll:653: {REAL}|-{UNSIGNED} {
I'll add comment // backup rule, -123 versus -123.
Description:
lexer.ll: remove unused patterns, avoid backing up
This removes the rest of the warnings from Lilypond `make bin`
... except for a type conversion warning in out/parser.cc generated
by Bison -- I don't see a way to remove that warning.
Please review this at http://codereview.appspot.com/4871041/
Affected files:
M lily/lexer.ll
Index: lily/lexer.ll
diff --git a/lily/lexer.ll b/lily/lexer.ll
index
83a7940b6938dc634083fe9936ee389635713412..bd3a2abb6915f3c6e564bc7db10df86ed4842b0e
100644
--- a/lily/lexer.ll
+++ b/lily/lexer.ll
@@ -135,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}
@@ -148,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]
@@ -165,7 +163,7 @@ BOM_UTF8 \357\273\277
<*>\r {
- // windows-suck-suck-suck
+ // swallow and ignore carriage returns
}
<extratoken>{ANY_CHAR} {
@@ -264,15 +262,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 ();
}
@@ -285,12 +283,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
- }
}
@@ -314,7 +306,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] == ';'))
@@ -333,7 +325,7 @@ BOM_UTF8 \357\273\277
scm_display (sid, err);
}
}
-<incl>\"[^"]* { // backup rule
+<incl,version,sourcefilename>\"[^"]* { // backup rule
error (_ ("end quote missing"));
exit (1);
}
@@ -420,7 +412,13 @@ BOM_UTF8 \357\273\277
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
-
+ {UNSIGNED}\/ {
+ // handle two tokens in "5/ " without using backup states
+ yylval.i = String_convert::dec2int (string (YYText ()));
+ unput ('/');
+ char_count_stack_.back ()--;
+ return UNSIGNED;
+ }
{DIGIT} {
yylval.i = String_convert::dec2int (string (YYText ()));
return DIGIT;
@@ -465,6 +463,13 @@ BOM_UTF8 \357\273\277
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
+ {UNSIGNED}\/ {
+ // report erroneous input "2/ 3" without backing up
+ yylval.i = String_convert::dec2int (string (YYText ()));
+ unput ('/');
+ char_count_stack_.back ()--;
+ return UNSIGNED;
+ }
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
return UNSIGNED;
@@ -505,6 +510,13 @@ BOM_UTF8 \357\273\277
yylval.scm = scan_fraction (YYText ());
return FRACTION;
}
+ {UNSIGNED}\/ {
+ // report erroneous input "7/c" without backing up
+ yylval.i = String_convert::dec2int (string (YYText ()));
+ unput ('/');
+ char_count_stack_.back ()--;
+ return UNSIGNED;
+ }
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
return UNSIGNED;
@@ -606,7 +618,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
@@ -631,13 +650,7 @@ BOM_UTF8 \357\273\277
}
}
-{WORD} {
- return scan_bare_word (YYText ());
-}
-{KEYWORD} {
- return scan_escaped_word (YYText () + 1);
-}
-{REAL} {
+{REAL}|-{UNSIGNED} {
Real r;
int cnv = sscanf (YYText (), "%lf", &r);
assert (cnv == 1);
@@ -646,6 +659,12 @@ BOM_UTF8 \357\273\277
yylval.scm = scm_from_double (r);
return REAL;
}
+-\. {
+ /* "-." is an error in context where REAL is allowed;
+ match it to report the error without backing up.
+ */
+ return '.';
+}
{UNSIGNED} {
yylval.i = String_convert::dec2int (string (YYText ()));
_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-devel