aboutsummaryrefslogtreecommitdiff
path: root/engines/director/lingo/lingo-lex.l
diff options
context:
space:
mode:
authorEugene Sandulenko2019-12-03 18:16:25 +0100
committerEugene Sandulenko2019-12-03 18:35:59 +0100
commit2432018f2ff412c8440cc0e875fda7d563ca07db (patch)
tree7c15f5c4e4ab2838b1c8a9b97c214e9033a47135 /engines/director/lingo/lingo-lex.l
parent9606b754823a7ef2ba1d55aca135f1b673c190d2 (diff)
downloadscummvm-rg350-2432018f2ff412c8440cc0e875fda7d563ca07db.tar.gz
scummvm-rg350-2432018f2ff412c8440cc0e875fda7d563ca07db.tar.bz2
scummvm-rg350-2432018f2ff412c8440cc0e875fda7d563ca07db.zip
DIRECTOR: LINGO: Rewrite 'if' statement fully. Improve line counting
Still one particular testcase fails, but this is a major improvement in terms of clarity. The execution is temporarily broken.
Diffstat (limited to 'engines/director/lingo/lingo-lex.l')
-rw-r--r--engines/director/lingo/lingo-lex.l27
1 files changed, 17 insertions, 10 deletions
diff --git a/engines/director/lingo/lingo-lex.l b/engines/director/lingo/lingo-lex.l
index f813bed17f..d5ca6b6383 100644
--- a/engines/director/lingo/lingo-lex.l
+++ b/engines/director/lingo/lingo-lex.l
@@ -38,20 +38,27 @@
using namespace Director;
int yyparse();
+
static void count() {
if (debugChannelSet(-1, kDebugLingoParse))
debug("LEXER: Read '%s' at %d:%d", yytext, g_lingo->_linenumber, g_lingo->_colnumber);
- g_lingo->_colnumber += strlen(yytext);
-}
-
-static void countnl() {
char *p = yytext;
- while(*p == '\n' || *p == '\r')
+ while (*p && *p != '\n' && *p != '\r') {
p++;
+ g_lingo->_colnumber++;
+ }
+
+ while (*p == '\n' || *p == '\r') {
+ if (*p == '\n') {
+ g_lingo->_linenumber++;
+ g_lingo->_colnumber = 0;
+ }
+
+ p++;
+ }
- g_lingo->_linenumber++;
g_lingo->_colnumber = strlen(p);
}
@@ -77,7 +84,7 @@ whitespace [\t ]
%%
-{whitespace}*\xC2[\r\n] { g_lingo->_linenumber++; g_lingo->_colnumber = 0; }
+{whitespace}*\xC2[\r\n] { count(); }
--[^\r\n]*
^{whitespace}+ { count(); }
[\t]+ { count(); return ' '; }
@@ -92,8 +99,8 @@ whitespace [\t ]
(?i:done) { count(); return tDONE; }
(?i:down) { count(); return tDOWN; }
(?i:if) { count(); return tIF; }
-(?i:[\n\r]+[\t ]*else[\t ]+if) { countnl(); return tNLELSIF; }
-(?i:[\n\r]+[\t ]*else) { countnl(); return tNLELSE; }
+(?i:[\n\r]+[\t ]*else[\t ]+if) { count(); return tNLELSIF; }
+(?i:[\n\r]+[\t ]*else) { count(); return tNLELSE; }
(?i:else) { count(); return tELSE; }
(?i:end)([\t ]*{identifier})? {
count();
@@ -314,7 +321,7 @@ whitespace [\t ]
{constfloat} { count(); yylval.f = atof(yytext); return FLOAT; }
{constinteger} { count(); yylval.i = strtol(yytext, NULL, 10); return INT; }
{operator} { count(); return *yytext; }
-{newline} { return '\n'; }
+{newline} { count(); return '\n'; }
{conststring} { count(); yylval.s = new Common::String(&yytext[1]); yylval.s->deleteLastChar(); return STRING; }
. { count(); }