mirror of
https://github.com/irmen/prog8.git
synced 2025-08-16 05:27:31 +00:00
* fix AstToSourceCode: missing semicolon in header and footer, missing "@" for strings with altEncoding
This commit is contained in:
@@ -9,6 +9,11 @@ import prog8.ast.statements.*
|
|||||||
import prog8.ast.walk.IAstVisitor
|
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.SourceCode]
|
||||||
|
*/
|
||||||
class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): IAstVisitor {
|
class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): IAstVisitor {
|
||||||
private var scopelevel = 0
|
private var scopelevel = 0
|
||||||
|
|
||||||
@@ -18,9 +23,9 @@ class AstToSourceCode(val output: (text: String) -> Unit, val program: Program):
|
|||||||
private fun outputi(s: Any) = output(indent(s.toString()))
|
private fun outputi(s: Any) = output(indent(s.toString()))
|
||||||
|
|
||||||
override fun visit(program: Program) {
|
override fun visit(program: Program) {
|
||||||
outputln("============= PROGRAM ${program.name} (FROM AST) ===============")
|
outputln("; ============ PROGRAM ${program.name} (FROM AST) ==============")
|
||||||
super.visit(program)
|
super.visit(program)
|
||||||
outputln("============= END PROGRAM ${program.name} (FROM AST) ===========")
|
outputln("; =========== END PROGRAM ${program.name} (FROM AST) ===========")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(module: Module) {
|
override fun visit(module: Module) {
|
||||||
@@ -262,6 +267,8 @@ class AstToSourceCode(val output: (text: String) -> Unit, val program: Program):
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visit(string: StringLiteralValue) {
|
override fun visit(string: StringLiteralValue) {
|
||||||
|
if (string.altEncoding)
|
||||||
|
output("@")
|
||||||
output("\"${escape(string.value)}\"")
|
output("\"${escape(string.value)}\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user