Skip to content
Snippets Groups Projects
Commit 35d23134 authored by Katja Goltsova's avatar Katja Goltsova Committed by Viktor Kunčak
Browse files

Simplify binders parsing

parent fe46ea4a
No related branches found
No related tags found
4 merge requests!62Easy tactics,!58Easy tactics,!54Front integration,!53Front integration
This commit is part of merge request !53. Comments created here will be created in the context of that merge request.
......@@ -222,26 +222,26 @@ object Parser {
}
)
def getBinderFormulaConstructor(binders: Seq[BinderLabel ~ VariableLabel]): Formula => Formula = binders match {
case Seq() => f => f
case (binder ~ boundVar) +: rest => f => BinderFormula(binder, boundVar, getBinderFormulaConstructor(rest)(f))
}
// consume binders and return a function that constructs a BinderFormula given the inner formula
val binders: Syntax[Formula => Formula] = many(accept(BinderKind) {
val binder: Syntax[(BinderLabel, VariableLabel)] = (accept(BinderKind) {
case ExistsToken => Exists
case ExistsOneToken => ExistsOne
case ForallToken => Forall
} ~ accept(FunctionOrPredicateKind) {
case ConstantToken(id) => VariableLabel(id)
case SchematicToken(id) => VariableLabel(id)
} ~ elem(DotKind).unit(DotToken).skip) map getBinderFormulaConstructor
} ~ elem(DotKind).unit(DotToken).skip) map { case b ~ v =>
(b, v)
}
lazy val formula: Syntax[Formula] = recursive {
(binders ~ connectorFormula ~ opt(toplevelConnector ~ connectorFormula)) map { case binderFormulaConstructor ~ f ~ rest =>
rest match {
case Some(conn ~ f2) => binderFormulaConstructor(ConnectorFormula(conn, Seq(f, f2)))
case None => binderFormulaConstructor(f)
(many(binder) ~ connectorFormula ~ opt(toplevelConnector ~ connectorFormula)) map { case binders ~ f ~ rest =>
val inner = rest match {
case Some(conn ~ f2) => ConnectorFormula(conn, Seq(f, f2))
case None => f
}
binders.foldRight(inner) { case ((binder, v), f) =>
BinderFormula(binder, v, f)
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment