-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from Philippus/issue/29
Make RegexParser.err handle whitespace like literal and regex
- Loading branch information
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
shared/src/test/scala/scala/util/parsing/combinator/gh29.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package scala.util.parsing.combinator | ||
|
||
import org.junit.Test | ||
import org.junit.Assert.assertEquals | ||
|
||
class gh29 { | ||
object Foo extends JavaTokenParsers { | ||
def word(x: String) = s"\\b$x\\b".r | ||
|
||
lazy val expr = aSentence | something | ||
|
||
lazy val aSentence = noun ~ verb ~ obj | ||
|
||
lazy val noun = word("noun") | ||
lazy val verb = word("verb") | err("not a verb!") | ||
lazy val obj = word("object") | ||
|
||
lazy val something = word("FOO") | ||
} | ||
|
||
val expected = | ||
"""[1.6] error: not a verb! | ||
noun vedsfasdf | ||
^""".stripMargin | ||
|
||
@Test | ||
def test(): Unit = { | ||
val f = Foo.parseAll(Foo.expr, "noun verb object") | ||
|
||
assertEquals("[1.17] parsed: ((noun~verb)~object)", f.toString) | ||
|
||
val g = Foo.parseAll(Foo.expr, "noun vedsfasdf") | ||
assertEquals(expected, g.toString) | ||
} | ||
} |