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
+16-13Lines changed: 16 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ You can also try the online version, PEG Playground at https://yhirose.github.io
10
10
11
11
The PEG syntax is well described on page 2 in the [document](http://www.brynosaurus.com/pub/lang/peg.pdf). *cpp-peglib* also supports the following additional syntax for now:
12
12
13
+
*`'...'i` (Case-insensitive literal operator)
13
14
*`<` ... `>` (Token boundary operator)
14
15
*`~` (Ignore operator)
15
16
*`\x20` (Hex number char)
@@ -169,11 +170,11 @@ auto ret = pg.parse(" token1, token2 ");
169
170
We can ignore unnecessary semantic values from the list by using `~` operator.
170
171
171
172
```cpp
172
-
peg::pegparser parser(
173
-
" ROOT <- _ ITEM (',' _ ITEM _)* "
174
-
" ITEM <- ([a-z])+ "
175
-
" ~_ <- [ \t]* "
176
-
);
173
+
peg::pegparser parser(R"(
174
+
ROOT <- _ ITEM (',' _ ITEM _)*
175
+
ITEM <- ([a-z])+
176
+
~_ <- [ \t]*
177
+
)");
177
178
178
179
parser["ROOT"] = [&](const SemanticValues& sv) {
179
180
assert(sv.size() == 2); // should be 2 instead of 5.
@@ -185,11 +186,11 @@ auto ret = parser.parse(" item1, item2 ");
185
186
The following grammar is same as the above.
186
187
187
188
```cpp
188
-
peg::parserparser(
189
-
" ROOT <- ~_ ITEM (',' ~_ ITEM ~_)* "
190
-
" ITEM <- ([a-z])+ "
191
-
" _ <- [ \t]* "
192
-
);
189
+
peg::pegparserparser(R"(
190
+
ROOT <- ~_ ITEM (',' ~_ ITEM ~_)*
191
+
ITEM <- ([a-z])+
192
+
_ <- [ \t]*
193
+
)");
193
194
```
194
195
195
196
*Semantic predicate* support is available. We can do it by throwing a `peg::parse_error` exception in a semantic action.
@@ -244,9 +245,10 @@ As you can see in the first example, we can ignore whitespaces between tokens au
244
245
These are valid tokens:
245
246
246
247
```
247
-
KEYWORD <- 'keyword'
248
-
WORD <- < [a-zA-Z0-9] [a-zA-Z0-9-_]* > # token boundary operator is used.
0 commit comments