From 127aa45f3259de80fcb8b8470f71666e99087182 Mon Sep 17 00:00:00 2001 From: Amal Elshihaby Date: Mon, 24 Nov 2014 20:27:31 +0200 Subject: [PATCH 1/4] [backport] Fix misleading error message when using optional or repeatedly parser #34 (cherry picked from commit c0cfde11e5788b3b63e9ebbb4c0e16c84d1dd416) --- .../util/parsing/combinator/Parsers.scala | 2 +- .../parsing/combinator/RegexParsers.scala | 13 +++- .../combinator/JavaTokenParsersTest.scala | 63 +++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/main/scala/scala/util/parsing/combinator/Parsers.scala b/src/main/scala/scala/util/parsing/combinator/Parsers.scala index 16754646..f6011d3a 100644 --- a/src/main/scala/scala/util/parsing/combinator/Parsers.scala +++ b/src/main/scala/scala/util/parsing/combinator/Parsers.scala @@ -884,7 +884,7 @@ trait Parsers { if (in1.atEnd) s else - lastNoSuccessVar.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1) + lastNoSuccessVar.value filterNot { _.next.pos < in1.pos } getOrElse Failure("end of input expected", in1) case ns => lastNoSuccessVar.value.getOrElse(ns) } } diff --git a/src/main/scala/scala/util/parsing/combinator/RegexParsers.scala b/src/main/scala/scala/util/parsing/combinator/RegexParsers.scala index f345fae0..52e781d0 100644 --- a/src/main/scala/scala/util/parsing/combinator/RegexParsers.scala +++ b/src/main/scala/scala/util/parsing/combinator/RegexParsers.scala @@ -137,8 +137,19 @@ trait RegexParsers extends Parsers { } } + /** + * A parser generator delimiting whole phrases (i.e. programs). + * + * `phrase(p)` succeeds if `p` succeeds and no input is left over after `p`. + * + * @param p the parser that must consume all input for the resulting parser + * to succeed. + * + * @return a parser that has the same result as `p`, but that only succeeds + * if `p` consumed all the input. + */ override def phrase[T](p: Parser[T]): Parser[T] = - super.phrase(p <~ opt("""\z""".r)) + super.phrase(p <~ "".r) /** Parse some prefix of reader `in` with parser `p`. */ def parse[T](p: Parser[T], in: Reader[Char]): ParseResult[T] = diff --git a/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala b/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala index 5851a655..28cf1ba7 100644 --- a/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala +++ b/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala @@ -55,4 +55,67 @@ class JavaTokenParsersTest { parseFailure("with space", 6) } + @Test + def repeatedlyParsesTest: Unit = { + object TestTokenParser extends JavaTokenParsers + import TestTokenParser._ + val p = ident ~ "(?i)AND".r.* + + val parseResult = parseAll(p, "start") + parseResult match { + case Success(r, _) => + assertEquals("start", r._1) + assertEquals(0, r._2.size) + case _ => sys.error(parseResult.toString) + } + + val parseResult1 = parseAll(p, "start start") + parseResult1 match { + case e @ Failure(message, next) => + assertEquals(next.pos.column, 7) + assert(message.endsWith("string matching regex `(?i)AND' expected but `s' found")) + case _ => sys.error(parseResult1.toString) + } + + val parseResult2 = parseAll(p, "start AND AND") + parseResult2 match { + case Success(r, _) => + assertEquals("start", r._1) + assertEquals("AND AND", r._2.mkString(" ")) + case _ => sys.error(parseResult2.toString) + } + } + + @Test + def optionParserTest: Unit = { + object TestTokenParser extends JavaTokenParsers + import TestTokenParser._ + val p = opt(ident) + + val parseResult = parseAll(p, "-start") + parseResult match { + case Failure(message, next) => + assertEquals(next.pos.line, 1) + assertEquals(next.pos.column, 1) + assert(message.endsWith(s"regex `\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*' expected but `-' found")) + case _ => sys.error(parseResult.toString) + } + + val parseResult2 = parseAll(p, "start ") + parseResult2 match { + case Success(r, _) => + assertEquals(r, Some("start")) + case _ => + sys.error(parseResult2.toString) + } + + val parseResult3 = parseAll(p, "start") + parseResult3 match { + case Success(r, _) => + assertEquals(r, Some("start")) + case _ => sys.error(parseResult3.toString) + } + } + + } From 4e0277bcba8e3b20334c7924f6e579fefebe2bd1 Mon Sep 17 00:00:00 2001 From: Antoine Gourlay Date: Wed, 22 Apr 2015 16:10:20 +0200 Subject: [PATCH 2/4] move to scala 2.11.6 and sbt 0.13.8 --- .travis.yml | 2 +- build.sbt | 2 +- project/build.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index d5b69bb4..c37a04c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ env: script: - admin/build.sh scala: - - 2.11.2 + - 2.11.6 jdk: - openjdk6 - openjdk7 diff --git a/build.sbt b/build.sbt index 4c513616..702fcf07 100644 --- a/build.sbt +++ b/build.sbt @@ -6,7 +6,7 @@ name := "scala-parser-combinators" version := "1.0.3-SNAPSHOT" -scalaVersion := "2.11.2" +scalaVersion := "2.11.6" snapshotScalaBinaryVersion := "2.11" diff --git a/project/build.properties b/project/build.properties index 748703f7..a6e117b6 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.7 +sbt.version=0.13.8 From 689d179598ebde7fc0a160085a8bf3b644f2d785 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 30 Apr 2015 13:07:37 +0200 Subject: [PATCH 3/4] Update the scala-modules plugin to 1.0.3 Also set version to 1.0.4-SNAPSHOT, since 1.0.3 is out. --- build.sbt | 14 ++------------ project/plugins.sbt | 4 +--- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/build.sbt b/build.sbt index 702fcf07..ee322c0a 100644 --- a/build.sbt +++ b/build.sbt @@ -4,12 +4,10 @@ scalaModuleSettings name := "scala-parser-combinators" -version := "1.0.3-SNAPSHOT" +version := "1.0.4-SNAPSHOT" scalaVersion := "2.11.6" -snapshotScalaBinaryVersion := "2.11" - // important!! must come here (why?) scalaModuleOsgiSettings @@ -22,12 +20,4 @@ libraryDependencies += "junit" % "junit" % "4.11" % "test" libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test" -MimaPlugin.mimaDefaultSettings - -MimaKeys.previousArtifact := Some(organization.value % s"${name.value}_2.11" % "1.0.2") - -// run mima during tests -test in Test := { - MimaKeys.reportBinaryIssues.value - (test in Test).value -} +mimaPreviousVersion := Some("1.0.2") diff --git a/project/plugins.sbt b/project/plugins.sbt index 5f604e6f..25f33731 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1 @@ -addSbtPlugin("org.scala-lang.modules" % "scala-module-plugin" % "1.0.2") - -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.6") +addSbtPlugin("org.scala-lang.modules" % "scala-module-plugin" % "1.0.3") From aa98174a73b682f1d5a1e5acacf656e320fe34c4 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Thu, 30 Apr 2015 13:08:52 +0200 Subject: [PATCH 4/4] update version numbers for v1.0.4 --- README.md | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 77c83325..3b9023b4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ As of Scala 2.11, this library is a separate jar that can be omitted from Scala To depend on scala-parser-combinators in SBT, add something like this to your build.sbt: ``` -libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.2" +libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4" ``` (Assuming you're using a `scalaVersion` for which a scala-parser-combinators is published. The first 2.11 milestone for which this is true is 2.11.0-M4.) diff --git a/build.sbt b/build.sbt index ee322c0a..c9209e22 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ scalaModuleSettings name := "scala-parser-combinators" -version := "1.0.4-SNAPSHOT" +version := "1.0.5-SNAPSHOT" scalaVersion := "2.11.6"