You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ target_link_libraries(my_app PUBLIC Iris::X4)
36
36
37
37
An *attribute* is the value produced by a successful parse. It represents the semantic result of a parser after it consumes input, and is propagated through combinators, directives, and rules according to their transformation rules. Attributes may be primitive values, containers, or user-defined types, and can be constructed, transformed, or suppressed depending on the parser expression.
38
38
39
-
Phrases like "the attribute type of a parser" usually refer to the value type of the attribute produced by that parser class.
39
+
Phrases like "the attribute of a parser" usually refer to the type of the attribute produced by that parser class.
40
40
41
41
### exposed attribute
42
42
@@ -61,6 +61,8 @@ constexpr auto p = x4::int_;
61
61
62
62
The `x4::sequence` parser (normally instantiated via `a >> b` syntax) yields a special tuple attribute. This attribute is generic in nature and can be transformed into any tuple-like or sequence-like concrete type, depending on the caller.
63
63
64
+
To adapt a user-defined type as an tuple-like type, use `IRIS_ALLOY_ADAPT_STRUCT` from [<iris/alloy/adapt.hpp>](https://github.com/iris-cpp/x4/blob/main/include/iris/alloy/adapt.hpp).
65
+
64
66
```cpp
65
67
// parser attr: `iris::alloy::tuple<int, int>`
66
68
constexprauto p = x4::int_ >> x4::int_;
@@ -71,7 +73,13 @@ x4::parse("...", p, ints);
71
73
72
74
// exposed attr: `std::tuple<int, int>`
73
75
std::tuple<int, int> int_int_tup;
74
-
x4::parse("...". p, int_int_tup);
76
+
x4::parse("...", p, int_int_tup);
77
+
78
+
// exposed attr: `Point`
79
+
struct Point { int x, y; };
80
+
IRIS_ALLOY_ADAPT_STRUCT(Point, x, y);
81
+
Point point;
82
+
x4::parse("...", p, point);
75
83
```
76
84
77
85
When multiple nested parser invocations are involved, the exposed attribute type may vary depending on context.
0 commit comments