File tree Expand file tree Collapse file tree 3 files changed +35
-1
lines changed
main/scala/scala/util/parsing/combinator
test/scala/scala/util/parsing/combinator Expand file tree Collapse file tree 3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 11import com .typesafe .tools .mima .plugin .{MimaPlugin , MimaKeys }
2+ import com .typesafe .tools .mima .core .{ProblemFilters , MissingMethodProblem }
23
34scalaModuleSettings
45
@@ -31,3 +32,5 @@ test in Test := {
3132 MimaKeys .reportBinaryIssues.value
3233 (test in Test ).value
3334}
35+
36+ MimaKeys .binaryIssueFilters += ProblemFilters .exclude[MissingMethodProblem ](" scala.util.parsing.combinator.RegexParsers.scala$util$parsing$combinator$RegexParsers$$super$err" )
Original file line number Diff line number Diff line change @@ -137,6 +137,22 @@ trait RegexParsers extends Parsers {
137137 }
138138 }
139139
140+ // we might want to make it public/protected in a future version
141+ private def ws [T ](p : Parser [T ]): Parser [T ] = new Parser [T ] {
142+ def apply (in : Input ) = {
143+ val offset = in.offset
144+ val start = handleWhiteSpace(in.source, offset)
145+ p(in.drop (start - offset))
146+ }
147+ }
148+
149+ /**
150+ * @inheritdoc
151+ *
152+ * This parser additionnal skips whitespace if `skipWhitespace` returns true.
153+ */
154+ override def err (msg : String ) = ws(super .err(msg))
155+
140156 override def phrase [T ](p : Parser [T ]): Parser [T ] =
141157 super .phrase(p <~ opt(""" \z""" .r))
142158
Original file line number Diff line number Diff line change 11package scala .util .parsing .combinator
22
33import org .junit .Test
4- import org .junit .Assert .assertEquals
4+ import org .junit .Assert .{ assertEquals , assertTrue }
55
66class RegexParsersTest {
77 @ Test
@@ -73,4 +73,19 @@ class RegexParsersTest {
7373 val success = parseAll(twoWords, " first second" ).asInstanceOf [Success [(String , String )]]
7474 assertEquals((" second" , " first" ), success.get)
7575 }
76+
77+ @ Test
78+ def errorConsumesWhitespace : Unit = {
79+ object parser extends RegexParsers {
80+ def num = " \\ d+" .r
81+
82+ def twoNums = num ~ (num | err(" error!" ))
83+ }
84+ import parser ._
85+
86+ // this used to return a Failure (for the second num)
87+ val error = parseAll(twoNums, " 458 bar" )
88+ assertTrue(s " expected an Error but got: ${error.getClass.getName}" , error.isInstanceOf [Error ])
89+ assertEquals(" error!" , error.asInstanceOf [Error ].msg)
90+ }
7691}
You can’t perform that action at this time.
0 commit comments