Commit Graph

6768 Commits

Author SHA1 Message Date
Akim Demaille
9096955fba parsers: support translatable token aliases
In addition to

    %token NUM "number"

accept

    %token NUM _("number")

in which case the token will be translated in error messages.
Do not use _() in the output if there are no translatable tokens.

* src/symtab.h, src/symtab.c (symbol): Add a 'translatable' member.
* src/parse-gram.y (TSTRING): New token.
(string_as_id.opt): Replace with...
(alias): this.
Use it.
* src/scan-gram.l (SC_ESCAPED_TSTRING): New start conditions, to match
TSTRINGs.
* src/output.c (prepare_symbols): Define b4_translatable if there are
translatable strings.

* data/skeletons/glr.c, data/skeletons/lalr1.cc,
* data/skeletons/yacc.c (yytnamerr): Receive b4_translatable, and use it.
2020-01-19 21:23:11 +01:00
Akim Demaille
e9d404415a tests: check that detailed error messages preserve UTF-8 characters
* tests/regression.at: here.
2020-01-19 21:23:03 +01:00
Akim Demaille
d9df62bfcd yacc.c: escape trigraphs in detailed parse.error
* src/output.c (escape_trigraphs, xescape_trigraphs): New.
(prepare_symbol_names): Use it.
* tests/regression.at: Check the handling of trigraphs with
parse.error = detailed.
2020-01-19 21:22:41 +01:00
Akim Demaille
adac9a17f0 regen 2020-01-19 14:51:14 +01:00
Akim Demaille
3b4b157369 bison: use detailed error messages
* #: .
2020-01-19 14:51:14 +01:00
Akim Demaille
5c332d70d7 regen 2020-01-19 14:51:14 +01:00
Akim Demaille
91247f50d7 yacc.c: tests: check detailed error messages
* tests/local.at (AT_ERROR_DETAILED_IF): New.
(AT_ERROR_SIMPLE_IF): Adjust.
* tests/calc.at: Check parse.error=detailed.
2020-01-19 14:51:14 +01:00
Akim Demaille
f443673450 yacc.c: add support for parse.error detailed
"detailed" error messages are almost like "verbose", except that we
don't double escape them, they don't get inner quotes, we don't use
yytnamerr, and we hide the table.

"custom" is exposed with the "detailed" tokens, not the "verbose"
ones: they are not double-quoted.

Because there's a risk that some people use yytname even without
"verbose", let's keep yytname (instead of yys_name) in "simple"
parse.error.

* src/output.c (prepare_symbol_names): Be ready to output symbol names
unquoted.
(prepare_symbol_names): Output both the old tname table, and the new
symbol_names one.
* data/skeletons/bison.m4: Accept 'detailed'.
* data/skeletons/yacc.c: When parse.error is 'detailed', don't emit
yytname and yytnamerr, just yysymbol_name with the table inside.
* tests/calc.at: Adjust.
2020-01-19 14:51:14 +01:00
Akim Demaille
8e6233353f c: use yysymbol_name in traces
Only parse.error verbose and simple will get the original yytname: the
other options will rely on a different table.  So let's move on top of
the yysymbol_name function.

* data/skeletons/c.m4 (yy_symbol_print): Use yysymbol_name.
* data/skeletons/glr.c (yytokenName): Rename as...
(yysymbol_name): this.
The change of naming scheme is unfortunate, but it's definitely glr.c
which is "wrong".
2020-01-19 14:51:14 +01:00
Akim Demaille
e5a5da16ed glr.c: move some functions after the definition of types
Currently yy_symbol_print is defined before yytokenName, although it
should use it instead of read yytname directly.  Move blocks around to
avoid this.

* data/skeletons/glr.c (yy_symbol_print): Move its definition after
that of yytokenName.
2020-01-19 14:51:14 +01:00
Akim Demaille
ebe427bbf3 Merge branch 'maint'
* maint:
  maint: post-release administrivia
  version 3.5.1
  news: update
  CI: use ICC again
  warnings: pacify ICC in lalr1.cc
  test: report.at: avoid tiny new failure
  git: update ignores
