Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0345e49

Browse files
committed
Add test for #45
1 parent f809b06 commit 0345e49

File tree

1 file changed

+46
-0
lines changed
  • src/test/scala/scala/util/parsing/combinator

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package scala.util.parsing.combinator
2+
3+
import scala.util.parsing.input._
4+
import scala.collection.immutable.PagedSeq
5+
6+
import org.junit.Test
7+
import org.junit.Assert.assertTrue
8+
9+
import scala.util.parsing.combinator.syntactical.StandardTokenParsers
10+
11+
class gh45 {
12+
13+
@Test
14+
def test4: Unit = {
15+
def check(rd: Reader[Char]): Unit = {
16+
val g = new grammar
17+
val p = g.phrase(g.script)
18+
val parseResult = p(new g.lexical.Scanner(rd))
19+
assertTrue(parseResult.isInstanceOf[g.Success[_]])
20+
}
21+
22+
val str = "x once y"
23+
check(new CharSequenceReader(str))
24+
/* Note that this only tests PagedSeq.rest since neither
25+
* PackratReader nor lexical.Scanner override/use the drop method.
26+
*/
27+
check(new PagedSeqReader(PagedSeq.fromStrings(List(str))))
28+
}
29+
30+
}
31+
32+
private final class grammar extends StandardTokenParsers with PackratParsers {
33+
lexical.reserved ++= List("x", "y", "z", "once")
34+
35+
var onceCnt: Int = 0
36+
lazy val once: PackratParser[String] = memo("once") ^? {
37+
case s if onceCnt == 0 =>
38+
onceCnt += 1
39+
s
40+
}
41+
42+
lazy val script: PackratParser[Any] =
43+
( "x" ~ once ~ "z"
44+
| "x" ~ once ~ "y"
45+
)
46+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /