Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def classdecl: Parser[ClassDecl] = "class" ~> identifier ~ opt("extends" ~> identifier) ~ ("{" ~> listtomem <~ "}") ^^ {
- case id ~ Some(sup) ~ d => ClassDecl(id,sup,d)
- case id ~ None ~ d => ClassDecl(id,null,d)
- }
- def listtomem: Parser[List[Decl]] = rep(attribute | abstractmethod | method) ^^
- {
- case dl => dl.foldLeft(List[Decl]())((a,b) => a++b)
- }
- def attribute: Parser[List[Decl]] = (vardecl|constdecl)
- def vardecl: Parser[List[VarDecl]] =rep1sep(identifier, ",") ~ (":" ~> vartype<~ ";") ^^ {case dl ~ typ =>dl.map( x=> VarDecl(x,typ)) }
- def constdecl: Parser[List[ConstDecl]] = ("final" ~> vartype) ~ (identifier <~ "=") ~ (express <~ ";") ^^ {
- case typ ~ id ~ expr => List(ConstDecl(id, typ, expr))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement