equal
deleted
inserted
replaced
77 // StrParser(_some_string_) more conveniently as |
77 // StrParser(_some_string_) more conveniently as |
78 // |
78 // |
79 // p"<_some_string_>" |
79 // p"<_some_string_>" |
80 |
80 |
81 implicit def parser_interpolation(sc: StringContext) = new { |
81 implicit def parser_interpolation(sc: StringContext) = new { |
82 def p(args: Any*) = TokParser(sc.s(args:_*)) |
82 def p(args: Any*) = StrParser(sc.s(args:_*)) |
83 } |
83 } |
84 |
84 |
85 p"while" ==> StrParser[String,....] |
|
86 TokParser[List[Token],....] |
|
87 |
|
88 for x := 3 to 10 |
|
89 |
85 |
90 // more convenient syntax for parser combinators |
86 // more convenient syntax for parser combinators |
91 implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new { |
87 implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new { |
92 def ||(q : => Parser[I, T]) = new AltParser[I, T](p, q) |
88 def ||(q : => Parser[I, T]) = new AltParser[I, T](p, q) |
93 def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q) |
89 def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q) |
104 |
100 |
105 val NumParserInt2 = NumParser.map(_.toInt) |
101 val NumParserInt2 = NumParser.map(_.toInt) |
106 |
102 |
107 |
103 |
108 // A parser for palindromes (just returns them as string) |
104 // A parser for palindromes (just returns them as string) |
109 lazy val Pal : Parser[List[Token], String] = { |
105 lazy val Pal : Parser[String, String] = { |
110 (p"a" ~ Pal ~ p"a").map{ case ((x, y), z) => s"$x$y$z" } || |
106 (p"a" ~ Pal ~ p"a").map{ case ((x, y), z) => s"$x$y$z" } || |
111 (p"b" ~ Pal ~ p"b").map{ case ((x, y), z) => s"$x$y$z" } || |
107 (p"b" ~ Pal ~ p"b").map{ case ((x, y), z) => s"$x$y$z" } || |
112 p"a" || p"b" || p"" |
108 p"a" || p"b" || p"" |
113 } |
109 } |
114 |
110 |