Metalang99 1.13.3
Full-blown preprocessor metaprogramming
either.h
Go to the documentation of this file.
1
6#ifndef ML99_EITHER_H
7#define ML99_EITHER_H
8
9#include <metalang99/priv/util.h>
10
11#include <metalang99/bool.h>
12#include <metalang99/choice.h>
13#include <metalang99/ident.h>
14
18#define ML99_left(x) ML99_call(ML99_left, x)
19
23#define ML99_right(x) ML99_call(ML99_right, x)
24
40#define ML99_isLeft(either) ML99_call(ML99_isLeft, either)
41
57#define ML99_isRight(either) ML99_call(ML99_isRight, either)
58
78#define ML99_eitherEq(cmp, either, other) ML99_call(ML99_eitherEq, cmp, either, other)
79
95#define ML99_unwrapLeft(either) ML99_call(ML99_unwrapLeft, either)
96
112#define ML99_unwrapRight(either) ML99_call(ML99_unwrapRight, either)
113
114#define ML99_LEFT(x) ML99_CHOICE(left, x)
115#define ML99_RIGHT(x) ML99_CHOICE(right, x)
116#define ML99_IS_LEFT(either) ML99_PRIV_IS_LEFT(either)
117#define ML99_IS_RIGHT(either) ML99_NOT(ML99_IS_LEFT(either))
118
119#ifndef DOXYGEN_IGNORE
120
121#define ML99_left_IMPL(x) v(ML99_LEFT(x))
122#define ML99_right_IMPL(x) v(ML99_RIGHT(x))
123
124#define ML99_isLeft_IMPL(either) v(ML99_IS_LEFT(either))
125#define ML99_isRight_IMPL(either) v(ML99_IS_RIGHT(either))
126
127// ML99_eitherEq_IMPL {
128
129#define ML99_eitherEq_IMPL(cmp, either, other) \
130 ML99_matchWithArgs_IMPL(either, ML99_PRIV_eitherEq_, cmp, other)
131
132#define ML99_PRIV_eitherEq_left_IMPL(x, cmp, other) \
133 ML99_matchWithArgs_IMPL(other, ML99_PRIV_eitherEq_left_, cmp, x)
134#define ML99_PRIV_eitherEq_right_IMPL(x, cmp, other) \
135 ML99_matchWithArgs_IMPL(other, ML99_PRIV_eitherEq_right_, cmp, x)
136
137#define ML99_PRIV_eitherEq_left_left_IMPL(y, cmp, x) ML99_appl2_IMPL(cmp, x, y)
138#define ML99_PRIV_eitherEq_left_right_IMPL ML99_false_IMPL
139
140#define ML99_PRIV_eitherEq_right_left_IMPL ML99_false_IMPL
141#define ML99_PRIV_eitherEq_right_right_IMPL(y, cmp, x) ML99_appl2_IMPL(cmp, x, y)
142// } (ML99_eitherEq_IMPL)
143
144#define ML99_unwrapLeft_IMPL(either) ML99_match_IMPL(either, ML99_PRIV_unwrapLeft_)
145#define ML99_PRIV_unwrapLeft_left_IMPL(x) v(x)
146#define ML99_PRIV_unwrapLeft_right_IMPL(_x) \
147 ML99_fatal(ML99_unwrapLeft, expected ML99_left but found ML99_right)
148
149#define ML99_unwrapRight_IMPL(either) ML99_match_IMPL(either, ML99_PRIV_unwrapRight_)
150#define ML99_PRIV_unwrapRight_left_IMPL(_x) \
151 ML99_fatal(ML99_unwrapRight, expected ML99_right but found ML99_left)
152#define ML99_PRIV_unwrapRight_right_IMPL(x) v(x)
153
154#define ML99_PRIV_IS_LEFT(either) ML99_DETECT_IDENT(ML99_PRIV_IS_LEFT_, ML99_CHOICE_TAG(either))
155#define ML99_PRIV_IS_LEFT_left ()
156
157// Arity specifiers {
158
159#define ML99_left_ARITY 1
160#define ML99_right_ARITY 1
161#define ML99_isLeft_ARITY 1
162#define ML99_isRight_ARITY 1
163#define ML99_eitherEq_ARITY 3
164#define ML99_unwrapLeft_ARITY 1
165#define ML99_unwrapRight_ARITY 1
166// } (Arity specifiers)
167
168#endif // DOXYGEN_IGNORE
169
170#endif // ML99_EITHER_H
Boolean algebra.
Choice types: (tag, ...).
Identifiers: [a-zA-Z0-9_]+.