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
...@@ -222,26 +222,26 @@ object Parser { ...@@ -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 // 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 ExistsToken => Exists
case ExistsOneToken => ExistsOne case ExistsOneToken => ExistsOne
case ForallToken => Forall case ForallToken => Forall
} ~ accept(FunctionOrPredicateKind) { } ~ accept(FunctionOrPredicateKind) {
case ConstantToken(id) => VariableLabel(id) case ConstantToken(id) => VariableLabel(id)
case SchematicToken(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 { lazy val formula: Syntax[Formula] = recursive {
(binders ~ connectorFormula ~ opt(toplevelConnector ~ connectorFormula)) map { case binderFormulaConstructor ~ f ~ rest => (many(binder) ~ connectorFormula ~ opt(toplevelConnector ~ connectorFormula)) map { case binders ~ f ~ rest =>
rest match { val inner = rest match {
case Some(conn ~ f2) => binderFormulaConstructor(ConnectorFormula(conn, Seq(f, f2))) case Some(conn ~ f2) => ConnectorFormula(conn, Seq(f, f2))
case None => binderFormulaConstructor(f) 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.
Finish editing this message first!
Please register or to comment