File tree 2 files changed +46
-1
lines changed
main/scala/scala/util/parsing/combinator
test/scala/scala/util/parsing/combinator
2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -949,6 +949,12 @@ trait Parsers {
949
949
*/
950
950
trait OnceParser [+ T ] extends Parser [T ] {
951
951
override def ~ [U ](p : => Parser [U ]): Parser [~ [T , U ]]
952
- = OnceParser { (for (a <- this ; b <- commit(p)) yield new ~ (a,b)).named(" ~" ) }
952
+ = OnceParser { (for (a <- this ; b <- commit(p)) yield new ~ (a,b)).named(" ~" ) }
953
+
954
+ override def ~> [U ](p : => Parser [U ]): Parser [U ]
955
+ = OnceParser { (for (a <- this ; b <- commit(p)) yield b).named(" ~>" ) }
956
+
957
+ override def <~ [U ](p : => Parser [U ]): Parser [T ]
958
+ = OnceParser { (for (a <- this ; b <- commit(p)) yield a).named(" <~" ) }
953
959
}
954
960
}
Original file line number Diff line number Diff line change
1
+ import scala .util .parsing .input .CharSequenceReader
2
+ import scala .util .parsing .combinator .RegexParsers
3
+
4
+ import org .junit .Test
5
+ import org .junit .Assert .assertEquals
6
+
7
+ class t6464 {
8
+ object SspParser extends RegexParsers {
9
+ val ok : Parser [Any ] =
10
+ (" <%" ~! rep(' ' ) ~ " \\ w+" .r ~ rep(' ' ) ~ " %>"
11
+ | " <%" ~! err(" should not fail here, because of ~!" ))
12
+
13
+ val buggy : Parser [Any ] =
14
+ (" <%" ~! rep(' ' ) ~> " \\ w+" .r <~ rep(' ' ) ~ " %>"
15
+ | " <%" ~! err(" should not fail here, because of ~!" ))
16
+
17
+ }
18
+ @ Test
19
+ def test : Unit = {
20
+ assertEquals(
21
+ " [1.9] parsed: ((((<%~List( ))~hi)~List( ))~%>)" ,
22
+ SspParser .phrase(SspParser .ok)(new CharSequenceReader (" <% hi %>" )).toString)
23
+ val expected = """ [1.7] error: string matching regex '\w+' expected but '%' found
24
+
25
+ <% %>
26
+ ^"""
27
+ assertEquals(
28
+ expected,
29
+ SspParser .phrase(SspParser .ok)(new CharSequenceReader (" <% %>" )).toString)
30
+
31
+ assertEquals(
32
+ " [1.9] parsed: hi" ,
33
+ SspParser .phrase(SspParser .buggy)(new CharSequenceReader (" <% hi %>" )).toString)
34
+
35
+ assertEquals(
36
+ expected,
37
+ SspParser .phrase(SspParser .buggy)(new CharSequenceReader (" <% %>" )).toString)
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments