mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
better name
This commit is contained in:
parent
ce75b776bb
commit
2c940de598
@ -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()
|
||||
}
|
||||
|
@ -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
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user