mirror of
https://github.com/yhirose/cpp-peglib.git
synced 2024-12-22 11:55:30 +00:00
Corrected documentation.
This commit is contained in:
parent
1e98ddeab2
commit
0dc3cd6da4
@ -95,7 +95,7 @@ assert(ret == true);
|
|||||||
assert(val == -3);
|
assert(val == -3);
|
||||||
```
|
```
|
||||||
|
|
||||||
It may be helpful to keep in mind that the action behavior is similar to the YACC semantic action model ($$ = $1, $2, ...).
|
It may be helpful to keep in mind that the action behavior is similar to the YACC semantic action model ($$, $1, $2, ...).
|
||||||
|
|
||||||
In this example, the actions return values. These samentic values will be pushed up to the parent definition which can be referred to in the parent action `[](const vector<Any>& v)`. In other words, when a certain definition has been accepted, we can find all semantic values which are associated with the child definitions in `const vector<Any>& v`. The values are wrapped by peblib::Any class which is like `boost::any`. We can retrieve the value by using `get<T>` method where `T` is the actual type of the value. If no value is returned in an action, an undefined `Any` will be pushed up to the parent. Finally, the resulting value of the root definition is received in the out parameter of `parse` method in the parser. `long val` is the resulting value in this case.
|
In this example, the actions return values. These samentic values will be pushed up to the parent definition which can be referred to in the parent action `[](const vector<Any>& v)`. In other words, when a certain definition has been accepted, we can find all semantic values which are associated with the child definitions in `const vector<Any>& v`. The values are wrapped by peblib::Any class which is like `boost::any`. We can retrieve the value by using `get<T>` method where `T` is the actual type of the value. If no value is returned in an action, an undefined `Any` will be pushed up to the parent. Finally, the resulting value of the root definition is received in the out parameter of `parse` method in the parser. `long val` is the resulting value in this case.
|
||||||
|
|
||||||
@ -121,9 +121,8 @@ Instead of makeing a parser by parsing PEG syntax text, we can also construct a
|
|||||||
using namespace peglib;
|
using namespace peglib;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Definition ROOT, TAG, TAG_NAME, _;
|
Definition ROOT, TAG_NAME, _;
|
||||||
ROOT = seq(_, zom(TAG));
|
ROOT = seq(_, zom(seq(chr('['), TAG_NAME, chr(']'), _)));
|
||||||
TAG = seq(chr('['), TAG_NAME, chr(']'), _);
|
|
||||||
TAG_NAME = oom(seq(npd(chr(']')), any()));
|
TAG_NAME = oom(seq(npd(chr(']')), any()));
|
||||||
_ = zom(cls(" \t"));
|
_ = zom(cls(" \t"));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user