fix ast printing of arrays with duplicate elements

This commit is contained in:
Irmen de Jong 2024-10-13 04:30:46 +02:00
parent 03412cacba
commit fa5479ee5f
2 changed files with 14 additions and 5 deletions

View File

@ -21,7 +21,16 @@ fun printAst(root: PtNode, skipLibraries: Boolean, output: (text: String) -> Uni
else
"&"
}
is PtArray -> "array len=${node.children.size} ${type(node.type)}"
is PtArray -> {
val valuelist = node.children.map {
when (it) {
is PtNumber -> it.number.toString()
is PtIdentifier -> it.name
else -> "?"
}
}.joinToString(", ")
"array len=${node.children.size} ${type(node.type)} [ $valuelist ]"
}
is PtArrayIndexer -> "<arrayindexer> ${type(node.type)} ${if(node.splitWords) "[splitwords]" else ""}"
is PtBinaryExpression -> "<expr> ${node.operator} ${type(node.type)}"
is PtBuiltinFunctionCall -> {

View File

@ -315,16 +315,16 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program:
}
override fun visit(array: ArrayLiteral) {
outputListMembers(array.value.asSequence())
outputListMembers(array.value)
}
private fun outputListMembers(array: Sequence<Expression>) {
private fun outputListMembers(array: Array<Expression>) {
var counter = 0
output("[")
scopelevel++
for (v in array) {
for ((idx, v) in array.withIndex()) {
v.accept(this)
if (v !== array.last())
if (idx != array.size-1)
output(", ")
counter++
if (counter > 16) {