librdesc
Loading...
Searching...
No Matches
rule_macros.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025-2026 Metehan Selvi <me@metehanselvi.com>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
24#ifndef RDESC_RULE_MACROS_H
25#define RDESC_RULE_MACROS_H
26
27
28#ifndef PREFIX_TK
30#define PREFIX_TK(tk) TK_ ## tk
31#endif
32
33#ifndef PREFIX_NT
35#define PREFIX_NT(nt) NT_ ## nt
36#endif
37
38#ifndef POSTFIX_NT_REST
40#define POSTFIX_NT_REST(nt) nt ## _REST
41#endif
42
44#define EOA -1
46#define EOP -2
47
50#define SEOA { .ty = RDESC_SENTINEL, .id = EOA }
52#define SEOP { { .ty = RDESC_SENTINEL, .id = EOP } }
56#define TK(tk) { .ty = RDESC_TOKEN, .id = PREFIX_TK(tk) }
58#define NT(nt) { .ty = RDESC_NONTERMINAL, .id = PREFIX_NT(nt) }
59
65#define EPSILON SEOA
66
67
72#define r(...) { { __VA_ARGS__, SEOA }, SEOP }
73
91#define ropt(...) \
92 r(__VA_ARGS__ alt EPSILON)
93
121#define rrr(head, base, suffix) \
122 r(_rdesc_priv_trim_paren base, NT(POSTFIX_NT_REST(head))), \
123 ropt(_rdesc_priv_trim_paren suffix, NT(POSTFIX_NT_REST(head)))
124
133#define alt , SEOA, }, {
134
136#define _rdesc_priv_trim_paren(...) __VA_ARGS__
140#endif