lalr1.cc: syntax_error as exceptions.

It is common to use sort of factories in the user actions.  These
factories may check some "syntactic" constraints that are not
enforced by the grammar itself.  This is possible using YYERROR
within the action itself.  Provide the user with a means to throw
a syntax_error exception.

	* data/c++.m4 (b4_public_types_declare, b4_public_types_define):
	Declare and define yy::parser::syntax_error.
	* data/lalr1.cc: Include stdexcept.
	(yy::parser::parse): Wrap the user action within a try/catch.
	* data/glr.cc: Include stdexcept.
This commit is contained in:
Akim Demaille
2009-09-08 22:00:13 +02:00
parent 2966006237
commit ff60136654
4 changed files with 42 additions and 2 deletions

View File

@@ -126,6 +126,13 @@ m4_define([b4_public_types_declare],
/// Symbol locations.
typedef b4_percent_define_get([[location_type]]) location_type;])[
/// Syntax errors thrown from user actions.
struct syntax_error : std::runtime_error
{
syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m);]b4_locations_if([
location_type location;])[
};
/// Tokens.
struct token
{
@@ -195,8 +202,15 @@ m4_define([b4_public_types_declare],
# ----------------------
# Provide the implementation needed by the public types.
m4_define([b4_public_types_define],
[[ // symbol_base_type.
[[ inline
]b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m)
: std::runtime_error (m)]b4_locations_if([
, location (l)])[
{}
// symbol_base_type.
template <typename Exact>
inline
]b4_parser_class_name[::symbol_base_type<Exact>::symbol_base_type ()
: value()]b4_locations_if([
, location()])[