https://github.com/pheymann/parseval
Simple, fast and dependency-free Parser
https://github.com/pheymann/parseval
Last synced: 21 days ago
JSON representation
Simple, fast and dependency-free Parser
- Host: GitHub
- URL: https://github.com/pheymann/parseval
- Owner: pheymann
- Created: 2019-03-28T19:32:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-22T09:56:42.000Z (almost 6 years ago)
- Last Synced: 2025-02-13T18:51:22.454Z (2 months ago)
- Language: Scala
- Homepage:
- Size: 48.8 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
*experimental*: this is a site project for learning purposes
# Parseval
This Parser Combinator library is a small excursion I did into parsers. I tried to build a concise and readable DSL that behaves in a functional manner.```Scala
val plus = lexeme(char('+'))
val minus = lexeme(char('-'))
val number = lexeme(integer) withError "failed to read number"lazy val expr: Parser[Int] = (
number
| expr.left(plus).flatMap(a => number.map(_ + a))
| expr.left(minus).flatMap(a => number.map(_ - a))
)expr.evalConsumeStream("1 + 2 - 3") == Success(-1)
```You can find a [JSON](https://www.json.org/) parser [here](https://github.com/pheymann/parseval/tree/master/json/src/main/scala/parseval/json).