Skip to content

Commit 5108a30

Browse files
committed
Polish README
1 parent 7f78dab commit 5108a30

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ target_link_libraries(my_app PUBLIC Iris::X4)
3636

3737
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.
3838

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.
4040

4141
### exposed attribute
4242

@@ -61,6 +61,8 @@ constexpr auto p = x4::int_;
6161

6262
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.
6363

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+
6466
```cpp
6567
// parser attr: `iris::alloy::tuple<int, int>`
6668
constexpr auto p = x4::int_ >> x4::int_;
@@ -71,7 +73,13 @@ x4::parse("...", p, ints);
7173

7274
// exposed attr: `std::tuple<int, int>`
7375
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);
7583
```
7684
7785
When multiple nested parser invocations are involved, the exposed attribute type may vary depending on context.

0 commit comments

Comments
 (0)