2020-01-19 14:50:09 +01:00
Akim Demaille
7e3a513d88 maint: post-release administrivia
* NEWS: Add header line for next release.
* .prev-version: Record previous version.
* cfg.mk (old_NEWS_hash): Auto-update.
2020-01-19 14:35:50 +01:00
Akim Demaille
57f64ebbf8 version 3.5.1
* NEWS: Record release date.
v3.5.1
2020-01-19 14:17:48 +01:00
Akim Demaille
c8d997cb5f news: update 2020-01-19 14:10:46 +01:00
Akim Demaille
61b8a8def5 CI: use ICC again
See https://github.com/nemequ/icc-travis/issues/15.
Thanks to Jeff Hammond and Evan Nemerson for their help.

* configure.ac (warn_common): Disable dubious warnings.
* .travis.yml: Use ICC again.
2020-01-19 11:36:47 +01:00
Akim Demaille
6990c5bde9 warnings: pacify ICC in lalr1.cc
See 139d065594.

* data/skeletons/yacc.c: If I might be a char, write a[+I] instead of
a[I], so that ICC does not complain.
2020-01-19 11:35:26 +01:00
Jim Meyering
27e822abfd test: report.at: avoid tiny new failure
Be robust to newer versions of Autoconf where the package URL defaults
to https instead of http.

* configure.ac (AC_INIT): Use https.
* tests/report.at: Adjust expected output s/http/https/
to match updated URL.
2020-01-19 10:03:01 +01:00
Akim Demaille
21ba496083 git: update ignores 2020-01-19 10:02:55 +01:00
Akim Demaille
c6e2dcabae regen 2020-01-17 06:51:24 +01:00
Akim Demaille
e1197fcc3d yacc.c: portability to G++ 4.8
Currently we get warnings with GCC 4.8 when running the
maintainer-check-g++ tests:

    143. skeletons.at:85: testing Installed skeleton file names ...
    ../../tests/skeletons.at:120: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret --skeleton=yacc.c -o input-cmd-line.c input-cmd-line.y
    ../../tests/skeletons.at:121: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o input-cmd-line input-cmd-line.c $LIBS
    stderr:
    input-cmd-line.c: In function 'int yysyntax_error(long int*, char**, const yyparse_context_t*)':
    input-cmd-line.c:977:52: error: conversion to 'int' from 'long int' may alter its value [-Werror=conversion]
                                       YYSIZEOF (yyarg) / YYSIZEOF (*yyarg));
                                                        ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/skeletons.at:121: exit code was 1, expected 0

and

    429. calc.at:823: testing Calculator parse.error=custom %locations api.prefix={calc}  ...
    ../../tests/calc.at:823: COLUMNS=1000; export COLUMNS;  bison --color=no -fno-caret -Wno-deprecated -o calc.c calc.y
    ../../tests/calc.at:823: $CC $CFLAGS $CPPFLAGS  $LDFLAGS -o calc calc.c $LIBS
    stderr:
    calc.y: In function 'int yyreport_syntax_error(const yyparse_context_t*)':
    calc.y:157:58: error: conversion to 'int' from 'long unsigned int' may alter its value [-Werror=conversion]
       int n = yysyntax_error_arguments (ctx, arg, sizeof arg / sizeof *arg);
                                                              ^
    cc1plus: all warnings being treated as errors
    stdout:
    ../../tests/calc.at:823: exit code was 1, expected 0

We could use a cast to avoid the warning, but it becomes too
cluttered.  We can also use YYPTRDIFF_T, but that forces the user to
use YYPTRDIFF_T too, although this is an array of tokens, which is
limited by YYNTOKENS, an int.  So let's completely avoid this warning.

* data/skeletons/yacc.c, tests/local.at (yyreport_syntax_error): Avoid
relying on sizeof to compute the array capacity.
2020-01-17 06:49:59 +01:00
Akim Demaille
1854429e40 yacc.c: pass the parse-params to yyreport_syntax_error
Enhance the calculator tests: show that passing arguments to yyerror
works.

* tests/calc.at: Add a new parse-param, nerrs, which counts the number
of syntax errors in a run.
* tests/local.at: Adjust to handle the new 'nerrs' argument, when
present.

The custom error reporting function show sees the user's additional
arguments.  Let's experiment with passing them as arguments to
yyreport_syntax_error, but maybe storing them in the context would be
a bettter alternative.

