object ABCParser extends App {
object Parser extends SimpleParser {
val InputLine = rule { &(A ~ 'c') ~ oneOrMore('a') ~ B ~ !(ch('a') | 'b' | 'c') ~ EOI }
val A: Rule0 = rule { 'a' ~ optional(A) ~ 'b' }
val B: Rule0 = rule { 'b' ~ optional(B) ~ 'c' }
}
repl()
@tailrec
def repl(): Unit =
StdIn.readLine("---\nEnter expression for abc-parser > ") match {
case "" ⇒ // terminate
case line ⇒
Parser.InputLine.run(line, maxValueStackSize = 2048) match {
case Success(_) ⇒ println("Expression is valid")
case Failure(e: ParseError) ⇒ println("Expression is not valid: " + e.format(line))
case Failure(e) ⇒ println("Unexpected error during parsing run: " + e)
}
repl()
}
}