Skip to content

Commit

Permalink
Add element tree to compileFile
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhbd committed Aug 4, 2023
1 parent ecdd7d9 commit 4a7c74d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ fun compileFile(text: String, fileName: String = "temp.s", predefined: List<Pred
val environment = TestHeadlessParser.build(
root = directory.path,
annotator = { element, message ->
throw AssertionError("at ${element.textOffset} : $message")
val tree = buildString {
element.containingFile.printTree {
append(" ")
append(it)
}
}
throw AssertionError("at ${element.textOffset} : $message\n${tree}")
},
predefinedTables = predefined,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ abstract class FixturesTest(
newRoot.deleteRecursively()
}

private fun PsiElement.printTree(printer: (String) -> Unit) {
printer("$this\n")
children.forEach { child ->
child.printTree { printer(" $it") }
}
}

private fun File.replaceKeywords() {
if (isDirectory) {
listFiles()?.forEach { it.replaceKeywords() }
Expand Down Expand Up @@ -171,3 +164,10 @@ private fun formatErrorList(errors: List<String>): String {
private val inlineErrorRegex = "^--\\s*error\\[col (\\d+)]:(.+)$".toRegex(RegexOption.MULTILINE)

private fun String.splitLines() = split("\\r?\\n".toRegex())

internal fun PsiElement.printTree(printer: (String) -> Unit) {
printer("$this\n")
children.forEach { child ->
child.printTree { printer(" $it") }
}
}

0 comments on commit 4a7c74d

Please sign in to comment.