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
+44-43
Original file line number
Diff line number
Diff line change
@@ -38,46 +38,47 @@ Aside from build issues (and the usual issues around error messages and debuggab
38
38
39
39
## List of predefined parsers and combinators
40
40
41
-
|Basic Parsers|Description|
42
-
| --- | --- |
43
-
|empty()|Always succeeds, consume no input.|
44
-
|end() |Match end of input.|
45
-
|sym(t)|Match a single terminal symbol *t*.|
46
-
|seq(s) |Match sequence of symbols.|
47
-
|list(p,s) |Match list of *p*, separated by *s*.|
48
-
|one_of(set) |Success when current input symbol is one of the set.|
49
-
|none_of(set)|Success when current input symbol is none of the set.|
50
-
|is_a(predicate) |Success when predicate return true on current input symbol.|
51
-
|not_a(predicate)|Success when predicate return false on current input symbol.|
52
-
|take(n)|Read *n* symbols.|
53
-
|skip(n)|Skip *n* symbols.|
54
-
|call(pf)|Call a parser factory, can be used to create recursive parsers.|
55
-
56
-
|Parser Combinators|Description|
57
-
| --- | --- |
58
-
| p | q | Match p or q, return result of the first success. |
59
-
| p + q | Match p and q, if both succeed return a pair of results. |
60
-
| p - q | Match p and q, if both succeed return result of p. |
61
-
| p * q | Match p and q, if both succeed return result of q. |
62
-
| p >> q | Parse p and get result P, then parse q and return result of q(P). |
63
-
| -p | Success when p succeeds, doesn't consume input. |
64
-
| !p | Success when p fails, doesn't consume input. |
65
-
|p.opt()|Make parser optional. Returns an `Option`.|
66
-
|p.repeat(m..n)|`p.repeat(0..)` repeat p zero or more times<br>`p.repeat(1..)` repeat p one or more times<br>`p.repeat(1..4)` match p at least 1 and at most 3 times<br>`p.repeat(5)` repeat p exactly 5 times|
67
-
|p.map(f)|Convert parser result to desired value.|
68
-
|p.convert(f)|Convert parser result to desired value, fails in case of conversion error.|
69
-
|p.pos() |Get input position after matching p.|
70
-
|p.collect()|Collect all matched input symbols.|
71
-
|p.discard()|Discard parser output.|
72
-
|p.name(_)|Give parser a name to identify parsing errors.|
73
-
|p.expect(_)|Mark parser as expected, abort early when failed in ordered choice.|
| p | q | Match p or q, return result of the first success.|
59
+
| p + q | Match p and q, if both succeed return a pair of results.|
60
+
| p - q | Match p and q, if both succeed return result of p.|
61
+
| p \* q | Match p and q, if both succeed return result of q.|
62
+
| p >> q | Parse p and get result P, then parse q and return result of q(P).|
63
+
| -p | Success when p succeeds, doesn't consume input.|
64
+
| !p | Success when p fails, doesn't consume input.|
65
+
|p.opt()|Make parser optional. Returns an `Option`.|
66
+
|p.repeat(m..n)|`p.repeat(0..)` repeat p zero or more times<br>`p.repeat(1..)` repeat p one or more times<br>`p.repeat(1..4)` match p at least 1 and at most 3 times<br>`p.repeat(5)` repeat p exactly 5 times|
67
+
|p.map(f)|Convert parser result to desired value.|
68
+
|p.convert(f)|Convert parser result to desired value, fails in case of conversion error.|
69
+
|p.pos() |Get input position after matching p.|
70
+
|p.collect()|Collect all matched input symbols.|
71
+
|p.discard()|Discard parser output.|
72
+
|p.name(\_) |Give parser a name to identify parsing errors.|
73
+
|p.expect(\_) |Mark parser as expected, abort early when failed in ordered choice.|
74
74
75
75
The choice of operators is established by their operator precedence, arity and "meaning".
76
76
Use `*` to ignore the result of first operand on the start of an expression, `+` and `-` can fulfill the need on the rest of the expression.
77
77
78
78
For example, `A * B * C - D + E - F` will return the results of C and E as a pair.
0 commit comments