From 6e6fb8cfa302eab5b38f1593fa01d45817a04411 Mon Sep 17 00:00:00 2001 From: ketmar Date: Sun, 15 Sep 2013 23:08:17 +0300 Subject: [PATCH] scan.c: cosmetix --- src/scan.c | 87 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/src/scan.c b/src/scan.c index 9cf8d0c..a99acc4 100644 --- a/src/scan.c +++ b/src/scan.c @@ -209,7 +209,7 @@ int yylex (void) { /* while scanning the word, disqualify it for (expensive) * keyword lookup when we can: $anything, "anything", \anything */ not_keyword = (c == '$'); - if (c == '{' || c == '}' || c == ';' || c == '[' || c == ']') { + if (strchr("{}[];", c)) { *b++ = c; goto lexdone; } @@ -224,59 +224,60 @@ int yylex (void) { /* look for white space to delimit word */ /* "'s get stripped but preserve white space */ /* \ protects next character */ - while (c != EOF && b < buf+sizeof(buf) && (in_quote || !isspace(c))) { + for (; c != EOF && b < buf+sizeof(buf) && (in_quote || !isspace(c)); c = yychar()) { if (c == '"') { /* begin or end " */ in_quote = !in_quote; not_keyword = 1; - } else if (!in_quote && (c == '{' || c == '}' || c == ';')) { - /* k8: allow specials to work as delimiters */ - break; - } else if (!in_quote && !not_keyword && (c == '[' || c == ']')) { + continue; + } + if (!in_quote) { /* k8: allow specials to work as delimiters */ - break; - } else if (!in_quote && !not_keyword && !was_not_alnum && c == ':') { - /* k8: allow specials to work as delimiters; '*:' is not good */ - /**b = 0; printf("***OUT [%s]! %d\n", buf, incp?incp->line:0);*/ - break; - } else if (c != '\\') { + if (strchr("{};", c)) break; + if (!not_keyword) { + if (strchr("[]", c)) break; + if (!was_not_alnum && c == ':') break; /* '*:' is not good */ + } + } + if (c != '\\') { /* normal char */ if (!isalnum(c)) was_not_alnum = 1; *b++ = c; - } else if ((c = yychar()) != EOF) { - /* \c */ - was_not_alnum = 1; - if (in_quote) { - switch (c) { - case 't': *b++ = '\t'; break; - case 'n': *b++ = '\n'; break; - case 'r': *b++ = '\r'; break; - case 'v': *b++ = '\v'; break; - case 'b': *b++ = '\b'; break; - case 'a': *b++ = '\a'; break; - case 'f': *b++ = '\f'; break; - case 'e': *b++ = '\x1b'; break; - case 'x': - c = yychar(); // first digit - n = digit(c, 16); - if (n < 0) { yyerror("invalid hex escape in quoted string"); goto eof; } - c = yychar(); // second digit - d = digit(c, 16); - if (d < 0) { if (c != EOF) yyprev(); } else n = (n*16)+d; - if (n == 0) { yyerror("invalid hex escape in quoted string"); goto eof; } - *b++ = n; - break; - default: *b++ = c; break; - } - } else { - *b++ = c; + continue; + } + /* screened char */ + if ((c = yychar()) == EOF) break; + was_not_alnum = 1; + if (in_quote) { + switch (c) { + case 't': *b++ = '\t'; break; + case 'n': *b++ = '\n'; break; + case 'r': *b++ = '\r'; break; + case 'v': *b++ = '\v'; break; + case 'b': *b++ = '\b'; break; + case 'a': *b++ = '\a'; break; + case 'f': *b++ = '\f'; break; + case 'e': *b++ = '\x1b'; break; + case 'x': + c = yychar(); // first digit + n = digit(c, 16); + if (n < 0) { yyerror("invalid hex escape in quoted string"); goto eof; } + c = yychar(); // second digit + d = digit(c, 16); + if (d < 0) { if (c != EOF) yyprev(); } else n = (n*16)+d; + if (n == 0) { yyerror("invalid hex escape in quoted string"); goto eof; } + *b++ = n; + break; + //TODO: add '\uXXXX'? + default: + if (isalnum(c)) { yyerror("invalid escape in quoted string"); goto eof; } + *b++ = c; + break; } - not_keyword = 1; } else { - /* \EOF */ - break; + *b++ = c; } - c = yychar(); + not_keyword = 1; } /* we looked ahead a character -- back up */ lexdoneback: -- 2.11.4.GIT