code_junkie

Scala combinator parsers - distinguish between number strings and variable strings

Nov 12th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. def factor: Parser[ExprTree] = (wholeNumber | "(" ~ expr ~ ")" | ident) ^^ {
  2. case a: wholeNumber => Number(a.toInt)
  3. case a: String => Variable(a)
  4. }
  5.  
  6. def factor: Parser[ExprTree] = ( wholeNumber ^^ { Number(_.toInt) }
  7. | "(" ~> expr <~ ")"
  8. | ident ^^ { Variable(_) } )
Add Comment
Please, Sign In to add comment