Skip to content

Commit 42ea6fa

Browse files
authored
Update README.md
1 parent 629cfed commit 42ea6fa

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
A nice parser combinator library for Kotlin
66

77
```kotlin
8-
val booleanGrammar = object : Grammar<BooleanExpression>() {
9-
val id by token("\\w+")
10-
val not by token("!")
11-
val and by token("&")
12-
val or by token("|")
13-
val ws by token("\\s+", ignore = true)
14-
val lpar by token("\\(")
15-
val rpar by token("\\)")
16-
17-
val term =
18-
(id use { Variable(text) }) or
19-
(-not * parser(this::term) map { (Not(it) }) or
20-
(-lpar * parser(this::rootParser) * -rpar)
21-
22-
val andChain = leftAssociative(term, and) { l, _, r -> And(l, r) }
23-
val rootParser = leftAssociative(andChain, or) { l, _, r -> Or(l, r) }
24-
}
25-
26-
val ast = booleanGrammar.parseToEnd("a & !b | b & (!a | c)")
8+
val booleanGrammar = object : Grammar<BooleanExpression>() {
9+
val id by token("\\w+")
10+
val not by token("!")
11+
val and by token("&")
12+
val or by token("|")
13+
val ws by token("\\s+", ignore = true)
14+
val lpar by token("\\(")
15+
val rpar by token("\\)")
16+
17+
val term =
18+
(id use { Variable(text) }) or
19+
(-not * parser(this::term) map { (Not(it) }) or
20+
(-lpar * parser(this::rootParser) * -rpar)
21+
22+
val andChain = leftAssociative(term, and) { l, _, r -> And(l, r) }
23+
val rootParser = leftAssociative(andChain, or) { l, _, r -> Or(l, r) }
24+
}
25+
26+
val ast = booleanGrammar.parseToEnd("a & !b | b & (!a | c)")
2727
```
2828

2929
### Using with Gradle

0 commit comments

Comments
 (0)