]> git.saurik.com Git - bison.git/blame - data/bison.m4
2006-10-16 Paolo Bonzini <bonzini@gnu.org>
[bison.git] / data / bison.m4
CommitLineData
90b9908d
PB
1m4_divert(-1) -*- Autoconf -*-
2
3# Language-independent M4 Macros for Bison.
4# Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
5
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19# 02110-1301 USA
20
21
22## ---------------- ##
23## Identification. ##
24## ---------------- ##
25
26# b4_copyright(TITLE, YEARS)
27# --------------------------
28m4_define([b4_copyright],
29[b4_comment([A Bison parser, made by GNU Bison b4_version.])
30
31b4_comment([$1
32
33m4_text_wrap([Copyright (C) $2 Free Software Foundation, Inc.], [ ])
34
35This program is free software; you can redistribute it and/or modify
36it under the terms of the GNU General Public License as published by
37the Free Software Foundation; either version 2, or (at your option)
38any later version.
39
40This program is distributed in the hope that it will be useful,
41but WITHOUT ANY WARRANTY; without even the implied warranty of
42MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43GNU General Public License for more details.
44
45You should have received a copy of the GNU General Public License
46along with this program; if not, write to the Free Software
47Foundation, Inc., 51 Franklin Street, Fifth Floor,
48Boston, MA 02110-1301, USA.])
49
50b4_comment([As a special exception, you may create a larger work that contains
51part or all of the Bison parser skeleton and distribute that work
52under terms of your choice, so long as that work isn't itself a
53parser generator using the skeleton or a modified version thereof
54as a parser skeleton. Alternatively, if you modify or redistribute
55the parser skeleton itself, you may (at your option) remove this
56special exception, which will cause the skeleton and the resulting
57Bison output files to be licensed under the GNU General Public
58License without this special exception.
59
60This special exception was added by the Free Software Foundation in
61version 2.2 of Bison.])])
62
63
64## ---------------- ##
65## Default values. ##
66## ---------------- ##
67
68# m4_define_default([b4_lex_param], []) dnl breaks other skeletons
69m4_define_default([b4_epilogue], [])
70m4_define_default([b4_parse_param], [])
71
72# The initial column and line.
73m4_define_default([b4_location_initial_column], [1])
74m4_define_default([b4_location_initial_line], [1])
75
76
77## ------------ ##
78## Data Types. ##
79## ------------ ##
80
81# b4_ints_in(INT1, INT2, LOW, HIGH)
82# ---------------------------------
83# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
84m4_define([b4_ints_in],
85[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
86
87
88
89## ------------------ ##
90## Decoding options. ##
91## ------------------ ##
92
93# b4_flag_if(FLAG, IF-TRUE, IF-FALSE)
94# -----------------------------------
95# Run IF-TRUE if b4_FLAG_flag is 1, IF-FALSE if FLAG is 0, otherwise fail.
96m4_define([b4_flag_if],
97[m4_case(b4_$1_flag,
98 [0], [$3],
99 [1], [$2],
100 [m4_fatal([invalid $1 value: ]$1)])])
101
102
103# b4_define_flag_if(FLAG)
104# -----------------------
105# Define "b4_FLAG_if(IF-TRUE, IF-FALSE)" that depends on the
106# value of the Boolean FLAG.
107m4_define([b4_define_flag_if],
108[_b4_define_flag_if($[1], $[2], [$1])])
109
110# _b4_define_flag_if($1, $2, FLAG)
111# --------------------------------
112# This macro works around the impossibility to define macros
113# inside macros, because issuing `[$1]' is not possible in M4 :(.
114# This sucks hard, GNU M4 should really provide M5 like $$1.
115m4_define([_b4_define_flag_if],
116[m4_if([$1$2], $[1]$[2], [],
117 [m4_fatal([$0: Invalid arguments: $@])])dnl
118m4_define([b4_$3_if],
119 [b4_flag_if([$3], [$1], [$2])])])
120
121
122# b4_FLAG_if(IF-TRUE, IF-FALSE)
123# -----------------------------
124# Expand IF-TRUE, if FLAG is true, IF-FALSE otherwise.
125b4_define_flag_if([defines]) # Whether headers are requested.
126b4_define_flag_if([error_verbose]) # Whether error are verbose.
127b4_define_flag_if([glr]) # Whether a GLR parser is requested.
128b4_define_flag_if([locations]) # Whether locations are tracked.
129b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
130b4_define_flag_if([pure]) # Whether the interface is pure.
131b4_define_flag_if([push]) # Whether push parsing is supported.
132b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
133
134
135## ------------------------- ##
136## Assigning token numbers. ##
137## ------------------------- ##
138
139
140## ----------- ##
141## Synclines. ##
142## ----------- ##
143
144# b4_basename(NAME)
145# -----------------
146# Similar to POSIX basename; the differences don't matter here.
147# Beware that NAME is not evaluated.
148m4_define([b4_basename],
149[m4_bpatsubst([$1], [^.*/\([^/]+\)/*$], [\1])])
150
151
152# b4_syncline(LINE, FILE)
153# -----------------------
154m4_define([b4_syncline],
155[b4_flag_if([synclines], [
156b4_sync_end([__line__], [b4_basename(m4_quote(__file__))])
157b4_sync_start([$1], [$2])])])
158
159m4_define([b4_sync_end], [b4_comment([Line $1 of $2])])
160m4_define([b4_sync_start], [b4_comment([Line $1 of $2])])
161
162# b4_user_code(USER-CODE)
163# -----------------------
164# Emit code from the user, ending it with synclines.
165m4_define([b4_user_code],
166[$1
167b4_syncline([@oline@], [@ofile@])])
168
169
170# b4_define_user_code(MACRO)
171# --------------------------
172# From b4_MACRO, build b4_user_MACRO that includes the synclines.
173m4_define([b4_define_user_code],
174[m4_define([b4_user_$1],
175[b4_user_code([b4_$1])])])
176
177
178# b4_user_actions
179# b4_user_initial_action
180# b4_user_post_prologue
136a0f76
PB
181# b4_user_pre_prologue
182# b4_user_provides
183# b4_user_requires
90b9908d
PB
184# b4_user_stype
185# ----------------------
186# Macros that issue user code, ending with synclines.
187b4_define_user_code([actions])
188b4_define_user_code([initial_action])
189b4_define_user_code([post_prologue])
136a0f76
PB
190b4_define_user_code([pre_prologue])
191b4_define_user_code([provides])
192b4_define_user_code([requires])
90b9908d
PB
193b4_define_user_code([stype])
194
195