progs/comb2.scala
changeset 686 05cfce0fdef7
parent 685 75d9f9e5906f
--- a/progs/comb2.scala	Thu Nov 07 00:07:16 2019 +0000
+++ b/progs/comb2.scala	Thu Nov 14 01:21:02 2019 +0000
@@ -54,18 +54,18 @@
 implicit def string2parser(s : String) = StringParser(s)
 
 implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new {
-  def || (q : => Parser[I, T]) = new AltParser[I, T](p, q)
+  def ||(q : => Parser[I, T]) = new AltParser[I, T](p, q)
   def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f)
-  def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
+  def ~[S](q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
 }
 
 implicit def StringOps(s: String) = new {
-  def || (q : => Parser[String, String]) = new AltParser[String, String](s, q)
-  def || (r: String) = new AltParser[String, String](s, r)
+  def ||(q : => Parser[String, String]) = new AltParser[String, String](s, q)
+  def ||(r: String) = new AltParser[String, String](s, r)
   def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f)
   def ~[S](q : => Parser[String, S]) = 
     new SeqParser[String, String, S](s, q)
-  def ~ (r: String) = 
+  def ~(r: String) = 
     new SeqParser[String, String, String](s, r)
 }
 
@@ -102,6 +102,7 @@
   }
 }
 
+// arithmetic expressions
 lazy val AExp: Parser[String, AExp] = 
   (Te ~ "+" ~ AExp) ==> { case x ~ _ ~ z => Aop("+", x, z): AExp } ||
   (Te ~ "-" ~ AExp) ==> { case x ~ _ ~ z => Aop("-", x, z): AExp } || Te 
@@ -140,7 +141,7 @@
 
 // blocks (enclosed in curly braces)
 lazy val Block: Parser[String, Block] =
-  (("{" ~ Stmts ~ "}") ==> { case x ~ y ~ z => y} || 
+  (("{" ~ Stmts ~ "}") ==> { case _ ~ y ~ _ => y } || 
    (Stmt ==> (s => List(s))))