mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
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.
This commit is contained in:
@@ -545,10 +545,11 @@ AT_PARSER_CHECK([calc input], 0, [], [stderr])
|
||||
])
|
||||
|
||||
|
||||
# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,
|
||||
# [NUM-STDERR-LINES],
|
||||
# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
|
||||
# ---------------------------------------------------------
|
||||
# _AT_CHECK_CALC_ERROR($1 = BISON-OPTIONS, $2 = EXIT-STATUS, $3 = INPUT,
|
||||
# $4 = [NUM-STDERR-LINES],
|
||||
# $5 = [VERBOSE-AND-LOCATED-ERROR-MESSAGE]
|
||||
# $6 = [CUSTOM-ERROR-MESSAGE])
|
||||
# ----------------------------------------------------------------------
|
||||
# Run 'calc' on INPUT, and expect a 'syntax error' message.
|
||||
#
|
||||
# If INPUT starts with a slash, it is used as absolute input file name,
|
||||
@@ -595,9 +596,15 @@ sed '/^Starting/d
|
||||
mv at-stderr stderr
|
||||
|
||||
# 2. Create the reference error message.
|
||||
AT_DATA([[expout]],
|
||||
AT_ERROR_CUSTOM_IF([
|
||||
AT_DATA([[expout]],
|
||||
[$6
|
||||
])
|
||||
],
|
||||
[AT_DATA([[expout]],
|
||||
[$5
|
||||
])
|
||||
])
|
||||
|
||||
# 3. If locations are not used, remove them.
|
||||
AT_YYERROR_SEES_LOC_IF([],
|
||||
@@ -605,7 +612,7 @@ AT_YYERROR_SEES_LOC_IF([],
|
||||
mv at-expout expout]])
|
||||
|
||||
# 4. If error-verbose is not used, strip the', unexpected....' part.
|
||||
m4_bmatch([$1], [%define parse.error verbose], [],
|
||||
AT_ERROR_SIMPLE_IF(
|
||||
[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
|
||||
mv at-expout expout]])
|
||||
|
||||
@@ -668,21 +675,27 @@ _AT_CHECK_CALC([$1],
|
||||
|
||||
# Some syntax errors.
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 2], [15],
|
||||
[1.3: syntax error, unexpected number])
|
||||
[[1.3: syntax error, unexpected number]],
|
||||
[[1.3: syntax error on token ["number"] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] ['\n'])]])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
|
||||
[1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
|
||||
[[1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!']],
|
||||
[[1.3: syntax error on token ['/'] (expected: ["number"] ['-'] ['('] ['!'])]])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
|
||||
[1.1: syntax error, unexpected $undefined])
|
||||
[[1.1: syntax error, unexpected $undefined]],
|
||||
[[1.1: syntax error on token [$undefined] (expected: ["number"] ['-'] ['\n'] ['('] ['!'])]])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
|
||||
[1.7: syntax error, unexpected '='])
|
||||
[[1.7: syntax error, unexpected '=']],
|
||||
[[1.7: syntax error on token ['='] (expected: ['-'] ['+'] ['*'] ['/'] ['^'])]])
|
||||
_AT_CHECK_CALC_ERROR([$1], [1],
|
||||
[
|
||||
+1],
|
||||
[20],
|
||||
[2.1: syntax error, unexpected '+'])
|
||||
[[2.1: syntax error, unexpected '+']],
|
||||
[[2.1: syntax error on token ['+'] (expected: ["end of input"] ["number"] ['-'] ['\n'] ['('] ['!'])]])
|
||||
# Exercise error messages with EOF: work on an empty file.
|
||||
_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
|
||||
[1.1: syntax error, unexpected end of input])
|
||||
[[1.1: syntax error, unexpected end of input]],
|
||||
[[1.1: syntax error on token ["end of input"] (expected: ["number"] ['-'] ['\n'] ['('] ['!'])]])
|
||||
|
||||
# Exercise the error token: without it, we die at the first error,
|
||||
# hence be sure to
|
||||
@@ -703,28 +716,41 @@ _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
|
||||
_AT_CHECK_CALC_ERROR([$1], [0],
|
||||
[() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
|
||||
[250],
|
||||
[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
||||
[[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
||||
1.18: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
|
||||
1.23: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
1.41: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
calc: error: 4444 != 1])
|
||||
calc: error: 4444 != 1]],
|
||||
[[1.2: syntax error on token [')'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.18: syntax error on token [')'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.23: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.41: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
calc: error: 4444 != 1]])
|
||||
|
||||
# The same, but this time exercising explicitly triggered syntax errors.
|
||||
# POSIX says the lookahead causing the error should not be discarded.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1], [102],
|
||||
[1.10: syntax error, unexpected number
|
||||
calc: error: 2222 != 1])
|
||||
[[1.10: syntax error, unexpected number
|
||||
calc: error: 2222 != 1]],
|
||||
[[1.10: syntax error on token ["number"] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
|
||||
calc: error: 2222 != 1]])
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1], [113],
|
||||
[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
[[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
1.12: syntax error, unexpected number
|
||||
calc: error: 2222 != 1])
|
||||
calc: error: 2222 != 1]],
|
||||
[[1.4: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.12: syntax error on token ["number"] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
|
||||
calc: error: 2222 != 1]])
|
||||
|
||||
# Check that yyerrok works properly: second error is not reported,
|
||||
# third and fourth are. Parse status is succesful.
|
||||
_AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)], [113],
|
||||
[1.2: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
[[1.2: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
1.10: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
|
||||
1.16: syntax error, unexpected '*', expecting number or '-' or '(' or '!'])
|
||||
1.16: syntax error, unexpected '*', expecting number or '-' or '(' or '!']],
|
||||
[[1.2: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.10: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])
|
||||
1.16: syntax error on token ['*'] (expected: ["number"] ['-'] ['('] ['!'])]])
|
||||
|
||||
AT_BISON_OPTION_POPDEFS
|
||||
|
||||
@@ -777,6 +803,8 @@ AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locatio
|
||||
AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}])
|
||||
|
||||
|
||||
AT_CHECK_CALC_LALR([%define parse.error custom])
|
||||
|
||||
# ----------------------- #
|
||||
# Simple GLR Calculator. #
|
||||
# ----------------------- #
|
||||
|
||||
Reference in New Issue
Block a user