version 2.2 of Bison.])])
+## -------- ##
+## Output. ##
+## -------- ##
+
+# b4_output_begin(FILE)
+# ---------------------
+# Enable output, i.e., send to diversion 0, expand after "#", and
+# generate the tag to output into FILE. Must be followed by EOL.
+m4_define([b4_output_begin],
+[m4_changecom()
+m4_divert_push(0)dnl
+@output(m4_unquote([$1])@)@dnl
+])
+
+
+# b4_output_end()
+# ---------------
+# Output nothing, restore # as comment character (no expansions after #).
+m4_define([b4_output_end],
+[m4_divert_pop(0)
+m4_changecom([#])
+])
+
+
## ---------------- ##
## Error handling. ##
## ---------------- ##
])dnl
m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
-# b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
-# -------------------------------------------
-# Write @KIND(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+# b4_error(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
+# -------------------------------------------------------
+# Write @KIND(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
#
# For example:
#
-# b4_error([[warn]], [[invalid value for '%s': %s]], [[foo]], [[3]])
+# b4_error([[complain]], [[input.y:2.3]], [[input.y:5.4]],
+# [[invalid %s]], [[foo]])
m4_define([b4_error],
-[b4_cat([[@]$1[(]$2[]]dnl
-[m4_if([$#], [2], [],
- [m4_foreach([b4_arg],
- m4_dquote(m4_shift(m4_shift($@))),
- [[@,]b4_arg])])[@)]])])
-
-# b4_error_at(KIND, START, END, FORMAT, [ARG1], [ARG2], ...)
-# ----------------------------------------------------------
-# Write @KIND_at(START@,END@,FORMAT@,ARG1@,ARG2@,...@) to stdout.
-#
-# For example:
-#
-# b4_error_at([[complain]], [[input.y:2.3]], [[input.y:5.4]],
-# [[invalid %s]], [[foo]])
-m4_define([b4_error_at],
-[b4_cat([[@]$1[_at(]$2[@,]$3[@,]$4[]]dnl
+[b4_cat([[@complain][(]$1[@,]$2[@,]$3[@,]$4[]]dnl
[m4_if([$#], [4], [],
[m4_foreach([b4_arg],
m4_dquote(m4_shift(m4_shift(m4_shift(m4_shift($@))))),
# m4_define([asdf], [ASDF])
# m4_define([fsa], [FSA])
# m4_define([fdsa], [FDSA])
-# b4_warn([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
-# b4_warn([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
-# b4_warn()
-# b4_warn(1)
-# b4_warn(1, 2)
+# b4_warn_at([[[asdf), asdf]]], [[[fsa), fsa]]], [[[fdsa), fdsa]]])
+# b4_warn_at([[asdf), asdf]], [[fsa), fsa]], [[fdsa), fdsa]])
+# b4_warn_at()
+# b4_warn_at(1)
+# b4_warn_at(1, 2)
#
# Should produce this without newlines:
#
-# @warn([asdf), asdf]@,[fsa), fsa]@,[fdsa), fdsa]@)
-# @warn(asdf), asdf@,fsa), fsa@,fdsa), fdsa@)
+# @warn_at([asdf), asdf]@,@,@,[fsa), fsa]@,[fdsa), fdsa]@)
+# @warn(asdf), asdf@,@,@,fsa), fsa@,fdsa), fdsa@)
# @warn(@)
# @warn(1@)
# @warn(1@,2@)
m4_define([b4_warn],
-[b4_error([[warn]], $@)])
+[b4_error([[warn]], [], [], $@)])
# b4_warn_at(START, END, FORMAT, [ARG1], [ARG2], ...)
# ---------------------------------------------------
#
# b4_warn_at([[input.y:2.3]], [[input.y:5.4]], [[invalid %s]], [[foo]])
m4_define([b4_warn_at],
-[b4_error_at([[warn]], $@)])
+[b4_error([[warn]], $@)])
# b4_complain(FORMAT, [ARG1], [ARG2], ...)
# ----------------------------------------
-# Write @complain(FORMAT@,ARG1@,ARG2@,...@) to stdout.
+# Bounce to b4_complain_at.
#
# See b4_warn example.
m4_define([b4_complain],
-[b4_error([[complain]], $@)])
+[b4_error([[complain]], [], [], $@)])
# b4_complain_at(START, END, FORMAT, [ARG1], [ARG2], ...)
# -------------------------------------------------------
#
# See b4_warn_at example.
m4_define([b4_complain_at],
-[b4_error_at([[complain]], $@)])
+[b4_error([[complain]], $@)])
# b4_fatal(FORMAT, [ARG1], [ARG2], ...)
# -------------------------------------
-# Write @fatal(FORMAT@,ARG1@,ARG2@,...@) to stdout and exit.
+# Bounce to b4_fatal_at.
#
# See b4_warn example.
m4_define([b4_fatal],
-[b4_error([[fatal]], $@)dnl
+[b4_error([[fatal]], [], [], $@)dnl
m4_exit(1)])
# b4_fatal_at(START, END, FORMAT, [ARG1], [ARG2], ...)
#
# See b4_warn_at example.
m4_define([b4_fatal_at],
-[b4_error_at([[fatal]], $@)dnl
+[b4_error([[fatal]], $@)dnl
m4_exit(1)])
# undefined. If FIELD = id, prepend the prefix.
m4_define([b4_symbol],
[m4_case([$2],
- [id], [m4_do([b4_percent_define_get([api.tokens.prefix])],
+ [id], [m4_do([b4_percent_define_get([api.token.prefix])],
[b4_symbol_([$1], [id])])],
[b4_symbol_($@)])])
m4_define([b4_percent_define_syncline(]$1[)], [[]])])])
-# b4_percent_define_if_define(VARIABLE)
-# -------------------------------------
-# Define b4_VARIABLE_if that executes its $1 or $2 depending whether
+# b4_percent_define_if_define(NAME, [VARIABLE = NAME])
+# ----------------------------------------------------
+# Define b4_NAME_if that executes its $1 or $2 depending whether
# VARIABLE was %defined. The characters `.' and `-' in VARIABLE are mapped
# to `_'.
m4_define([b4_percent_define_if_define_],
[m4_define(m4_bpatsubst([b4_$1_if], [[-.]], [_]),
- [b4_percent_define_flag_if([$1], [$2], [$3])])])
+ [b4_percent_define_flag_if(m4_default([$2], [$1]),
+ [$3], [$4])])])
m4_define([b4_percent_define_if_define],
-[b4_percent_define_default([[$1]], [[false]])
-b4_percent_define_if_define_([$1], $[1], $[2])])
+[b4_percent_define_default([m4_default([$2], [$1])], [[false]])
+b4_percent_define_if_define_([$1], [$2], $[1], $[2])])
# b4_percent_define_check_values(VALUES)
[$1],
m4_dquote(m4_indir([b4_percent_define(]$1[)])))
m4_foreach([b4_value], m4_dquote(m4_shift($@)),
- [b4_complain_at(b4_percent_define_get_loc([$1]),
+ [b4_error([[note]], b4_percent_define_get_loc([$1]), []
[[accepted value: '%s']],
m4_dquote(b4_value))])])dnl
m4_popdef([b4_good_value])],
# Default values for %define.
# ---------------------------
-# If the api.tokens.prefix, it is empty.
-m4_percent_define_default([[api.tokens.prefix]], [[]])
+# If the api.token.prefix, it is empty.
+m4_percent_define_default([[api.token.prefix]], [[]])
# b4_parse_assert_if([IF-ASSERTIONS-ARE-USED], [IF-NOT])
# b4_parse_trace_if([IF-DEBUG-TRACES-ARE-ENABLED], [IF-NOT])
-# b4_lex_symbol_if([IF-YYLEX-RETURNS-A-COMPLETE-SYMBOL], [IF-NOT])
+# b4_token_ctor_if([IF-YYLEX-RETURNS-A-TOKEN], [IF-NOT])
# b4_variant_if([IF-VARIANT-ARE-USED], [IF-NOT])
# ----------------------------------------------
-b4_percent_define_if_define([lex_symbol])
+b4_percent_define_if_define([token_ctor], [api.token.constructor])
b4_percent_define_if_define([locations]) # Whether locations are tracked.
b4_percent_define_if_define([parse.assert])
b4_percent_define_if_define([parse.trace])
b4_percent_define_if_define([variant])
+# b4_bison_locations_if([IF-TRUE])
+# --------------------------------
+# Expand IF-TRUE if using locations, and using the default location
+# type.
+m4_define([b4_bison_locations_if],
+[b4_locations_if([b4_percent_define_ifdef([[api.location.type]], [], [$1])])])
+
# b4_error_verbose_if([IF-ERRORS-ARE-VERBOSE], [IF-NOT])
# ------------------------------------------------------