progs/comb1.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 26 Oct 2018 17:13:41 +0100
changeset 593 bb24d4e207b6
parent 590 c6a1e19e9801
child 594 d40d7d7b85bc
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
import scala.language.implicitConversions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
import scala.language.reflectiveCalls
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
     4
/* Note, in the lectures I did not show the type consraint
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
     5
 * I <% Seq[_] , which means that the input type I can be
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
     6
 * treated, or seen, as a sequence. */
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
     7
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
     8
abstract class Parser[I <% Seq[_], T] {
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
     9
  def parse(ts: I): Set[(T, I)]
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    11
  def parse_all(ts: I) : Set[T] =
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
    12
    for ((head, tail) <- parse(ts); 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
    13
        if (tail.isEmpty)) yield head
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    16
class SeqParser[I <% Seq[_], T, S](p: => Parser[I, T], 
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    17
                                   q: => Parser[I, S]) extends Parser[I, (T, S)] {
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    18
  def parse(sb: I) = 
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
    for ((head1, tail1) <- p.parse(sb); 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
         (head2, tail2) <- q.parse(tail1)) yield ((head1, head2), tail2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    23
class AltParser[I <% Seq[_], T](p: => Parser[I, T], 
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    24
                                q: => Parser[I, T]) extends Parser[I, T] {
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    25
  def parse(sb: I) = p.parse(sb) ++ q.parse(sb)   
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    28
class FunParser[I <% Seq[_], T, S](p: => Parser[I, T], 
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    29
                                   f: T => S) extends Parser[I, S] {
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    30
  def parse(sb: I) = 
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
    for ((head, tail) <- p.parse(sb)) yield (f(head), tail)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
183
b17eff695c7f added new stuff
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 178
diff changeset
    34
// atomic parsers  
461
890188804fb4 updated
Christian Urban <urbanc@in.tum.de>
parents: 458
diff changeset
    35
case class CharParser(c: Char) extends Parser[String, Char] {
177
53def1fbf472 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
    36
  def parse(sb: String) = 
462
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
    37
    if (sb != "" && sb.head == c) Set((c, sb.tail)) else Set()
177
53def1fbf472 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
    38
}
53def1fbf472 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 172
diff changeset
    39
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    40
import scala.util.matching.Regex
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    41
case class RegexParser(reg: Regex) extends Parser[String, String] {
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    42
  def parse(sb: String) = reg.findPrefixMatchOf(sb) match {
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    43
    case None => Set()
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    44
    case Some(m) => Set((m.matched, m.after.toString))  
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    48
val NumParser = RegexParser("[0-9]+".r)
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    49
def StringParser(s: String) = RegexParser(Regex.quote(s).r)
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    50
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    51
val NumParserInt = NumParser ==> (s => s.toInt)
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
    53
// convenience
462
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
    54
implicit def string2parser(s: String) = StringParser(s)
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    55
implicit def char2parser(c: Char) = CharParser(c)
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    56
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
implicit def ParserOps[I<% Seq[_], T](p: Parser[I, T]) = new {
590
c6a1e19e9801 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
    58
  def | (q : => Parser[I, T]) = new AltParser[I, T](p, q)
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
implicit def StringOps(s: String) = new {
590
c6a1e19e9801 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
    64
  def | (q : => Parser[String, String]) = new AltParser[String, String](s, q)
c6a1e19e9801 updated
Christian Urban <urbanc@in.tum.de>
parents: 588
diff changeset
    65
  def | (r: String) = new AltParser[String, String](s, r)
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
  def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    67
  def ~[S] (q : => Parser[String, S]) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    68
    new SeqParser[String, String, S](s, q)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    69
  def ~ (r: String) = 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    70
    new SeqParser[String, String, String](s, r)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    71
}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    72
588
a4646557016d updated
Christian Urban <urbanc@in.tum.de>
parents: 586
diff changeset
    73
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    74
lazy val Pal : Parser[String, String] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    75
  (("a" ~ Pal ~ "a") ==> { case ((x, y), z) => x + y + z } |
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    76
   ("b" ~ Pal ~ "b") ==> { case ((x, y), z) => x + y + z } | "a" | "b" | "")
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    77
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
    78
Pal.parse_all("abaaaba")
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    79
Pal.parse("abaaaba")
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
    80
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
    81
println("Palindrome: " + Pal.parse_all("abaaaba"))
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
    83
// well-nested parenthesis parser
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
lazy val P : Parser[String, String] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    85
  "(" ~ P ~ ")" ~ P ==> { case (((_, x), _), y) => "{" + x + "}" + y } | ""
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
P.parse_all("(((()()))())")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
P.parse_all("(((()()))()))")
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
P.parse_all(")(")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
    90
P.parse_all("()")
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
360
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 185
diff changeset
    92
// arithmetic expressions
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
    93
367
04127a5aad23 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 366
diff changeset
    94
lazy val E: Parser[String, Int] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    95
  (T ~ "+" ~ E) ==> { case ((x, y), z) => x + z } |
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    96
  (T ~ "-" ~ E) ==> { case ((x, y), z) => x - z } | T 
470
8df654e9eb4e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 467
diff changeset
    97
lazy val T: Parser[String, Int] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
    98
  (F ~ "*" ~ T) ==> { case ((x, y), z) => x * z } | F
367
04127a5aad23 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 366
diff changeset
    99
lazy val F: Parser[String, Int] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   100
  ("(" ~ E ~ ")") ==> { case ((x, y), z) => y } | NumParserInt
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   101
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   102
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   103
println(E.parse_all("4*2+3"))
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   104
println(E.parse_all("4*(2+3)"))
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   105
println(E.parse_all("4/2+3"))
367
04127a5aad23 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 366
diff changeset
   106
println(E.parse("1 + 2 * 3"))
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   107
println(E.parse_all("(1+2)+3"))
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   108
println(E.parse_all("1+2+3"))  
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   109
586
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   110
Christian Urban <urbanc@in.tum.de>
parents: 531
diff changeset
   111
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   112
// no left-recursion allowed, otherwise will loop
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   113
lazy val EL: Parser[String, Int] = 
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   114
  (EL ~ "+" ~ EL ==> { case ((x, y), z) => x + z} | 
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   115
   EL ~ "*" ~ EL ==> { case ((x, y), z) => x * z} |
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   116
   "(" ~ EL ~ ")" ==> { case ((x, y), z) => y} |
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   117
   NumParserInt)
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   118
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   119
//println(EL.parse_all("1+2+3"))
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   120
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
462
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   122
// a repetition parser
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   123
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   124
def RepParser[I  <% Seq[_], T](p: => Parser[I, T]): Parser[I, List[T]] = {
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   125
  p ==> { case x => x :: Nil } |
462
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   126
  p ~ RepParser(p) ==> { case (x, y) => x :: y }   
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   127
}
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   128
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   129
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   130
// a repetition parser
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   131
lazy val R : Parser[String, List[Char]] = RepParser('a') 
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   132
println(R.parse_all("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   133
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   134
Christian Urban <urbanc@in.tum.de>
parents: 461
diff changeset
   135
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   136
// non-ambiguous vs ambiguous grammars
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
lazy val S : Parser[String, String] =
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   138
  ("1" ~ S ~ S) ==> { case ((x, y), z) => x + y + z } | ""
172
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   140
S.parse("1" * 15)
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   141
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   142
lazy val U : Parser[String, String] =
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   143
  ("1" ~ U) ==> { case (x, y) => x + y  } | ""
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   144
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   145
U.parse("1" * 15)
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   146
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   147
U.parse("11")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   148
U.parse("11111")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   149
U.parse("11011")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   150
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   151
U.parse_all("1" * 100)
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   152
U.parse_all("1" * 100 + "0")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   153
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   154
lazy val UCount : Parser[String, Int] =
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   155
  ("1" ~ UCount) ==> { case (x, y) => y + 1 } | 
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   156
  "" ==> { (x) => 0 }
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   157
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   158
UCount.parse("11111")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   159
UCount.parse_all("11111")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   160
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   161
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   162
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   163
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   164
// Single Character parser
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   165
lazy val One : Parser[String, String] = "1"
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   166
lazy val Two : Parser[String, String] = "2"
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   167
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   168
One.parse("1")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   169
One.parse("111")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   170
366
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   171
(One ~ One).parse("111")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   172
(One ~ One ~ One).parse("111")
5a83336a9690 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 362
diff changeset
   173
(One ~ One ~ One ~ One).parse("1111")
362
57ea439feaff updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 360
diff changeset
   174
593
bb24d4e207b6 updated
Christian Urban <urbanc@in.tum.de>
parents: 590
diff changeset
   175
(One | Two).parse("111")
467
b5ec11e89768 fixed bug
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 462
diff changeset
   176
b5ec11e89768 fixed bug
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 462
diff changeset
   177
531
Christian Urban <urbanc@in.tum.de>
parents: 470
diff changeset
   178