Commit Graph

6836 Commits

Author SHA1 Message Date
Akim Demaille
c592202345 examples: clean up
* examples/c/calc/calc.y: Restore to its original state, with
parse.error=detailed instead of parse.error=custom (this example
should be simple).
* examples/c/calc/calc.test: Check syntax errors.
* examples/c/lexcalc/parse.y: Add comments.
2020-01-26 14:02:08 +01:00
Akim Demaille
0917f4dc76 tests: check custom error messages and push parsers
* tests/local.at (AT_LAC_IF): New.
* tests/calc.at: And also check the suppot for LAC.
2020-01-26 13:29:19 +01:00
Akim Demaille
0f792833c2 style: formatting changes
* data/skeletons/lalr1.java: here.
2020-01-26 13:29:19 +01:00
Akim Demaille
b62e063df5 todo: update 2020-01-26 13:29:19 +01:00
Akim Demaille
e6b0612f91 bison: pretend to 3.6 already
* src/parse-gram.y: here.
2020-01-26 13:29:18 +01:00
Akim Demaille
2eb3328afc git: update ignores
* lib/.gitignore: here.
2020-01-26 13:29:18 +01:00
Akim Demaille
81849520cd regen 2020-01-23 08:30:51 +01:00
Akim Demaille
fc2191f137 diagnostics: modernize bison's syntax errors
We used to display the unexpected token first:

    $ bison foo.y
    foo.y:1.8-13: error: syntax error, unexpected %token, expecting character literal or identifier or <tag>
        1 | %token %token
          |        ^~~~~~

GCC uses a different format:

    $ gcc-mp-9 foo.c
    foo.c:1:5: error: expected identifier or '(' before ')' token
        1 | int()()()
          |     ^

and so does Clang:

    $ clang-mp-9.0 foo.c
    foo.c:1:5: error: expected identifier or '('
    int()()()
        ^
    1 error generated.

They display the unexpected token last (or not at all).  Also, they
don't waste width with "syntax error".  Let's try that.  It gives, for
the same example as above:

    $ bison foo.y
    foo.y:1.8-13: error: expected character literal or identifier or <tag> before %token
        1 | %token %token
          |        ^~~~~~

* src/complain.h, src/complain.c (syntax_error): New.
* src/parse-gram.y (yyreport_syntax_error): Use it.
2020-01-23 08:30:28 +01:00
Akim Demaille
6fb362c87a regen 2020-01-23 08:26:33 +01:00
Akim Demaille
46ab1d0cbe diagnostics: report syntax errors in color
* src/parse-gram.y (parse.error): Set to 'custom'.
(yyreport_syntax_error): New.
* data/bison-default.css (.expected, .unexpected): New.
* tests/diagnostics.at: Adjust.
2020-01-23 08:26:33 +01:00
Akim Demaille
f54a5b303b regen 2020-01-23 08:26:33 +01:00
Akim Demaille
2cc361387c diagnostics: translate bison's own tokens
As a test case, support translations in Bison itself.

* src/parse-gram.y: Mark the translatable tokens.
While at it, use clearer names.
* tests/input.at: Adjust expectations.
2020-01-23 08:26:28 +01:00
Akim Demaille
e6d1289f4a diagnostics: handle -fno-caret in the called functions
Don't force callers of location_caret to have to deal with flags that
disable it.

* src/location.h, src/location.c (location_caret)
(location_caret_suggestion): Early return if disabled.
* src/complain.c: Simplify.
2020-01-22 22:31:41 +01:00
Akim Demaille
16c77b4ba2 yacc.c: fixes
* data/skeletons/yacc.c: Avoid warnings about unused functions.
Fix typo.
2020-01-22 22:31:07 +01:00
Adrian Vogelsgesang
172f103c1e larlr1.cc: Reject unsupported values for parse.lac
Just as the yacc.c skeleton, the lalr1.cc skeleton should reject
invalid values for parse.lac.

* data/skeletons/lalr1.cc: check validity of parse.lac
* tests/input.at: new test cases
2020-01-21 06:22:27 +01:00
Akim Demaille
6ada985ff3 parsers: issue tname with i18n markup
Some users would like to avoid having to "parse" the *.y file to find
the strings to translate.  Let's issue the translatable tokens with N_
to allow "parsing" the generated parsers instead.

See
https://lists.gnu.org/archive/html/bison-patches/2019-01/msg00015.html

* src/output.c (prepare_symbol_names): Issue symbol_names with N_()
markup.
2020-01-19 21:23:11 +01:00
Akim Demaille
2e12257803 tests: check token internationalization
* tests/calc.at: Check it.
2020-01-19 21:23:11 +01:00
Akim Demaille
1db962716a regen 2020-01-19 21:23:11 +01:00
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