commit 6487efc23af50dde9cbb51d68b47d5bda35d825e
parent 432f9068d89aac5deba79d82a90c767064911ddb
Author: erai <erai@omiltem.net>
Date: Sun, 15 Sep 2024 19:30:50 -0400
canonical node output
Diffstat:
M | node.c | | | 25 | ++++++++++++++++++++++++- |
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/node.c b/node.c
@@ -183,15 +183,38 @@ node_to_str(kind: int): *byte {
}
show_node(n: *node) {
+ var i: int;
+ var ch: int;
+ var hex: *byte;
+ hex = "0123456789abcdef";
if !n {
return;
}
fdputc(2, '(');
fdputs(2, node_to_str(n.kind));
+ if n.kind == N_NUM {
+ fdputc(2, ' ');
+ fdputd(2, n.n);
+ }
if n.s {
fdputc(2, ' ');
fdputc(2, '"');
- fdputs(2, n.s);
+ i = 0;
+ loop {
+ ch = n.s[i]:int;
+ if !ch {
+ break;
+ }
+ if ch < 32 || ch > 127 || ch == '\\' || ch == '"' {
+ fdputc(2, '\\');
+ fdputc(2, 'x');
+ fdputc(2, hex[ch >> 4]:int);
+ fdputc(2, hex[ch & 15]:int);
+ } else {
+ fdputc(2, ch);
+ }
+ i = i + 1;
+ }
fdputc(2, '"');
}
if n.a {