Skip to content
Snippets Groups Projects
Commit 1f6d48e2 authored by Christian Maeder's avatar Christian Maeder
Browse files

refactored parsing

parent 980e7ecf
No related branches found
No related tags found
No related merge requests found
......@@ -14,29 +14,38 @@ object ParseXML {
val xml = XML.loadFile(f.getPath)
xml \\ "error"
} catch {
case e: SAXParseException => Nil
case e: SAXParseException =>
println(e.getLineNumber + ":" + e.getColumnNumber)
Nil
}
}
def getAttrs(attrs: List[String], x: Node): List[String] = {
attrs map (a => (x \ ("@" + a)).toString())
val as = x.attributes
attrs map (a => as.get(a).getOrElse("").toString)
}
def traverse(dir: File, proc: File => Unit): Unit =
dir.listFiles foreach { f => if (f.isDirectory) traverse(f, proc) else proc(f)}
dir.listFiles map { f => if (f.isDirectory) traverse(f, proc) else proc(f)}
def procFile(f: File): Unit = {
def procFile(proc: (File, Node) => Unit)(f: File): Unit = {
if (f.canRead && f.getPath.endsWith(".err") && f.length() > 0) {
val errs = readXml(f)
if (errs.isEmpty) println("NOERR: " + f)
else errs map (x => {
else errs map (x => procErr(f, x))
}
}
def procErr(f: File, x: Node): Unit = {
println(f)
if ((x.child filter (c => c.isInstanceOf[Elem])).isEmpty) {
getAttrs(List("type", "shortMsg", "level"), x) map println
println(x.text)
}
)
}
def main(args: Array[String]): Unit = {
val dir = new File("/local/maeder/tptp/Distribution/errors")
traverse(dir, procFile)
traverse(dir, procFile(procErr))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment