File tree 3 files changed +35
-1
lines changed
main/scala/scala/util/parsing/combinator
test/scala/scala/util/parsing/combinator
3 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
1
import com .typesafe .tools .mima .plugin .{MimaPlugin , MimaKeys }
2
+ import com .typesafe .tools .mima .core .{ProblemFilters , MissingMethodProblem }
2
3
3
4
scalaModuleSettings
4
5
@@ -31,3 +32,5 @@ test in Test := {
31
32
MimaKeys .reportBinaryIssues.value
32
33
(test in Test ).value
33
34
}
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 {
137
137
}
138
138
}
139
139
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
+
140
156
override def phrase [T ](p : Parser [T ]): Parser [T ] =
141
157
super .phrase(p <~ opt(""" \z""" .r))
142
158
Original file line number Diff line number Diff line change 1
1
package scala .util .parsing .combinator
2
2
3
3
import org .junit .Test
4
- import org .junit .Assert .assertEquals
4
+ import org .junit .Assert .{ assertEquals , assertTrue }
5
5
6
6
class RegexParsersTest {
7
7
@ Test
@@ -73,4 +73,19 @@ class RegexParsersTest {
73
73
val success = parseAll(twoWords, " first second" ).asInstanceOf [Success [(String , String )]]
74
74
assertEquals((" second" , " first" ), success.get)
75
75
}
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
+ }
76
91
}
You can’t perform that action at this time.
0 commit comments