Permalink
Browse files

Added experimental separate conversion for right-associative sequences

  • Loading branch information...
1 parent 0275b69 commit 4326c9b8ef165ffccc23c19fc46cb7838b107aaf @djspiewak committed Apr 24, 2009
Showing with 11 additions and 6 deletions.
  1. +7 −2 src/main/scala/edu/uwm/cs/gll/ImplicitConversions.scala
  2. +4 −4 src/spec/scala/ArithmeticSpecs.scala
@@ -9,7 +9,8 @@ trait ImplicitConversions {
implicit def funSyntax1[A](p: Parser[A]) = new RichSyntax1(p)
implicit def funLitSyntax(p: String) = new RichSyntax1(literal(p))
implicit def funSyntax2[A, B](p: Parser[~[A, B]]) = new RichSyntax2(p)
- implicit def funSyntax3[A, B, C](p: Parser[~[~[A, B], C]]) = new RichSyntax3(p)
+ implicit def funSyntax3l[A, B, C](p: Parser[~[~[A, B], C]]) = new RichSyntax3l(p)
+ implicit def funSyntax3r[A, B, C](p: Parser[~[A, ~[B, C]]]) = new RichSyntax3r(p)
implicit def funSyntax4[A, B, C, D](p: Parser[~[~[~[A, B], C], D]]) = new RichSyntax4(p)
implicit def funSyntax5[A, B, C, D, E](p: Parser[~[~[~[~[A, B], C], D], E]]) = new RichSyntax5(p)
implicit def funSyntax6[A, B, C, D, E, F](p: Parser[~[~[~[~[~[A, B], C], D], E], F]]) = new RichSyntax6(p)
@@ -29,10 +30,14 @@ trait ImplicitConversions {
def ^^[R](fun: (A, B)=>R) = p map { case a ~ b => fun(a, b) }
}
- class RichSyntax3[A, B, C](p: Parser[~[~[A, B], C]]) {
+ class RichSyntax3l[A, B, C](p: Parser[~[~[A, B], C]]) {
def ^^[R](fun: (A, B, C)=>R) = p map { case a ~ b ~ c => fun(a, b, c) }
}
+ class RichSyntax3r[A, B, C](p: Parser[~[A, ~[B, C]]]) {
+ def ^^[R](fun: (A, B, C)=>R) = p map { case a ~ (b ~ c) => fun(a, b, c) }
+ }
+
class RichSyntax4[A, B, C, D](p: Parser[~[~[~[A, B], C], D]]) {
def ^^[R](fun: (A, B, C, D)=>R) = p map { case a ~ b ~ c ~ d => fun(a, b, c, d) }
}
@@ -145,10 +145,10 @@ object ArithmeticSpecs extends Specification with ScalaCheck with ImplicitConver
// %%
lazy val expr: Parser[Expr] = (
- expr ~ "+" ~ expr ^^ { (e1, _, e2) => Add(e1, e2)}
- | expr ~ "-" ~ expr ^^ { (e1, _, e2) => Sub(e1, e2)}
- | expr ~ "*" ~ expr ^^ { (e1, _, e2) => Mul(e1, e2)}
- | expr ~ "/" ~ expr ^^ { (e1, _, e2) => Div(e1, e2)}
+ expr ~ ("+" ~> expr) ^^ { (e1, e2) => Add(e1, e2)}
+ | expr ~ ("-" ~> expr) ^^ { (e1, e2) => Sub(e1, e2)}
+ | expr ~ ("*" ~> expr) ^^ { (e1, e2) => Mul(e1, e2)}
+ | expr ~ ("/" ~> expr) ^^ { (e1, e2) => Div(e1, e2)}
| "-" ~> expr ^^ Neg
| num ^^ IntLit
)

0 comments on commit 4326c9b

Please sign in to comment.