Advertisement
tudzic

Untitled

Oct 29th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.75 KB | None | 0 0
  1. def classdecl: Parser[ClassDecl] = "class" ~> identifier ~ opt("extends" ~> identifier) ~ ("{" ~> listtomem <~ "}") ^^ {
  2.     case id ~ Some(sup) ~ d => ClassDecl(id,sup,d)
  3.     case id ~ None ~ d => ClassDecl(id,null,d)
  4.   }
  5.    
  6.   def listtomem: Parser[List[Decl]] =  rep(attribute | abstractmethod | method) ^^
  7.   {
  8.   case dl => dl.foldLeft(List[Decl]())((a,b) => a++b)
  9.   }
  10.    
  11.   def attribute: Parser[List[Decl]] = (vardecl|constdecl)
  12.    
  13.   def vardecl: Parser[List[VarDecl]] =rep1sep(identifier, ",") ~ (":" ~> vartype<~ ";")  ^^ {case dl ~ typ =>dl.map( x=> VarDecl(x,typ)) }
  14.  
  15.   def constdecl: Parser[List[ConstDecl]] = ("final" ~> vartype) ~ (identifier <~ "=") ~ (express <~ ";") ^^ {
  16.       case typ ~ id ~ expr => List(ConstDecl(id, typ, expr))
  17.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement