## Namespaces. ##
## ------------ ##
-# AT_CHECK_NAMESPACE(NAMESPACE-DECL, [COMPILE-ERROR])
-# ---------------------------------------------------
+# AT_TEST(NAMESPACE-DECL, [COMPILE-ERROR])
+# ----------------------------------------
# See if Bison can handle %define namespace "NAMESPACE-DECL". If COMPILE-ERROR
# is specified, then Bison should accept the input, but compilation will fail,
# so don't check compilation.
-m4_define([AT_CHECK_NAMESPACE],
-[
-
+m4_pushdef([AT_TEST],
+[AT_BISON_OPTION_PUSHDEFS([%language "C++" %define api.namespace "$1"])
AT_DATA_GRAMMAR([[input.y]],
[[%language "C++"
%defines
std::cerr << "At " << loc << ": " << msg << std::endl;
}
-int
-main ()
-{
- ]$1[::parser p;
- return p.parse ();
-}
+]AT_MAIN_DEFINE[
]])
AT_BISON_CHECK([[-o input.cc input.y]])
m4_if([$#], [1],
[AT_COMPILE_CXX([[input]], [[input.cc]])
AT_PARSER_CHECK([[./input]])])
-
+AT_BISON_OPTION_POPDEFS
])
AT_SETUP([[Relative namespace references]])
-AT_CHECK_NAMESPACE([[foo]])
-AT_CHECK_NAMESPACE([[foo::bar]])
-AT_CHECK_NAMESPACE([[foo::bar::baz]])
+AT_TEST([[foo]])
+AT_TEST([[foo::bar]])
+AT_TEST([[foo::bar::baz]])
AT_CLEANUP
AT_SETUP([[Absolute namespace references]])
-AT_CHECK_NAMESPACE([[::foo]])
-AT_CHECK_NAMESPACE([[::foo::bar]])
-AT_CHECK_NAMESPACE([[::foo::bar::baz]])
-AT_CHECK_NAMESPACE([[ ::foo]])
-AT_CHECK_NAMESPACE([[ ::foo::bar]])
-AT_CHECK_NAMESPACE([[ ::foo::bar::baz]])
+AT_TEST([[::foo]])
+AT_TEST([[::foo::bar]])
+AT_TEST([[::foo::bar::baz]])
+AT_TEST([[ ::foo]])
+AT_TEST([[ ::foo::bar]])
+AT_TEST([[ ::foo::bar::baz]])
AT_CLEANUP
AT_SETUP([[Syntactically invalid namespace references]])
-AT_CHECK_NAMESPACE([[:foo:bar]], [[-]])
-AT_CHECK_NAMESPACE([[foo: :bar]], [[-]])
+AT_TEST([[:foo:bar]], [[-]])
+AT_TEST([[foo: :bar]], [[-]])
# This one is interesting because `[3]' is encoded as `@<:@3@:>@', which
# contains single occurrences of `:'.
-AT_CHECK_NAMESPACE([[foo[3]::bar::baz]], [[-]])
-AT_CHECK_NAMESPACE([[foo::bar,baz]], [[-]])
-AT_CHECK_NAMESPACE([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
+AT_TEST([[foo[3]::bar::baz]], [[-]])
+AT_TEST([[foo::bar,baz]], [[-]])
+AT_TEST([[foo::bar::(baz /* Pacify Emacs ) */]], [[-]])
AT_CLEANUP
+m4_popdef([AT_TEST])
## -------------------------------------- ##
## Syntax error discarding no lookahead. ##
AT_SETUP([export YYLTYPE])
+AT_BISON_OPTION_PUSHDEFS([%name-prefix "my_"])
AT_DATA_GRAMMAR([input.y],
-[%locations
+[[%locations
%name-prefix "my_"
%{
#include <stdio.h>
#include <stdlib.h>
-static int
-my_lex (void)
-{
- return EOF;
-}
-
-static void
-my_error (const char *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
+]AT_YYERROR_DEFINE[
+]AT_YYLEX_DEFINE[
%}
%%
exp:;
-])
+]])
AT_BISON_CHECK([--defines -o input.c input.y])
int my_parse (void);
-int
-main (void)
-{
- return my_parse ();
-}
+]AT_MAIN_DEFINE[
]])
# Link and execute, just to make sure everything is fine (and in
AT_COMPILE([input.o])
AT_COMPILE([caller], [caller.o input.o])
AT_PARSER_CHECK([./caller])
-
+AT_BISON_OPTION_POPDEFS
AT_CLEANUP
## ----------------- ##
[m4_bmatch([$3], [%define *api\.pure\|%pure-parser],
[m4_bmatch([$3], [%define *api\.pure *"?false"?], [$2], [$1])],
[$2])])
+# AT_NAME_PREFIX: also consider api.namespace.
m4_pushdef([AT_NAME_PREFIX],
-[m4_bmatch([$3], [\(%define api\.prefix\|%name-prefix\) ".*"],
- [m4_bregexp([$3], [\(%define api\.prefix\|%name-prefix\) "\([^""]*\)"], [\2])],
+[m4_bmatch([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) ".*"],
+ [m4_bregexp([$3], [\(%define api\.\(namespace\|prefix\)\|%name-prefix\) "\([^""]*\)"], [\3])],
[yy])])
m4_pushdef([AT_TOKEN_CTOR_IF],
[m4_bmatch([$3], [%define api.token.constructor], [$1], [$2])])
yydebug |= 1;]], [[
(void) argc;
(void) argv;]])[
- return yyparse ();
+ return ]AT_NAME_PREFIX[parse ();
}]],
[c++],
[[#include <cstdlib> // getenv.
int
main (int argc, char const* argv[])
{
- yy::parser p;]AT_DEBUG_IF([[
+ ]AT_NAME_PREFIX[::parser p;]AT_DEBUG_IF([[
if (getenv("YYDEBUG")
|| (argc == 2
&& (!strcmp (argv[1], "-d") || !strcmp (argv[1], "--debug"))))