Skip to content

Instantly share code, notes, and snippets.

@jvillste
Created October 31, 2010 20:26
Show Gist options
  • Save jvillste/657092 to your computer and use it in GitHub Desktop.
Save jvillste/657092 to your computer and use it in GitHub Desktop.
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