Created
May 12, 2015 06:24
-
-
Save lihaoyi/4dfc76939844da6e1db8 to your computer and use it in GitHub Desktop.
Monadic Parsers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ load.ivy("com.lihaoyi" %% "fastparse" % "0.1.4") | |
@ import fastparse._ | |
import fastparse._ | |
@ val parser = P( "a".rep1.!.flatMap(s => ("b" * s.length) ~ ("c" * s.length)) ) | |
parser: fastparse.Parser[Unit] = parser | |
@ parser.parse("aaa") | |
res4: fastparse.core.Result[Unit] = Failure(parser:0 / "bbb":3 ..."", false) | |
@ parser.parse("aaabbbcc") | |
res5: fastparse.core.Result[Unit] = Failure(parser:0 / "ccc":6 ..."cc", false) | |
@ parser.parse("aaaabcccc") | |
res6: fastparse.core.Result[Unit] = Failure(parser:0 / "bbbb":4 ..."bcccc", false) | |
@ parser.parse("aaaaabbbbbccccc") | |
res7: fastparse.core.Result[Unit] = Success((), 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment