Skip to content
Snippets Groups Projects
Verified Commit 850ff7e6 authored by Florian Cassayre's avatar Florian Cassayre
Browse files

Fix the indenting of imports in the printer

parent 78cfcc81
Branches
Tags
1 merge request!3Proof judgement ADT, sugars and printer
...@@ -180,6 +180,17 @@ object Printer { ...@@ -180,6 +180,17 @@ object Printer {
Seq(prettyFormulas(sequent.left), "⊢", prettyFormulas(sequent.right)).filter(_.nonEmpty).mkString(spaceSeparator(compact)) Seq(prettyFormulas(sequent.left), "⊢", prettyFormulas(sequent.right)).filter(_.nonEmpty).mkString(spaceSeparator(compact))
} }
/**
* Returns a string representation of the line number in a proof.
* Example output:
* <pre>
* 0:2:1
* </pre>
* @param line the line number
* @return the string representation of this line number
*/
def prettyLineNumber(line: Seq[Int]): String = line.mkString(":")
/** /**
* Returns a string representation of this proof. * Returns a string representation of this proof.
* @param proof the proof * @param proof the proof
...@@ -187,14 +198,13 @@ object Printer { ...@@ -187,14 +198,13 @@ object Printer {
* (`->`) as an error. The proof is considered to be valid by default * (`->`) as an error. The proof is considered to be valid by default
* @return a string where each indented line corresponds to a step in the proof * @return a string where each indented line corresponds to a step in the proof
*/ */
def prettySCProof(proof: SCProof, judgement: SCProofCheckerJudgement = SCValidProof): String = { def prettySCProof(proof: SCProof, judgement: SCProofCheckerJudgement = SCValidProof, forceDisplaySubproofs: Boolean = false): String = {
def computeMaxNumbering(proof: SCProof, level: Int, result: IndexedSeq[Int]): IndexedSeq[Int] = { def computeMaxNumberingLengths(proof: SCProof, level: Int, result: IndexedSeq[Int]): IndexedSeq[Int] = {
val resultWithCurrent = result.updated(level, Math.max(proof.steps.size - 1, result(level))) val resultWithCurrent = result.updated(level, (Seq((proof.steps.size - 1).toString.length, result(level)) ++ (if(proof.imports.nonEmpty) Seq((-proof.imports.size).toString.length) else Seq.empty)).max)
proof.steps.collect { case sp: SCSubproof => sp }.foldLeft(resultWithCurrent)((acc, sp) => computeMaxNumbering(sp.sp, level + 1, if(acc.size <= level + 1) acc :+ 0 else acc)) proof.steps.collect { case sp: SCSubproof => sp }.foldLeft(resultWithCurrent)((acc, sp) => computeMaxNumberingLengths(sp.sp, level + 1, if(acc.size <= level + 1) acc :+ 0 else acc))
} }
val maxNumbering = computeMaxNumbering(proof, 0, IndexedSeq(0)) // The maximum value for each number column val maxNumberingLengths = computeMaxNumberingLengths(proof, 0, IndexedSeq(0)) // The maximum value for each number column
val maxNumberingLengths = maxNumbering.map(_.toString.length) val maxLevel = maxNumberingLengths.size - 1
val maxLevel = maxNumbering.size - 1
def leftPadSpaces(v: Any, n: Int): String = { def leftPadSpaces(v: Any, n: Int): String = {
val s = String.valueOf(v) val s = String.valueOf(v)
...@@ -239,7 +249,8 @@ object Printer { ...@@ -239,7 +249,8 @@ object Printer {
prettySequent(step.bot) prettySequent(step.bot)
) )
step match { step match {
case sp @ SCSubproof(_, _, true) => pretty("Subproof", sp.premises*) +: prettySCProofRecursive(sp.sp, level + 1, currentTree, (if(i == 0) topMostIndices else IndexedSeq.empty) :+ i) case sp @ SCSubproof(_, _, display) if display || forceDisplaySubproofs =>
pretty("Subproof", sp.premises*) +: prettySCProofRecursive(sp.sp, level + 1, currentTree, (if(i == 0) topMostIndices else IndexedSeq.empty) :+ i)
case other => case other =>
val line = other match { val line = other match {
case Rewrite(_, t1) => pretty("Rewrite", t1) case Rewrite(_, t1) => pretty("Rewrite", t1)
...@@ -268,7 +279,7 @@ object Printer { ...@@ -268,7 +279,7 @@ object Printer {
case RightSubstIff(_, t1, _, _, _, _) => pretty("R. SubstIff", t1) case RightSubstIff(_, t1, _, _, _, _) => pretty("R. SubstIff", t1)
case InstFunSchema(_, t1, _, _, _) => pretty("?Fun Instantiation", t1) case InstFunSchema(_, t1, _, _, _) => pretty("?Fun Instantiation", t1)
case InstPredSchema(_, t1, _, _, _) => pretty("?Pred Instantiation", t1) case InstPredSchema(_, t1, _, _, _) => pretty("?Pred Instantiation", t1)
case SCSubproof(_, _, false) => pretty("SCSubproof (hidden)") case SCSubproof(_, _, false) => pretty("Subproof (hidden)")
case other => throw new Exception(s"No available method to print this proof step, consider updating Printer.scala\n$other") case other => throw new Exception(s"No available method to print this proof step, consider updating Printer.scala\n$other")
} }
Seq(line) Seq(line)
...@@ -288,7 +299,7 @@ object Printer { ...@@ -288,7 +299,7 @@ object Printer {
full.mkString(" ") full.mkString(" ")
}.mkString("\n") + (judgement match { }.mkString("\n") + (judgement match {
case SCValidProof => "" case SCValidProof => ""
case SCInvalidProof(path, message) => s"\nProof checker has reported error at line ${path.mkString(".")}: $message" case SCInvalidProof(path, message) => s"\nProof checker has reported an error at line ${path.mkString(".")}: $message"
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment