Created
October 31, 2010 20:26
-
-
Save jvillste/657092 to your computer and use it in GitHub Desktop.
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
class ModelParser extends JavaTokenParsers { | |
def packageParser: Parser[PackageAST] = ident ~ "{" ~ rep(typeParser) ~ "}" ^^ | |
{ case name ~ "{" ~ types ~ "}" => new PackageAST(name, types) } | |
def typeParser: Parser[TypeAST] = ident ~ opt(":" ~> repsep(ident,",")) ~ opt("{" ~> rep(propertyParser) <~ "}") ^^ | |
{ case name ~ superTypes ~ properties => new TypeAST(name,superTypes,properties) } | |
def propertyParser: Parser[PropertyAST] = ident ~ ":" ~ ident ^^ | |
{ case name ~ ":" ~ range => new PropertyAST(name,range) } | |
def packageName: Parser[String] = """[a-f][a-f][a-f]""".r | |
} | |
class PackageAST(name:String, types:List[TypeAST]) | |
class TypeAST(name:String, superTypes:Option[List[String]], properties:Option[List[PropertyAST]] ) | |
class PropertyAST(name:String, range:String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment