better name

This commit is contained in:
Irmen de Jong 2021-10-29 01:06:01 +02:00
parent ce75b776bb
commit 2c940de598
3 changed files with 6 additions and 7 deletions

View File

@ -1,7 +1,7 @@
package prog8.compiler
import com.github.michaelbull.result.*
import prog8.ast.AstToSourceCode
import prog8.ast.AstToSourceTextConverter
import prog8.ast.IBuiltinFunctions
import prog8.ast.IMemSizer
import prog8.ast.Program
@ -378,7 +378,7 @@ private fun writeAssembly(programAst: Program,
fun printAst(programAst: Program) {
println()
val printer = AstToSourceCode(::print, programAst)
val printer = AstToSourceTextConverter(::print, programAst)
printer.visit(programAst)
println()
}

View File

@ -12,9 +12,8 @@ import prog8.ast.walk.IAstVisitor
/**
* Produces Prog8 source text from a [Program] (AST node),
* passing it as a String to the specified receiver function.
* TODO: rename/refactor to make proper sense in the presence of class [prog8.parser.SourceCode]
*/
class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): IAstVisitor {
class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: Program): IAstVisitor {
private var scopelevel = 0
private fun indent(s: String) = " ".repeat(scopelevel) + s

View File

@ -2,7 +2,7 @@ package prog8tests
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import prog8.ast.AstToSourceCode
import prog8.ast.AstToSourceTextConverter
import prog8.ast.Module
import prog8.ast.Program
import prog8.ast.internedStringsModuleName
@ -15,14 +15,14 @@ import kotlin.test.assertContains
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestAstToSourceCode {
class TestAstToSourceText {
private fun generateP8(module: Module) : String {
val program = Program("test", DummyFunctions, DummyMemsizer)
.addModule(module)
var generatedText = ""
val it = AstToSourceCode({ str -> generatedText += str }, program)
val it = AstToSourceTextConverter({ str -> generatedText += str }, program)
it.visit(program)
return generatedText