[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/4] c: rename yyexpected_tokens as yypcontext_expected_tokens
From: |
Akim Demaille |
Subject: |
[PATCH 1/4] c: rename yyexpected_tokens as yypcontext_expected_tokens |
Date: |
Sun, 12 Apr 2020 19:27:05 +0200 |
The user should think of yypcontext fields as accessible only via
yypcontext_* functions. So let's rename yyexpected_tokens to reflect
that.
Let's _not_ rename yyreport_syntax_error, as the user may define this
function, and is not allowed to access directly the fields of
yypcontext_t: she *must* use the "accessors". This is comparable to
the case of C++/Java where the user defines
parser::report_syntax_error, not parser::context::report_syntax_error.
* data/skeletons/glr.c, data/skeletons/yacc.c (yyexpected_tokens):
Rename as...
(yypcontext_expected_tokens): this.
Adjust dependencies.
---
NEWS | 2 +-
data/skeletons/glr.c | 7 ++++---
data/skeletons/yacc.c | 15 ++++++++-------
examples/c/bistromathic/parse.y | 2 +-
src/parse-gram.c | 6 +++---
src/parse-gram.y | 2 +-
tests/local.at | 2 +-
7 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/NEWS b/NEWS
index 861edad3..3fc4eaae 100644
--- a/NEWS
+++ b/NEWS
@@ -46,7 +46,7 @@ GNU Bison NEWS
{
enum { TOKENMAX = 10 };
yysymbol_kind_t expected[TOKENMAX];
- int n = yyexpected_tokens (ctx, expected, TOKENMAX);
+ int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
if (n < 0)
// Forward errors to yyparse.
res = n;
diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 1fd042fb..345788d1 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -2088,8 +2088,8 @@ yyprocessOneStack (yyGLRStack* yystackp, ptrdiff_t yyk,
YYARG is null, return the number of expected tokens (guaranteed to
be less than YYNTOKENS). */
static int
-yyexpected_tokens (const yyGLRStack* yystackp,
- yysymbol_kind_t yyarg[], int yyargn)
+yypcontext_expected_tokens (const yyGLRStack* yystackp,
+ yysymbol_kind_t yyarg[], int yyargn)
{
/* Actual size of YYARG. */
int yycount = 0;
@@ -2190,7 +2190,8 @@ yy_syntax_error_arguments (const yyGLRStack* yystackp,
if (yyarg)
yyarg[yycount] = yytoken;
++yycount;
- yyn = yyexpected_tokens (yystackp, yyarg ? yyarg + 1 : yyarg, yyargn -
1);
+ yyn = yypcontext_expected_tokens (yystackp,
+ yyarg ? yyarg + 1 : yyarg, yyargn - 1);
if (yyn == YYENOMEM)
return YYENOMEM;
else
diff --git a/data/skeletons/yacc.c b/data/skeletons/yacc.c
index 73679084..b71c1ff5 100644
--- a/data/skeletons/yacc.c
+++ b/data/skeletons/yacc.c
@@ -1140,8 +1140,8 @@ static int
yypstate_expected_tokens (yypstate *yyps,
yysymbol_kind_t yyarg[], int yyargn)]], [[
static int
-yyexpected_tokens (const yypcontext_t *yyctx,
- yysymbol_kind_t yyarg[], int yyargn)]])[
+yypcontext_expected_tokens (const yypcontext_t *yyctx,
+ yysymbol_kind_t yyarg[], int yyargn)]])[
{
/* Actual size of YYARG. */
int yycount = 0;
@@ -1196,8 +1196,8 @@ yyexpected_tokens (const yypcontext_t *yyctx,
]b4_push_if([[
/* Similar to the previous function. */
static int
-yyexpected_tokens (const yypcontext_t *yyctx,
- yysymbol_kind_t yyarg[], int yyargn)
+yypcontext_expected_tokens (const yypcontext_t *yyctx,
+ yysymbol_kind_t yyarg[], int yyargn)
{
return yypstate_expected_tokens (yyctx->yyps, yyarg, yyargn);
}]])[
@@ -1359,7 +1359,8 @@ yy_syntax_error_arguments (const yypcontext_t *yyctx,
if (yyarg)
yyarg[yycount] = yyctx->yytoken;
++yycount;
- yyn = yyexpected_tokens (yyctx, yyarg ? yyarg + 1 : yyarg, yyargn - 1);
+ yyn = yypcontext_expected_tokens (yyctx,
+ yyarg ? yyarg + 1 : yyarg, yyargn - 1);
if (yyn == YYENOMEM)
return YYENOMEM;]b4_lac_if([[
else if (yyn == 0)
@@ -1513,8 +1514,8 @@ void
yypstate_clear (yypstate *yyps)
{
]b4_initialize_parser_state_variables[
- /* Initialize the state stack, in case yyexpected_tokens is called
- before the first call to yyparse. */
+ /* Initialize the state stack, in case yypcontext_expected_tokens is
+ called before the first call to yyparse. */
*yyssp = 0;
}
diff --git a/examples/c/bistromathic/parse.y b/examples/c/bistromathic/parse.y
index 4d4b1e45..54002d29 100644
--- a/examples/c/bistromathic/parse.y
+++ b/examples/c/bistromathic/parse.y
@@ -290,7 +290,7 @@ yyreport_syntax_error (const yypcontext_t *ctx)
{
enum { TOKENMAX = 10 };
yysymbol_kind_t expected[TOKENMAX];
- int n = yyexpected_tokens (ctx, expected, TOKENMAX);
+ int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
if (n < 0)
// Forward errors to yyparse.
res = n;
diff --git a/src/parse-gram.c b/src/parse-gram.c
index fb74a582..f476a935 100644
--- a/src/parse-gram.c
+++ b/src/parse-gram.c
@@ -1597,8 +1597,8 @@ typedef struct
Return 0 if there are more than YYARGN expected tokens, yet fill
YYARG up to YYARGN. */
static int
-yyexpected_tokens (const yypcontext_t *yyctx,
- yysymbol_kind_t yyarg[], int yyargn)
+yypcontext_expected_tokens (const yypcontext_t *yyctx,
+ yysymbol_kind_t yyarg[], int yyargn)
{
/* Actual size of YYARG. */
int yycount = 0;
@@ -2807,7 +2807,7 @@ yyreport_syntax_error (const yypcontext_t *ctx)
{
argv[argc++] = yysymbol_name (unexpected);
yysymbol_kind_t expected[ARGS_MAX - 1];
- int nexpected = yyexpected_tokens (ctx, expected, ARGS_MAX - 1);
+ int nexpected = yypcontext_expected_tokens (ctx, expected, ARGS_MAX - 1);
if (nexpected < 0)
res = nexpected;
else
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 9980355a..d09f49a7 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -811,7 +811,7 @@ yyreport_syntax_error (const yypcontext_t *ctx)
{
argv[argc++] = yysymbol_name (unexpected);
yysymbol_kind_t expected[ARGS_MAX - 1];
- int nexpected = yyexpected_tokens (ctx, expected, ARGS_MAX - 1);
+ int nexpected = yypcontext_expected_tokens (ctx, expected, ARGS_MAX - 1);
if (nexpected < 0)
res = nexpected;
else
diff --git a/tests/local.at b/tests/local.at
index 73319a18..2cda26bc 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -646,7 +646,7 @@ yyreport_syntax_error (const yypcontext_t
*ctx]AT_PARAM_IF([, AT_PARSE_PARAMS])[
{
enum { TOKENMAX = 10 };
yysymbol_kind_t expected[TOKENMAX];
- int n = yyexpected_tokens (ctx, expected, TOKENMAX);
+ int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
/* Forward errors to yyparse. */
if (n <= 0)
res = n;
--
2.26.0
- [PATCH 0/4] Doc: update, and document "kinds", Akim Demaille, 2020/04/12
- [PATCH 1/4] c: rename yyexpected_tokens as yypcontext_expected_tokens,
Akim Demaille <=
- [PATCH 2/4] doc: document yypcontext_t, and api.symbol.prefix, Akim Demaille, 2020/04/12
- [PATCH 4/4] doc: use "code", not "number", for token (and symbol) kinds, Akim Demaille, 2020/04/12
- [PATCH 3/4] doc: promote yytoken_kind_t, not yytokentype, Akim Demaille, 2020/04/12