Use heuristics to detect whether a block contains a tree
This commit is contained in:
parent
5f510bb9b9
commit
fac0f3605d
3 changed files with 12 additions and 4 deletions
|
|
@ -12,16 +12,21 @@ val lineRe = "^\\s*§(?<block>.*)$".r
|
|||
|
||||
class Conf(args: Seq[String]) extends ScallopConf(args):
|
||||
val path: ScallopOption[Path] = trailArg[Path]()
|
||||
val indent: ScallopOption[Int] = opt[Int](default = Some(2))
|
||||
val blockRegex: ScallopOption[String] = opt[String](default = Some(blockRe.regex))
|
||||
val lineRegex: ScallopOption[String] = opt[String](default = Some(lineRe.regex))
|
||||
val indent: ScallopOption[Int] = opt[Int](default = Some(2))
|
||||
val noHeuristics: ScallopOption[Boolean] = opt[Boolean]()
|
||||
verify()
|
||||
|
||||
@main
|
||||
def main(args: String*): Unit =
|
||||
val conf = new Conf(args)
|
||||
val formatter =
|
||||
Formatter(indent = conf.indent(), blockRe = Regex(conf.blockRegex()), lineRe = Regex(conf.lineRegex()))
|
||||
val formatter = Formatter(
|
||||
blockRe = Regex(conf.blockRegex()),
|
||||
lineRe = Regex(conf.lineRegex()),
|
||||
indent = conf.indent(),
|
||||
heuristics = !conf.noHeuristics(),
|
||||
)
|
||||
reformat(conf.path(), formatter)
|
||||
|
||||
def reformat(path: Path, formatter: Formatter): Unit =
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import scala.util.boundary
|
|||
import scala.util.matching.Regex
|
||||
import scala.util.matching.Regex.Match
|
||||
|
||||
case class Formatter(indent: Int, blockRe: Regex, lineRe: Regex):
|
||||
case class Formatter(blockRe: Regex, lineRe: Regex, indent: Int, heuristics: Boolean):
|
||||
private val blockReI = blockRe.pattern.namedGroups().get("block")
|
||||
private val lineReI = lineRe.pattern.namedGroups().get("block")
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ case class Formatter(indent: Int, blockRe: Regex, lineRe: Regex):
|
|||
private def parseBlock(text: String, m: Match): Option[BlockInfo] = boundary:
|
||||
val block = parseBlockLines(m.group(blockReI)).getOrElse(boundary.break(None))
|
||||
val tree = Parser(block.content).parse.getOrElse(boundary.break(None))
|
||||
if heuristics && tree.containsNoLines then return None
|
||||
Some(BlockInfo(
|
||||
block = block,
|
||||
tree = tree,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ case class ProofTree(premises: Seq[ProofTree] = Seq(), line: Option[String] = No
|
|||
|
||||
combined.copy(conclusionStart = belowCentered.start, conclusionEnd = belowCentered.end)
|
||||
|
||||
def containsNoLines: Boolean = line.isEmpty && premises.forall(_.containsNoLines)
|
||||
|
||||
object ProofTree:
|
||||
def empty: ProofTree = ProofTree()
|
||||
def star: ProofTree = ProofTree().addConclusion("*")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue