Created
March 7, 2010 05:52
-
-
Save kmizu/324179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code doen't work in Scala 2.7.X. | |
*/ | |
import scala.util.parsing.combinator._ | |
import scala.util.parsing.input._ | |
object LeftRecursion extends PackratParsers { | |
type Elem = Char | |
lazy val any = elem("", _ != CharSequenceReader.EofCh) | |
lazy val P: PackratParser[Any] = A ~ not(any) | |
lazy val A: PackratParser[Any] = A ~ 'a' | success(null) | |
def main(args: Array[String]) { | |
implicit def in(str: String) = | |
new PackratReader(new CharSequenceReader(str)) | |
println(P("")) // success | |
println(P("aaa")) // success | |
println(P("b")) // failure | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment