Skip to content

Commit 0655aa7

Browse files
authored
Readme: add headings; simplify
1 parent dfb5ce6 commit 0655aa7

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ Patterns are defined directly in code, instead of in a text string.
4545

4646
### Standard PEG
4747

48-
`"text"`
48+
##### `"text"`
4949

5050
Text within double quotes matches that exact text, no need to escape special letters with `\`. If you want to turn a string variable `s` into a pattern, use `Literal(s)`.
5151

52-
`OneOf(...)`
52+
##### `OneOf(...)`
5353

5454
This is like character classes (`[...]`) from regular expressions, and matches 1 character. `OneOf("aeiouAEIOU")` matches any single character in that string, and `OneOf("a"..."e")` matches any of "abcde". They can also be combined, like `OneOf("aeiou", punctuation, "x"..."z")`. To match any character _except_ ..., use `OneOf(not: ...)`.
5555

@@ -64,31 +64,31 @@ OneOf(description: "ten") { character in
6464

6565
It takes a closure `@escaping (Character) -> Bool` and matches any character for which the closure returns `true`. The description parameter is only used when creating a textual representation of the pattern.
6666

67-
`a • b • c`
67+
##### `a • b • c`
6868

6969
The • operator (Option-8 on U.S. keyboards, Option-Q on Norwegian ones) first matches `a`, then `b` and then `c`. It is used to create a pattern from a sequence of other patterns.
7070

71-
`a*`
71+
##### `a*`
7272

73-
matches 0 or more, as many as it can (it is greedy, like the regex `a*?`). So a pattern like `a* • a` will never match anything because the repeated `a` pattern will always match all it can, leaving nothing left for the last `a`.
73+
matches 0 or more, as many as it can (it is greedy, like the regex `a*?`). So a pattern like `a* • a` will never match anything because the `a*` pattern will always match all it can, leaving nothing left for the last `a`.
7474

75-
`a+`
75+
##### `a+`
7676

7777
matches 1 or more, also as many as it can (like the regex `a+?`).
7878

79-
`a¿`
79+
##### `a¿`
8080

8181
makes `a` optional, but it always matches if it can (the `¿` character is Option-Shift-TheKeyWith?OnIt on most keyboards).
8282

83-
`a / b`
83+
##### `a / b`
8484

8585
This first tries the pattern on the left. If that fails it tries the pattern on the right. This is _ordered choice_, once `a` has matched it will never go back and try `b` if a later part of the expression fails. This is the main difference between PEGs and most other grammars and regex'es.
8686

87-
`&&a • b`
87+
##### `&&a • b`
8888

8989
The "and predicate" first verifies that `a` matches, then moves the position in the input back to where `a` began and continues with `b`. In other words it verifies that both `a` and `b` match from the same position. So to match one ASCII letter you can use `&&ascii • letter`.
9090

91-
`!a • b`
91+
##### `!a • b`
9292

9393
The "not predicate" verifies that `a` does _not_ match, then just like above it moves the position in the input back to where `a` began and continues with `b`. You can read it like "b and not a".
9494

@@ -119,25 +119,25 @@ They all have the same name as the last part of the property, except for `wholeN
119119

120120
There is also `alphanumeric`, which is a `letter` or a `digit`.
121121

122-
`any`
122+
##### `any`
123123

124124
Matches any character. `!any` matches only the end of the text.
125125

126-
`Line()`
126+
##### `Line()`
127127

128128
Matches a single line, not including the newline characters. So `Line() • Line()` will never match anything, but `Line() • "\n" • Line()` matches 2 lines.
129129

130130
`Line.start` matches at the beginning of the text, and after any newline characters. `Line.end` matches at the end of the text, and right before any newline characters. They both have a length of 0, which means the next pattern will start at the same position in the text.
131131

132-
`Word.boundary`
132+
##### `Word.boundary`
133133

134134
Matches the position right before or right after a word. Like `Line.start` and `Line.end` it also has a length of 0.
135135

136-
`a.repeat(...)`
136+
##### `a.repeat(...)`
137137

138138
`a.repeat(2)` matches 2 of that pattern in a row. `a.repeat(...2)` matches 0, 1 or 2, `a.repeat(2...)` matches 2 or more and `a.repeat(3...6)` between 3 and 6.
139139

140-
`Skip() • a • b`
140+
##### `Skip() • a • b`
141141

142142
Finds the first match of `a • b` from the current position.
143143

0 commit comments

Comments
 (0)