]> git.saurik.com Git - bison.git/commitdiff
tests: lalr1.cc: check syntax_error.
authorAkim Demaille <demaille@gostai.com>
Thu, 9 Feb 2012 09:34:00 +0000 (10:34 +0100)
committerAkim Demaille <demaille@gostai.com>
Fri, 10 Feb 2012 08:17:45 +0000 (09:17 +0100)
* tests/c++.at (Syntax error as exception): New.

tests/c++.at

index d81a1fb38faf28247025ad026bd583db049272af..36c4d992386029d6ceeb7bd7eb6d97a9c173a971 100644 (file)
@@ -448,3 +448,78 @@ Reducing 'a'.
 ]])
 
 AT_CLEANUP
+
+
+## --------------------------- ##
+## Syntax error as exception.  ##
+## --------------------------- ##
+
+AT_SETUP([[Syntax error as exception]])
+
+AT_DATA_GRAMMAR([[input.yy]],
+[[%skeleton "lalr1.cc"
+
+%code
+{
+  int yylex (yy::parser::semantic_type *);
+}
+
+%defines
+%define variant
+%define parse.error verbose
+%define parse.trace
+%%
+
+start:
+  thing
+| start thing
+;
+
+thing:
+  error   { std::cerr << "caught error" << std::endl; }
+| item
+;
+
+item:
+  'a'
+| 's'
+  {
+    throw yy::parser::syntax_error("invalid expression");
+  }
+
+%%
+
+int
+yylex (yy::parser::semantic_type *)
+{
+  static char const *input = "as";
+  switch (int res = *input++)
+  {
+    default:
+      return res;
+  }
+}
+
+void
+yy::parser::error (const std::string &m)
+{
+  std::cerr << "error: " << m << std::endl;
+}
+
+int
+main ()
+{
+  yy::parser parser;
+  parser.set_debug_level(!!getenv("YYDEBUG"));
+  return parser.parse ();
+}
+]])
+AT_BISON_CHECK([[-o input.cc input.yy]])
+AT_COMPILE_CXX([[input]])
+
+AT_PARSER_CHECK([[./input]], [[0]], [[]],
+[[error: invalid expression
+caught error
+]])
+
+AT_CLEANUP