* data/skeletons/yacc.c (yyreport_syntax_error): Handle the
parse-params.
* tests/calc.at, tests/local.at: Adjust.
2020-01-17 06:49:59 +01:00
Akim Demaille
cece227f95 tests: a clearer test for parse-params
Currently the parse-params are tested in calc.at by checking that the
global variable and the parse-params have the same value.  But it does
not check that value, that could remain being 0 just as well.

* tests/calc.at: Don't define the params when they are not used.
Check the final value of result and count.
Also, do count the number of line of logs.
2020-01-17 06:49:59 +01:00
Akim Demaille
e83077c617 yacc.c: check custom error messages with parse-params
* tests/calc.at: Check with prefix and parse-params.
2020-01-17 06:49:59 +01:00
Akim Demaille
fd33cc9c8b yacc.c: let custom error messages see the location
* data/skeletons/yacc.c (yyparse_context_t): Add yylloc when
applicable.
(yyparse_context_location): New.
* tests/local.at (AT_YYERROR_DEFINE(c)): Handle the location.
* tests/calc.at: Check it.
2020-01-17 06:49:59 +01:00
Akim Demaille
8637438cee yacc.c: isolate yyexpected_tokens
Provide users with a means to query for the currently allowed tokens.
Could be used for autocompletion for instance.

* data/skeletons/yacc.c (yyexpected_tokens): New, extracted from
yysyntax_error_arguments.
* examples/c/calc/calc.y (PRINT_EXPECTED_TOKENS): New.
Use it.
2020-01-17 06:49:59 +01:00
Akim Demaille
ee97f37cb4 tests: compute verbose error messages from the custom ones
We use a different format to check parse.error custom.  Compute the
"verbose" one from it instead of forcing the test author to provide
the various formats of expected error messages.

* tests/calc.at (_AT_CHECK_CALC_ERROR): Handle this transformation
when needed.
Simplify callers.
2020-01-17 06:49:59 +01:00
Akim Demaille
68ef3a0466 yacc.c: check custom error messages
* tests/local.at (AT_ERROR_CUSTOM_IF, AT_ERROR_VERBOSE_IF)
(AT_ERROR_SIMPLE_IF): New.
(AT_YYERROR_DEFINE(c)): Generate yyreport_syntax_error.
* tests/calc.at (_AT_CHECK_CALC_ERROR): Accept custom error messages
as additional test case.
Use it.
Add a new test case for %define parse.error custom.
2020-01-17 06:49:59 +01:00
Akim Demaille
cda1934606 yacc.c: add custom error message generation
When parse.error is custom, let users define a yyreport_syntax_error
function, and use it.

* data/skeletons/bison.m4 (b4_error_verbose_if): Accept 'custom'.
* data/skeletons/yacc.c: Implement it.
* examples/c/calc/calc.y: Experiment with it.
2020-01-17 06:49:59 +01:00
Akim Demaille
5b883180e6 yacc.c: style: avoid macros
* data/skeletons/yacc.c (YYSYNTAX_ERROR): Remove, the call is now
sufficiently small so that we can afford to duplicate it.
2020-01-17 06:49:59 +01:00
Akim Demaille
135d0336d5 yacc.c: store token numbers, not token strings
That allows users to cover more cases, such as easily filtering some
arguments they don't want to expose.  But they now have to call
yysymbol_name explicitly.

* data/skeletons/yacc.c (yysyntax_error_arguments, yysyntax_error):
Deal with symbol numbers instead of symbol names.
2020-01-17 06:49:59 +01:00
Akim Demaille
cc6c647f00 yacc.c: extract yyerror_message_arguments
Isolate a function that returns the list of expected and unexpected
tokens.  It will be exposed to users willing to customize their error
messages.

* data/skeletons/yacc.c (yyparse_context_t): New.
(yyerror_message_arguments): New, extracted from yysyntax_error.
2020-01-17 06:49:59 +01:00
Akim Demaille
a1aef9825a regen 2020-01-17 06:49:45 +01:00
Akim Demaille
ece99a890c tests: make AT_PARSE_PARAMS usable at the end of arguments
When not empty, AT_PARSE_PARAMS was guaranteed to end with a comma.
Remove the trailing comma, so that we can use AT_PARSE_PARAMS at the
end of the arguments, not only at the beginning.

