Skip to content

using ~> and <~ enables backtracking disabled by ~! #6464

Closed
@scabug

Description

@scabug
// using ~> and <~ enables backtracking disabled by ~!
// it seems that scala.util.parsing.combinator.Parsers.OnceParser must implement own ~> <~ instead of inheriting them.

// testcase:

import scala.util.parsing.input.CharSequenceReader
import scala.util.parsing.combinator.RegexParsers


object SspParser extends RegexParsers {
  val ok: Parser[Any] =
    ( "<%" ~! rep(' ') ~  "\\w+".r  ~ rep(' ') ~ "%>"
    | "<%" ~! error("should not fail here, because of ~!") )

  val buggy: Parser[Any] =
    ( "<%" ~! rep(' ') ~> "\\w+".r <~ rep(' ') ~ "%>"
    | "<%" ~! error("should not fail here, because of ~!") )

  def main(args:Array[String]) {
    println( phrase(ok)   (new CharSequenceReader("<% hi %>")))  // [1.9] parsed: ((((<%~List( ))~hi)~List( ))~%>)
    println( phrase(ok)   (new CharSequenceReader("<%    %>")))  // [1.7] error: string matching regex `\w+' expected but `%' found
    println( phrase(buggy)(new CharSequenceReader("<% hi %>")))  // [1.9] parsed: hi
    println( phrase(buggy)(new CharSequenceReader("<%    %>")))  // java.lang.RuntimeException: should not fail here, because of ~!
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions