]> git.saurik.com Git - bison.git/blobdiff - data/bison.m4
Clean up b4_check_percent_code_qualifiers a little.
[bison.git] / data / bison.m4
index 87d113b66df2346039594c9eb07b839ffabbc0bb..052dafaa87f0b0418e7609975c3cdb1d0ca9b125 100644 (file)
@@ -1,7 +1,7 @@
-m4_divert(-1)                                               -*- Autoconf -*-
+                                                            -*- Autoconf -*-
 
 # Language-independent M4 Macros for Bison.
-# Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -61,6 +61,71 @@ This special exception was added by the Free Software Foundation in
 version 2.2 of Bison.])])
 
 
+## ---------------- ##
+## Error handling.  ##
+## ---------------- ##
+
+# b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
+# ---------------------------------------------------------------
+# Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to diversion 0.
+m4_define([b4_error],
+[m4_divert_push(0)[@]$1[(]$2[]m4_if([$#], [2], [],
+[m4_foreach([b4_arg],
+            m4_dquote(m4_shift(m4_shift($@))),
+            [[@,]b4_arg])])[@)]m4_divert_pop(0)])
+
+# b4_warn(FORMAT, [ARG1], [ARG2], ...)
+# --------------------------------------------------------
+# Write @warn(FORMAT@,ARG1@,ARG2@,...@) to diversion 0.
+#
+# As a simple test suite, this:
+#
+#   m4_define([asdf], [ASDF])
+#   m4_define([fsa], [FSA])
+#   m4_define([fdsa], [FDSA])
+#   b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
+#   m4_divert(0)
+#   b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
+#   m4_divert(0)
+#   b4_warn([asdf), asdf], [fsa), fsa], [fdsa), fdsa])
+#   m4_divert(0)
+#   b4_warn
+#   m4_divert(0)
+#   b4_warn()
+#   m4_divert(0)
+#   b4_warn(1)
+#   m4_divert(0)
+#   b4_warn(1, 2)
+#
+# Should produce this:
+#
+#   @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@)
+#   @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@)
+#   @warn(ASDF), ASDF@,FSA), FSA@,FDSA), FDSA@)
+#   @warn(@)
+#   @warn(@)
+#   @warn(1@)
+#   @warn(1@,2@)
+m4_define([b4_warn],
+[b4_error([[warn]], $@)])
+
+# b4_complain(FORMAT, [ARG1], [ARG2], ...)
+# ------------------------------------------------------------
+# Write @complain(FORMAT@,ARG1@,ARG2@,...@) to diversion 0.
+#
+# See the test suite for b4_warn above.
+m4_define([b4_complain],
+[b4_error([[complain]], $@)])
+
+# b4_fatal(FORMAT, [ARG1], [ARG2], ...)
+# ---------------------------------------------------------
+# Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to diversion 0.
+#
+# See the test suite for b4_warn above.
+m4_define([b4_fatal],
+[b4_error([[fatal]], $@)])
+
+
 ## ---------------- ##
 ## Default values.  ##
 ## ---------------- ##
@@ -127,8 +192,13 @@ b4_define_flag_if([error_verbose]) # Whether error are verbose.
 b4_define_flag_if([glr])               # Whether a GLR parser is requested.
 b4_define_flag_if([locations])         # Whether locations are tracked.
 b4_define_flag_if([nondeterministic])  # Whether conflicts should be handled.
+b4_define_flag_if([pull])              # Whether pull parsing is requested.
 b4_define_flag_if([pure])              # Whether the interface is pure.
-b4_define_flag_if([push])              # Whether push parsing is supported.
+b4_define_flag_if([push])              # Whether push parsing is requested.
+b4_define_flag_if([use_push_for_pull])  # Whether push parsing should be used
+                                        # in place of pull parsing (where
+                                        # available) for the sake of the test
+                                        # suite.
 b4_define_flag_if([yacc])              # Whether POSIX Yacc is emulated.
 
 
@@ -179,8 +249,6 @@ m4_define([b4_define_user_code],
 # b4_user_initial_action
 # b4_user_post_prologue
 # b4_user_pre_prologue
-# b4_user_provides
-# b4_user_requires
 # b4_user_stype
 # ----------------------
 # Macros that issue user code, ending with synclines.
@@ -188,8 +256,49 @@ b4_define_user_code([actions])
 b4_define_user_code([initial_action])
 b4_define_user_code([post_prologue])
 b4_define_user_code([pre_prologue])
-b4_define_user_code([provides])
-b4_define_user_code([requires])
 b4_define_user_code([stype])
 
 
+# b4_check_percent_code_qualifiers([VAILD_QUALIFIER], [VALID_QUALIFIER], ...)
+# ---------------------------------------------------------------------------
+# Complain if any %code qualifier used in the grammar is not a valid qualifier.
+#
+# If no %code qualifiers are used in the grammar,
+# b4_used_percent_code_qualifiers must be undefined or expand to the empty
+# string.  Otherwise, it must expand to a comma-delimited list specifying all
+# %code qualifiers used in the grammar.   Each item in the list must expand to
+# text that expands to one of those qualifiers.  For example, to define
+# b4_used_percent_code_qualifiers with two qualifiers with correct quoting:
+#
+#   m4_define([b4_used_percent_code_qualifiers],
+#             [[[[requires]], [[provides]]]])
+#
+# Multiple occurrences of the same qualifier are fine.  Empty string qualifiers
+# are fine.
+#
+# Each VALID_QUALIFIER must expand to a valid qualifier.  For example,
+# b4_check_percent_code_qualifiers might be invoked with:
+#
+#   b4_check_percent_code_qualifiers([[requires]], [[provides]])
+#
+# Multiple occurrences of the same valid qualifier are fine.  A VALID_QUALIFIER
+# that expands to the empty string will correctly define the empty string as a
+# valid qualifier, but it would be ugly for a Bison skeleton to actually use
+# that.  If b4_used_percent_code_qualifiers is invoked with empty parens, then
+# there is one valid qualifier and it is the empty string.  To specify that
+# there are no valid qualifiers, invoke b4_check_percent_code_qualifiers
+# without parens.
+#
+# Qualifiers and valid qualifiers must not contain the character `,'.
+m4_define([b4_check_percent_code_qualifiers],
+[m4_ifdef([b4_used_percent_code_qualifiers], [
+m4_foreach([b4_qualifier],
+           b4_used_percent_code_qualifiers,
+           [m4_if(m4_index(m4_if($#, 0, [], [[,]m4_quote($*)[,]]),
+                           [,]b4_qualifier[,]),
+                  [-1],
+                  [b4_complain([[`%s' is not a recognized %%code qualifier]],
+                               [b4_qualifier])
+                  ])
+           ])
+])])