blob: 79fee8a2b9d0920c6f8b5325c015c64948736245 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package moe.nea.lisp
sealed class LispAst : HasLispPosition {
abstract fun toSource(): String
data class Program(override val position: LispPosition, val nodes: List<LispNode>) : LispAst() {
override fun toSource(): String {
return nodes.joinToString("\n") {
it.toSource()
}
}
}
sealed class LispNode : LispAst()
data class Atom(override val position: LispPosition, val label: String) : LispNode() {
override fun toSource(): String {
return ":$label"
}
}
data class Reference(override val position: LispPosition, val label: String) : LispNode() {
override fun toSource(): String {
return label
}
}
data class Parenthesis(override val position: LispPosition, val items: List<LispNode>) : LispNode() {
override fun toSource(): String {
return items.joinToString(" ", "(", ")") { it.toSource() }
}
}
data class StringLiteral(override val position: LispPosition, val parsedString: String) : LispNode() {
override fun toSource(): String {
return "\"${parsedString.replace("\\", "\\\\").replace("\"", "\\\"")}\"" // TODO: better escaping
}
}
}
|