Skip to content

Commit

Permalink
more work on parse constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornregnell committed Apr 10, 2024
1 parent c29d913 commit 8c89538
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/scala/05-constraints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,25 @@ object csp:
object parseConstraints:
import parseUtils.*
object mk:
type ConstrMaker = Seq[Var] => Constr
type Param = Var | Int | Boolean

type ConstrMaker = Seq[Param] => Constr

private def bang(x: Param) = throw err.badParamType(x.toString)

extension (x: Param)
def asVar: Var = x match { case x: Var => x case _ => bang(x)}
def asInt: Int = x match { case x: Int => x case _ => bang(x)}
def asBool: Boolean = x match { case x: Boolean => x case _ => bang(x)}

val constr: Map[String, ConstrMaker] = Map(
"XeqY" -> (xs => XeqY(xs(0), xs(1)))
"XeqY" -> (xs => XeqY(xs(0).asVar, xs(1).asVar)), //should these be strings and xs(0).parseVar ???
"XeqC" -> (xs => XeqC(xs(0).asVar, xs(1).asInt)),
)

val oper: Map[String, ConstrMaker] = Map(
">" -> (xs => XgtY(xs(0), xs(1))),
"<" -> (xs => XltY(xs(0), xs(1))),
">" -> {xs => XgtY(xs(0).asVar, xs(1).asVar)},
"<" -> {xs => XltY(xs(0).asVar, xs(1).asVar)},
)
end mk

Expand Down

0 comments on commit 8c89538

Please sign in to comment.