Scala parser combinators: how to parse "if(x)" if x can contain a ")"
Posted
by Germán
on Stack Overflow
See other posts from Stack Overflow
or by Germán
Published on 2010-05-23T21:12:48Z
Indexed on
2010/05/23
21:21 UTC
Read the original article
Hit count: 308
scala
|parser-combinators
I'm trying to get this to work:
def emptyCond: Parser[Cond] = ("if" ~ "(") ~> regularStr <~ ")" ^^ { case s => Cond("",Nil,Nil) }
where regularStr is defined to accept a number of things, including ")". Of course, I want this to be an acceptable input: if(foo()). But for any if(x) it is taking the ")" as part of the regularStr and so this parser never succeeds.
What am I missing?
© Stack Overflow or respective owner