* tests/local.at: here.
Unfortunately, m4_append relies on the macro not being defined whereas
we would have preferred it to check for emptiness.  So use
m4_define/m4_undefine instead of m4_pushdef/m4_popdef.
2020-01-15 08:55:51 +01:00
Akim Demaille
169c2530e4 tests: fix AT_BISON_OPTION_PUSHDEFS, AT_BISON_OPTION_POPDEFS pairs
* tests/glr-regression.at, tests/java.at, tests/javapush.at:
Close properly what is opened.
Do not nest.
2020-01-15 08:54:52 +01:00
Akim Demaille
c894a6e2ce d, java: use traces more alike that of C
Same order, same places, same content.

* data/skeletons/lalr1.d, data/skeletons/lalr1.java: here.
2020-01-15 06:23:46 +01:00
Akim Demaille
187c2ac344 c++: report the stack at the same places as in C
Let's have C be the reference, and match it elsewhere.  Maybe C is too
verbose and some adjustments are needed, but then that would be done
in another batch of patches.

* data/skeletons/lalr1.cc: Print the stack once we popped after
YYERROR, and before emptying the stack at the end of parsing.
2020-01-15 06:22:42 +01:00
Akim Demaille
f06c0d2c05 c++: display the stack in the same order as in C
Currently the C and C++ parse traces differ in the order in which the
stack is displayed: bottom up in C, top down in C++.  Let's stick to
the C order.

* data/skeletons/stack.hh (stack::iterator, stack::const_iterator)
(begin, end): Be forward, not backward.
2020-01-15 06:22:31 +01:00
Akim Demaille
975be86ccc style: avoid redundancy in the tests
* tests/local.at (m4_rpatsubst): New.
Use it to handle %parse-params.
* tests/calc.at: Use %parse-params with several arguments.
2020-01-15 06:22:19 +01:00
Akim Demaille
1c0adb410d yacc.c: comment changes
In particular, import Adrian Vogelsgesang's comments about LAC from
lalr1.cc.

* data/skeletons/yacc.c: here.
2020-01-11 18:01:39 +01:00
Akim Demaille
32b529f038 yacc.c: style: double-quote the argument of b4_percent_define_get
* data/skeletons/yacc.c: Here, for consistency.
2020-01-11 17:35:24 +01:00
Akim Demaille
46cce832fd yacc.c: introduce yysymbol_name
Provide the users with a public API to get the name of the tokens.  A
thin wrapper around yytname.

* data/skeletons/yacc.c (yysymbol_name): New.
Use it.
2020-01-11 16:14:06 +01:00
Akim Demaille
98a1045bea CI: check on PPC64le, ARM64 and s390x
I was hoping it would help us catch warnings when char is
unsigned (see 78bb152a63), but it does
not seem to help.  It's a pity that the compiler is the same all over
the place, I would have preferred testing others.

* .travis.yml: here.
2020-01-11 16:11:45 +01:00
Akim Demaille
8426663631 todo: update 2020-01-11 08:59:51 +01:00
Akim Demaille
a0675d707f Merge branch 'maint' into HEAD
* maint:
  gnulib: update
  lalr1.cc: avoid static_cast
  glr.c: add missing cast
  regen
  package: bump copyrights to 2020
  gitignore: update
2020-01-11 07:38:39 +01:00
Akim Demaille
9cf0a97aa9 gnulib: update 2020-01-11 06:03:51 +01:00
Akim Demaille
3dec8a4caf lalr1.cc: avoid static_cast
Reported by donmac703.
Fixes https://github.com/akimd/bison/issues/20.

* data/skeletons/lalr1.cc: here.
2020-01-10 19:31:00 +01:00
Akim Demaille
2cb52c5a91 glr.c: add missing cast
Reported by psjo.
Fixes https://github.com/akimd/bison/issues/19.

* data/skeletons/glr.c (yyprocessOneStack): Here.
2020-01-10 19:30:54 +01:00
Akim Demaille
04f3bfc596 regen 2020-01-10 19:21:35 +01:00
Akim Demaille
c67daa9a97 package: bump copyrights to 2020
Run 'make update-copyright'.
2020-01-10 19:16:23 +01:00
Akim Demaille
2ca8e86f83 gitignore: update 2020-01-10 19:16:16 +01:00