[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/9] style: introduce & use STRING_1GROW
From: |
Akim Demaille |
Subject: |
[PATCH 3/9] style: introduce & use STRING_1GROW |
Date: |
Sat, 13 Jun 2020 17:23:11 +0200 |
* src/flex-scanner.h (STRING_1GROW): New.
* src/scan-gram.l, src/scan-skel.l: Use it.
---
src/flex-scanner.h | 3 +++
src/scan-gram.l | 26 +++++++++++++-------------
src/scan-skel.l | 6 +++---
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/flex-scanner.h b/src/flex-scanner.h
index f0f3ae17..56ca7ce3 100644
--- a/src/flex-scanner.h
+++ b/src/flex-scanner.h
@@ -109,6 +109,9 @@ static struct obstack obstack_for_string;
# define STRING_FINISH() \
(last_string = obstack_finish0 (&obstack_for_string))
+# define STRING_1GROW(Char) \
+ obstack_1grow (&obstack_for_string, Char)
+
# define STRING_FREE() \
obstack_free (&obstack_for_string, last_string)
diff --git a/src/scan-gram.l b/src/scan-gram.l
index 655eee70..3b03923a 100644
--- a/src/scan-gram.l
+++ b/src/scan-gram.l
@@ -89,14 +89,14 @@ static boundary scanner_cursor;
verify (UCHAR_MAX < ULONG_MAX); \
long c = Char; \
if (0 < c && c <= UCHAR_MAX) \
- obstack_1grow (&obstack_for_string, c); \
+ STRING_1GROW (c); \
else \
{ \
complain (loc, complaint, \
_("invalid number after \\-escape: %s"), \
yytext + 1); \
/* Avoid additional errors about empty char literal. */ \
- obstack_1grow (&obstack_for_string, '?'); \
+ STRING_1GROW ('?'); \
} \
} while (0)
@@ -661,16 +661,16 @@ eqopt ({sp}=)?
STRING_GROW_ESCAPE (strtol (yytext + 2, NULL, 16));
}
- \\a obstack_1grow (&obstack_for_string, '\a');
- \\b obstack_1grow (&obstack_for_string, '\b');
- \\f obstack_1grow (&obstack_for_string, '\f');
- \\n obstack_1grow (&obstack_for_string, '\n');
- \\r obstack_1grow (&obstack_for_string, '\r');
- \\t obstack_1grow (&obstack_for_string, '\t');
- \\v obstack_1grow (&obstack_for_string, '\v');
+ \\a STRING_1GROW ('\a');
+ \\b STRING_1GROW ('\b');
+ \\f STRING_1GROW ('\f');
+ \\n STRING_1GROW ('\n');
+ \\r STRING_1GROW ('\r');
+ \\t STRING_1GROW ('\t');
+ \\v STRING_1GROW ('\v');
/* \\[\"\'?\\] would be shorter, but it confuses xgettext. */
- \\("\""|"'"|"?"|"\\") obstack_1grow (&obstack_for_string, yytext[1]);
+ \\("\""|"'"|"?"|"\\") STRING_1GROW (yytext[1]);
\\(u|U[0-9abcdefABCDEF]{4})[0-9abcdefABCDEF]{4} {
STRING_GROW_ESCAPE (convert_ucn_to_byte (yytext));
@@ -685,7 +685,7 @@ eqopt ({sp}=)?
p = quotearg_style_mem (escape_quoting_style, p, 1);
complain (loc, complaint, _("invalid character after \\-escape: %s"),
p);
- obstack_1grow (&obstack_for_string, '?');
+ STRING_1GROW ('?');
}
}
@@ -766,7 +766,7 @@ eqopt ({sp}=)?
<SC_BRACED_CODE>
{
"}" {
- obstack_1grow (&obstack_for_string, '}');
+ STRING_1GROW ('}');
--nesting;
if (nesting < 0)
@@ -791,7 +791,7 @@ eqopt ({sp}=)?
RETURN_VALUE (BRACED_PREDICATE, last_string);
}
else
- obstack_1grow (&obstack_for_string, '}');
+ STRING_1GROW ('}');
}
}
diff --git a/src/scan-skel.l b/src/scan-skel.l
index a5771639..4c524584 100644
--- a/src/scan-skel.l
+++ b/src/scan-skel.l
@@ -102,9 +102,9 @@ static void output_mapped_file (char const *name);
{
[^@]+ STRING_GROW ();
- "@@" obstack_1grow (&obstack_for_string, '@');
- "@{" obstack_1grow (&obstack_for_string, '[');
- "@}" obstack_1grow (&obstack_for_string, ']');
+ "@@" STRING_1GROW ('@');
+ "@{" STRING_1GROW ('[');
+ "@}" STRING_1GROW (']');
"@'" continue; /* For starting an argument that begins with whitespace. */
@\n continue;
--
2.27.0
- [PATCH 0/9] Fix reports, Akim Demaille, 2020/06/13
- [PATCH 1/9] style: prefer 'FOO ()' to 'FOO' for function-like macros, Akim Demaille, 2020/06/13
- [PATCH 2/9] style: reduce scopes, Akim Demaille, 2020/06/13
- [PATCH 3/9] style: introduce & use STRING_1GROW,
Akim Demaille <=
- [PATCH 4/9] style: factor common bits about string scanning, Akim Demaille, 2020/06/13
- [PATCH 5/9] tests: check reports with conflicts and UTF-8, Akim Demaille, 2020/06/13
- [PATCH 6/9] parser: keep string aliases as the user wrote it, Akim Demaille, 2020/06/13
- [PATCH 7/9] regen, Akim Demaille, 2020/06/13
- [PATCH 8/9] reports: don't escape the labels, Akim Demaille, 2020/06/13
- [PATCH 9/9] reports: the column width differs from the byte count, Akim Demaille, 2020/06/13