Added broken check for bool if cond. Also added some wonky if/else pretty printing for AST.
This commit is contained in:
29
AST.jai
29
AST.jai
@@ -146,12 +146,13 @@ pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *Stri
|
||||
|
||||
children := parent.children;
|
||||
for child : children {
|
||||
if it_index > 0 {
|
||||
indent(builder, indentation);
|
||||
}
|
||||
// if it_index > 0 {
|
||||
// indent(builder, indentation);
|
||||
// }
|
||||
|
||||
if !child continue;
|
||||
pretty_print_node(child, 0, builder);
|
||||
|
||||
pretty_print_node(child, indentation, builder);
|
||||
|
||||
if it_index != children.count - 1 {
|
||||
if flags & .Separator {
|
||||
@@ -220,6 +221,7 @@ pretty_print_unary :: (node : *AST_Node, indentation : int, builder : *String_Bu
|
||||
}
|
||||
|
||||
print_return_node :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
||||
indent(builder, indentation);
|
||||
append(builder, "(return ");
|
||||
|
||||
pretty_print_children(node, 0, builder);
|
||||
@@ -228,18 +230,19 @@ print_return_node :: (node : *AST_Node, indentation : int, builder : *String_Bui
|
||||
}
|
||||
|
||||
pretty_print_if :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
||||
indent(builder, indentation);
|
||||
indent(builder, indentation);
|
||||
append(builder, "(if ");
|
||||
|
||||
body := node.children[0];
|
||||
pretty_print_node(body, 0, builder);
|
||||
condition := node.children[0];
|
||||
pretty_print_node(condition, 0, builder);
|
||||
append(builder, "\n");
|
||||
|
||||
if node.children.count == 2 {
|
||||
body := node.children[1];
|
||||
pretty_print_node(body, indentation + 1, builder);
|
||||
|
||||
if node.children.count == 3 {
|
||||
append(builder, "\n");
|
||||
indent(builder, indentation);
|
||||
append(builder, "(else ");
|
||||
pretty_print_node(node.children[1], 0, builder);
|
||||
append(builder, ")");
|
||||
pretty_print_node(node.children[2], indentation + 1, builder);
|
||||
}
|
||||
|
||||
append(builder, ")");
|
||||
@@ -259,7 +262,7 @@ pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Bui
|
||||
print_return_node(node, indentation, builder);
|
||||
}
|
||||
case .If; {
|
||||
pretty_print_if(node, indentation, builder);
|
||||
pretty_print_if(node, indentation + 2, builder);
|
||||
}
|
||||
case .Struct;
|
||||
case .ArgList; {
|
||||
|
||||
Reference in New Issue
Block a user