[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/10] api.token.raw: cannot be used with character literals
From: |
Akim Demaille |
Subject: |
[PATCH 05/10] api.token.raw: cannot be used with character literals |
Date: |
Sun, 1 Sep 2019 18:41:18 +0200 |
* src/parse-gram.y (CHAR): api.token.raw and character literals are
mutually exclusive.
* tests/input.at (Character literals and api.token.raw): New.
---
src/parse-gram.y | 19 ++++++++++++++++---
tests/input.at | 38 ++++++++++++++++++++++++++++++++++++--
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 6a19e571..9fcf8195 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -106,6 +106,7 @@
/* Handle a %yacc directive. */
static void handle_yacc (location const *loc);
+ /* Implementation of yyerror. */
static void gram_error (location const *, char const *);
/* A string that describes a char (e.g., 'a' -> "'a'"). */
@@ -196,7 +197,7 @@
%token BRACED_CODE "{...}"
%token BRACED_PREDICATE "%?{...}"
%token BRACKETED_ID "[identifier]"
-%token CHAR "char"
+%token CHAR "character literal"
%token COLON ":"
%token EPILOGUE "epilogue"
%token EQUAL "="
@@ -732,12 +733,24 @@ id:
{ $$ = symbol_from_uniqstr ($1, @1); }
| CHAR
{
+ const char *var = "api.token.raw";
if (current_class == nterm_sym)
{
- gram_error (&@1,
- _("character literals cannot be nonterminals"));
+ complain (&@1, complaint,
+ _("character literals cannot be nonterminals"));
YYERROR;
}
+ if (muscle_percent_define_ifdef (var))
+ {
+ unsigned indent = 0;
+ complain_indent (&@1, complaint, &indent,
+ _("character literals cannot be used together"
+ " with %s"), var);
+ indent += SUB_INDENT;
+ location loc = muscle_percent_define_get_loc (var);
+ complain_indent (&loc, complaint, &indent,
+ _("definition of %s"), var);
+ }
$$ = symbol_get (char_name ($1), @1);
symbol_class_set ($$, token_sym, @1, false);
symbol_user_token_number_set ($$, $1, @1);
diff --git a/tests/input.at b/tests/input.at
index 578e63cb..edb61f84 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -232,10 +232,10 @@ input.y:3.17-24: error: nonterminals cannot be given a
string alias
input.y:4.8-10: error: character literals cannot be nonterminals
4 | %nterm '+' '*';
| ^~~
-input.y:5.8-15: error: syntax error, unexpected string, expecting char or
identifier or <tag>
+input.y:5.8-15: error: syntax error, unexpected string, expecting character
literal or identifier or <tag>
5 | %nterm "number";
| ^~~~~~~~
-input.y:6.8-13: error: syntax error, unexpected string, expecting char or
identifier or <tag>
+input.y:6.8-13: error: syntax error, unexpected string, expecting character
literal or identifier or <tag>
6 | %token "tok1" 1;
| ^~~~~~
input.y:7.14: error: syntax error, unexpected integer
@@ -2722,3 +2722,37 @@ AT_BISON_CHECK([[-fcaret input.y]], [[0]], [[]],
AT_BISON_OPTION_POPDEFS
AT_CLEANUP
+
+
+
+## -------------------------------------- ##
+## Character literals and api.token.raw. ##
+## -------------------------------------- ##
+
+AT_SETUP([[Character literals and api.token.raw]])
+
+AT_BISON_OPTION_PUSHDEFS
+AT_DATA_GRAMMAR([[input.y]],
+[[%define api.token.raw
+%token 'a'
+%%
+exp: 'b' "c" {}
+]])
+
+AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
+[[input.y:10.8-10: error: character literals cannot be used together with
api.token.raw
+ 10 | %token 'a'
+ | ^~~
+input.y:9.1-21: definition of api.token.raw
+ 9 | %define api.token.raw
+ | ^~~~~~~~~~~~~~~~~~~~~
+input.y:12.6-8: error: character literals cannot be used together with
api.token.raw
+ 12 | exp: 'b' "c" {}
+ | ^~~
+input.y:9.1-21: definition of api.token.raw
+ 9 | %define api.token.raw
+ | ^~~~~~~~~~~~~~~~~~~~~
+]])
+
+AT_BISON_OPTION_POPDEFS
+AT_CLEANUP
--
2.23.0
- RFC: Introduce api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 01/10] style: tidy yacc.c, Akim Demaille, 2019/09/01
- [PATCH 02/10] api.token.raw: implement, Akim Demaille, 2019/09/01
- [PATCH 03/10] api.token.raw: check it, Akim Demaille, 2019/09/01
- [PATCH 04/10] api.token.raw: apply to the other skeletons, Akim Demaille, 2019/09/01
- [PATCH 05/10] api.token.raw: cannot be used with character literals,
Akim Demaille <=
- [PATCH 06/10] api.token.raw: document it, Akim Demaille, 2019/09/01
- [PATCH 07/10] parser: use api.token.raw, Akim Demaille, 2019/09/01
- [PATCH 09/10] d: handle eof in yytranslate, Akim Demaille, 2019/09/01
- [PATCH 10/10] java: handle eof in yytranslate, Akim Demaille, 2019/09/01
- [PATCH 08/10] regen, Akim Demaille, 2019/09/01
- Re: RFC: Introduce api.token.raw, Akim Demaille, 2019/09/14