]> git.ipfire.org Git - thirdparty/bird.git/blame - conf/gen_parser.m4
Integrated IP functions.
[thirdparty/bird.git] / conf / gen_parser.m4
CommitLineData
ce6ca809
MM
1m4_divert(-1)m4_dnl
2#
3# BIRD -- Generator of Configuration Grammar
4#
bc2fb680 5# (c) 1998--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
ce6ca809
MM
6#
7# Can be freely distributed and used under the terms of the GNU GPL.
8#
9
10# Diversions used:
11# 1 includes
12# 2 types etc.
13# 3 rules
14# 4 C code
15
16# Common aliases
17m4_define(DNL, `m4_dnl')
18
19# Define macros for defining sections
20m4_define(CF_ZONE, `m4_divert($1)/* $2 from m4___file__ */')
21m4_define(CF_HDR, `CF_ZONE(1, Headers)')
2edb31b0 22m4_define(CF_DEFINES, `CF_ZONE(1, Defines)')
ce6ca809
MM
23m4_define(CF_DECLS, `CF_ZONE(2, Declarations)')
24m4_define(CF_GRAMMAR, `CF_ZONE(3, Grammar)')
25m4_define(CF_CODE, `CF_ZONE(4, C Code)')
26m4_define(CF_END, `m4_divert(-1)')
27
28# Simple iterator
29m4_define(CF_itera, `m4_ifelse($#, 1, [[CF_iter($1)]], [[CF_iter($1)[[]]CF_itera(m4_shift($@))]])')
30m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)')
31
32# Keywords act as untyped %token
33m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])')
34m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
35)DNL')
36
37# Dynamic syntax rules
38m4_define(CF_dyn_rules,)
39m4_define(CF_ADDTO, `m4_define([[CF_rule_$1]],m4_ifdef([[CF_rule_$1]],CF_rule_$1 | ,[[m4_define([[CF_dyn_rules]],CF_dyn_rules[[CF_RULE($1)
40]])]])$2)DNL')
ce6ca809 41
bc2fb680
MM
42# CLI commands
43m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL
44m4_divert(2)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
45m4_divert(3)CF_ADDTO(cli_cmd, CF_cmd)
ffb59d24 46CF_cmd: $1 $2 END')
a92cf57d 47m4_define(CF_CLI_CMD, `')
ffb59d24 48m4_define(CF_CLI_HELP, `')
bc2fb680 49
944f008a
MM
50# ENUM declarations are ignored
51m4_define(CF_ENUM, `')
52
ce6ca809
MM
53# After all configuration templates end, we finally generate the grammar file.
54m4_m4wrap(`
55m4_divert(0)DNL
56%{
57m4_undivert(1)DNL
58%}
59
60m4_undivert(2)DNL
61
62%%
63m4_undivert(3)DNL
64
65/* Dynamic rules */
66
0846203e 67m4_define(CF_RULE, [[$1: CF_rule_$1 ;]])
ce6ca809
MM
68CF_dyn_rules
69%%
70m4_undivert(4)DNL
71')
72
73# As we are processing C source, we must access all M4 primitives via
74# m4_* and also set different quoting convention: `[[' and ']]'
75m4_changequote([[,]])