Last active
August 29, 2015 14:01
-
-
Save gszeliga/9b00f91195b6dc6234a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def natural = rep1(single_digit) ^^ (_.mkString.toInt) named ("natural") | |
def signedInt = new Parser[Int] { | |
def apply(in: Input) = { | |
'-'(in) match { | |
case Success(_, rest) => natural(rest) map (_ * -1) | |
case _ => natural(in) | |
} | |
} | |
} named ("signed_int") | |
def rawbyte = new Parser[Byte] { | |
def apply(in: Input) = { | |
if (in.atEnd) Failure("End of input reached", in) | |
else Success(in.first, in.rest) | |
} | |
} named ("raw_bytes") | |
def string: Parser[BString] = | |
natural ~ ':' >> { | |
case size ~ _ => repN(size, rawbyte) ^^ (BString(_)) | |
} named ("string") | |
def int: Parser[BInt] = { | |
delimitedBy(NUMBER_BEGIN, NUMBER_END)(signedInt) ^^ (BInt(_)) named ("int") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment