summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2016-06-18 07:08:00 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-06-18 07:08:00 (GMT)
commit45c143f157d7225fac7df014d80fc73085e1a126 (patch) (side-by-side diff)
treef99559c7e1d0e225fe09ac7d108c80082fb957ff /src
parent6669c8843b3cad84d4de63584b2675bc1b1c8ef5 (diff)
downloadgrecs-45c143f157d7225fac7df014d80fc73085e1a126.tar.gz
grecs-45c143f157d7225fac7df014d80fc73085e1a126.tar.bz2
Fix handling of undefined escape sequences.
* src/lineacc.c (grecs_line_acc_grow_char_unescape): If the escape sequence is not defined, add the character itself and return 1. Return 0 otherwise. (grecs_line_acc_grow_unescape_last): Take pointer to locus as third argument. If not NULL, print warning about undefined escape sequences. All callers updated. * src/parser.c (grecs_parse): Unless grecs_trace_flags is already set, set it from the value of GRECS_DEBUG environment variable.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/bind-lex.l6
-rw-r--r--src/dhcpd-lex.l6
-rw-r--r--src/grecs-lex.l12
-rw-r--r--src/lineacc.c17
-rw-r--r--src/meta1-lex.l6
-rw-r--r--src/parser.c17
6 files changed, 49 insertions, 15 deletions
diff --git a/src/bind-lex.l b/src/bind-lex.l
index b0b8d61..1dd0ca0 100644
--- a/src/bind-lex.l
+++ b/src/bind-lex.l
@@ -94,12 +94,14 @@ P [1-9][0-9]*
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1); }
+ yyleng - 1,
+ &yylloc); }
\"[^\\"\n]*\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow(yytext + 1, yyleng - 1); }
<STR>[^\\"\n]*\\. |
-<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
+<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc); }
<STR>[^\\"\n]*\n |
<STR>\"[^\\"\n]*\n { grecs_line_acc_grow(yytext, yyleng); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
diff --git a/src/dhcpd-lex.l b/src/dhcpd-lex.l
index 450a54b..34e0144 100644
--- a/src/dhcpd-lex.l
+++ b/src/dhcpd-lex.l
@@ -144,12 +144,14 @@ P [1-9][0-9]*
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1); }
+ yyleng - 1,
+ &yylloc); }
\"[^\\"\n]*\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow(yytext + 1, yyleng - 1); }
<STR>[^\\"\n]*\\. |
-<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
+<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc); }
<STR>[^\\"\n]*\n |
<STR>\"[^\\"\n]*\n { grecs_line_acc_grow(yytext, yyleng); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index b007780..98bf384 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -121,15 +121,19 @@ P [1-9][0-9]*
\"[^\\"\n]*\\\n { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1);
+ yyleng - 1,
+ &yylloc);
grecs_locus_point_advance_line(grecs_current_locus_point); }
\"[^\\"\n]*\\. { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1); }
-<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng);
+ yyleng - 1,
+ &yylloc); }
+<STR>\"[^\\"\n]*\\\n { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc);
grecs_locus_point_advance_line(grecs_current_locus_point); }
-<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
+<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
grecs_line_add(yytext, yyleng - 1);
diff --git a/src/lineacc.c b/src/lineacc.c
index eb7f064..c1957a6 100644
--- a/src/lineacc.c
+++ b/src/lineacc.c
@@ -42,11 +42,15 @@ grecs_line_acc_grow_char(int c)
grecs_txtacc_grow(line_acc, &t, 1);
}
-void
+int
grecs_line_acc_grow_char_unescape(int c)
{
- if (c != '\n')
- grecs_line_acc_grow_char(wordsplit_c_unquote_char(c));
+ if (c != '\n') {
+ int uc = wordsplit_c_unquote_char(c);
+ grecs_line_acc_grow_char(uc ? uc : c);
+ return !uc;
+ }
+ return 0;
}
void
@@ -57,10 +61,13 @@ grecs_line_acc_grow(const char *text, size_t len)
/* Same, but unescapes the last character from text */
void
-grecs_line_acc_grow_unescape_last(char *text, size_t len)
+grecs_line_acc_grow_unescape_last(char *text, size_t len, grecs_locus_t *loc)
{
grecs_txtacc_grow(line_acc, text, len - 2);
- grecs_line_acc_grow_char_unescape(text[len - 1]);
+ if (grecs_line_acc_grow_char_unescape(text[len - 1]) && loc)
+ grecs_warning(loc, 0,
+ _("unknown escape sequence: '\\%c'"),
+ text[len - 1]);
}
void
diff --git a/src/meta1-lex.l b/src/meta1-lex.l
index 75603d3..7f6fa78 100644
--- a/src/meta1-lex.l
+++ b/src/meta1-lex.l
@@ -80,9 +80,11 @@ X [0-9a-fA-F]
\"[^\\"\n]*\\. { BEGIN(STR);
grecs_line_begin();
grecs_line_acc_grow_unescape_last(yytext + 1,
- yyleng - 1); }
+ yyleng - 1,
+ &yylloc); }
<STR>[^\\"\n]*\\x{X}{1,2} { meta1_line_add_unescape_hex(yytext, yyleng); }
-<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng); }
+<STR>[^\\"\n]*\\. { grecs_line_acc_grow_unescape_last(yytext, yyleng,
+ &yylloc); }
<STR>[^\\"\n]*\" { BEGIN(INITIAL);
if (yyleng > 1)
grecs_line_add(yytext, yyleng - 1);
diff --git a/src/parser.c b/src/parser.c
index 5364834..f1573af 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -56,6 +56,23 @@ grecs_lex_trace(int n)
struct grecs_node *
grecs_parse(const char *name)
{
+ if (!grecs_trace_flags) {
+ char *p = getenv("GRECS_DEBUG");
+ if (p) {
+ while (*p) {
+ switch (*p++) {
+ case 'g':
+ case 'G':
+ grecs_trace_flags |= GRECS_TRACE_GRAM;
+ break;
+ case 'l':
+ case 'L':
+ grecs_trace_flags |= GRECS_TRACE_LEX;
+ break;
+ }
+ }
+ }
+ }
grecs_error_count = 0;
grecs_current_locus_point.file = grecs_install_text(name);
grecs_current_locus_point.line = 1;

Return to:

Send suggestions and report system problems to the System administrator.