Created
May 12, 2015 11:42
-
-
Save AlecZorab/e9b4360c033bbdae75f9 to your computer and use it in GitHub Desktop.
Experiments in fastparse
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
object ParseGist extends App { | |
import fastparse._ | |
val space = P(CharsWhile(" \n".contains(_)).?) | |
val digits = P(CharsWhile('0' to '9' contains _)) | |
val exponent = P(CharIn("eE") ~ CharIn("+-").? ~ digits) | |
val fractional = P("." ~ digits) | |
val integral = P("0" | CharIn('1' to '9') ~ digits.?) | |
val integer = space ~ P(CharIn("+-").? ~ integral).!.map(_.toInt) | |
val double = space ~ P(CharIn("+-").? ~ integral ~ fractional.? ~ exponent.?).!.map(_.toDouble) | |
//why do I get this type? | |
val p4Header:Parser[((Int, Int, Int, Double, Double, Int, Int, Double, Double), Double, Int, Int)] = | |
P(integer ~ integer ~ integer ~ double ~ double ~ integer ~ integer ~ double ~ double ~ double ~ integer ~ integer) | |
val res = p4Header.parse( """2 27 0 3.000000 3.000000 1 3 0.080000 0.000000 0.000000 0 1002""") | |
println(res) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment