File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+
4
+ import scala .io .Source
5
+ import scala .util .parsing .combinator .Parsers
6
+ import scala .util .parsing .input .Reader
7
+ import scala .util .parsing .input .Position
8
+
9
+
10
+
11
+ object DemoApp extends App {
12
+ val parsers = new DemoParsers
13
+ val reader = new DemoReader (10 )
14
+ val result = parsers.startsWith(" s" ).* (reader)
15
+ Console println result
16
+ }
17
+
18
+
19
+ class DemoReader (n : Int ) extends Reader [String ] {
20
+ def atEnd = n == 0
21
+ def first = " s" + n
22
+ def rest = new DemoReader (n - 1 )
23
+ def pos = new Position {
24
+ def line = 0
25
+ def column = 0
26
+ def lineContents = first
27
+ }
28
+ println(" reader: " + n)
29
+ }
30
+
31
+
32
+ class DemoParsers extends Parsers {
33
+ type Elem = String
34
+ def startsWith (prefix : String ) = acceptIf(_ startsWith prefix)(" Error: " + _)
35
+ }
You can’t perform that action at this time.
0 commit comments