1998-11-27 19:33:53 +00:00
|
|
|
m4_divert(-1)m4_dnl
|
|
|
|
#
|
|
|
|
# BIRD -- Generator of Configuration Grammar
|
|
|
|
#
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
# (c) 1998--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
|
1998-11-27 19:33:53 +00:00
|
|
|
#
|
|
|
|
# Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Diversions used:
|
|
|
|
# 1 includes
|
2018-08-13 09:41:27 +00:00
|
|
|
# 2 context structure
|
|
|
|
# 3 inline C code and macros
|
|
|
|
# 4 parser declarations
|
|
|
|
# 5 grammar rules
|
|
|
|
# 6 C code
|
|
|
|
|
1998-11-27 19:33:53 +00:00
|
|
|
|
|
|
|
# Common aliases
|
|
|
|
m4_define(DNL, `m4_dnl')
|
|
|
|
|
|
|
|
# Define macros for defining sections
|
|
|
|
m4_define(CF_ZONE, `m4_divert($1)/* $2 from m4___file__ */')
|
|
|
|
m4_define(CF_HDR, `CF_ZONE(1, Headers)')
|
2018-08-13 09:41:27 +00:00
|
|
|
m4_define(CF_CTX, `CF_ZONE(2, Context)')
|
|
|
|
m4_define(CF_DEFINES, `CF_ZONE(3, Defines)')
|
|
|
|
m4_define(CF_DECLS, `CF_ZONE(4, Bison Declarations)')
|
|
|
|
m4_define(CF_GRAMMAR, `CF_ZONE(5, Grammar)')
|
|
|
|
m4_define(CF_CODE, `CF_ZONE(6, C Code)')
|
1998-11-27 19:33:53 +00:00
|
|
|
m4_define(CF_END, `m4_divert(-1)')
|
|
|
|
|
|
|
|
# Simple iterator
|
|
|
|
m4_define(CF_itera, `m4_ifelse($#, 1, [[CF_iter($1)]], [[CF_iter($1)[[]]CF_itera(m4_shift($@))]])')
|
|
|
|
m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)')
|
|
|
|
|
|
|
|
# Keywords act as untyped %token
|
|
|
|
m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])')
|
|
|
|
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
|
|
|
|
)DNL')
|
|
|
|
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
# CLI commands
|
|
|
|
m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL
|
2018-08-13 09:41:27 +00:00
|
|
|
m4_divert(4)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
|
|
|
|
m4_divert(5)cli_cmd: CF_cmd
|
1999-11-17 12:00:21 +00:00
|
|
|
CF_cmd: $1 $2 END')
|
2012-12-26 11:40:48 +00:00
|
|
|
m4_define(CF_CLI_CMD, `')
|
1999-11-17 12:00:21 +00:00
|
|
|
m4_define(CF_CLI_HELP, `')
|
Parse CLI commands. We use the same parser as for configuration files (because
we want to allow filter and similar complex constructs to be used in commands
and we should avoid code duplication), only with CLI_MARKER token prepended
before the whole input.
Defined macro CF_CLI(cmd, args, help) for defining CLI commands in .Y files.
The first argument specifies the command itself, the remaining two arguments
are copied to the help file (er, will be copied after the help file starts
to exist). This macro automatically creates a skeleton rule for the command,
you only need to append arguments as in:
CF_CLI(STEAL MONEY, <$>, [[Steal <$> US dollars or equivalent in any other currency]]): NUM {
cli_msg(0, "%d$ stolen", $3);
} ;
Also don't forget to reset lexer state between inputs.
1999-10-31 17:47:47 +00:00
|
|
|
|
1999-11-15 11:35:41 +00:00
|
|
|
# ENUM declarations are ignored
|
|
|
|
m4_define(CF_ENUM, `')
|
|
|
|
|
1998-11-27 19:33:53 +00:00
|
|
|
# After all configuration templates end, we finally generate the grammar file.
|
|
|
|
m4_m4wrap(`
|
|
|
|
m4_divert(0)DNL
|
|
|
|
%{
|
|
|
|
m4_undivert(1)DNL
|
2018-08-13 09:41:27 +00:00
|
|
|
|
|
|
|
m4_undivert(3)DNL
|
1998-11-27 19:33:53 +00:00
|
|
|
%}
|
|
|
|
|
2018-08-13 09:41:27 +00:00
|
|
|
m4_undivert(4)DNL
|
1998-11-27 19:33:53 +00:00
|
|
|
|
|
|
|
%%
|
2018-08-13 09:41:27 +00:00
|
|
|
m4_undivert(5)DNL
|
1998-11-27 19:33:53 +00:00
|
|
|
|
|
|
|
%%
|
2018-08-13 09:41:27 +00:00
|
|
|
m4_undivert(6)DNL
|
1998-11-27 19:33:53 +00:00
|
|
|
')
|
|
|
|
|
|
|
|
# As we are processing C source, we must access all M4 primitives via
|
|
|
|
# m4_* and also set different quoting convention: `[[' and ']]'
|
|
|
|
m4_changequote([[,]])
|