More print improvements.
This commit is contained in:
52
AST.jai
52
AST.jai
@@ -105,6 +105,7 @@ pretty_print_fieldlist :: (node : *AST_Node, indentation : int, builder : *Strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
pretty_print_field :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
pretty_print_field :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
||||||
|
indent(builder, indentation);
|
||||||
print_to_builder(builder, tprint("(:= %", node.name));
|
print_to_builder(builder, tprint("(:= %", node.name));
|
||||||
|
|
||||||
if node.kind != .Unnamed_Field && node.token.ident_value.count > 0 {
|
if node.kind != .Unnamed_Field && node.token.ident_value.count > 0 {
|
||||||
@@ -127,7 +128,7 @@ pretty_print_field :: (node : *AST_Node, indentation : int, builder : *String_Bu
|
|||||||
|
|
||||||
if !node.array_field && node.children.count > 0 {
|
if !node.array_field && node.children.count > 0 {
|
||||||
append(builder, " ");
|
append(builder, " ");
|
||||||
pretty_print_children(node, indentation, builder);
|
pretty_print_node(node.children[0], indentation, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
append(builder, ")");
|
append(builder, ")");
|
||||||
@@ -139,6 +140,15 @@ Children_Print_Flags :: enum_flags {
|
|||||||
Space :: 1 << 2;
|
Space :: 1 << 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pretty_print_block :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
||||||
|
for child : node.children {
|
||||||
|
pretty_print_node(child, indentation, builder);
|
||||||
|
if it_index != node.children.count - 1 {
|
||||||
|
append(builder, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *String_Builder, flags : Children_Print_Flags = .Separator) {
|
pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *String_Builder, flags : Children_Print_Flags = .Separator) {
|
||||||
if !parent {
|
if !parent {
|
||||||
return;
|
return;
|
||||||
@@ -152,7 +162,8 @@ pretty_print_children :: (parent : *AST_Node, indentation : int, builder : *Stri
|
|||||||
|
|
||||||
if !child continue;
|
if !child continue;
|
||||||
|
|
||||||
pretty_print_node(child, indentation, builder);
|
ind := ifx it_index > 0 indentation else 0;
|
||||||
|
pretty_print_node(child, ind, builder);
|
||||||
|
|
||||||
if it_index != children.count - 1 {
|
if it_index != children.count - 1 {
|
||||||
if flags & .Separator {
|
if flags & .Separator {
|
||||||
@@ -208,7 +219,9 @@ pretty_print_binary :: (node : *AST_Node, indentation : int, builder : *String_B
|
|||||||
print_to_builder(builder, op_to_string(op));
|
print_to_builder(builder, op_to_string(op));
|
||||||
append(builder, " ");
|
append(builder, " ");
|
||||||
|
|
||||||
pretty_print_children(node, 0, builder, flags = 0);
|
pretty_print_node(node.children[0], 0, builder);
|
||||||
|
append(builder, " ");
|
||||||
|
pretty_print_node(node.children[1], 0, builder);
|
||||||
append(builder, ")");
|
append(builder, ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,14 +230,14 @@ pretty_print_unary :: (node : *AST_Node, indentation : int, builder : *String_Bu
|
|||||||
op := node.token;
|
op := node.token;
|
||||||
|
|
||||||
print_to_builder(builder, op_to_string(op));
|
print_to_builder(builder, op_to_string(op));
|
||||||
pretty_print_children(node, 0, builder, flags = 0);
|
pretty_print_node(node.children[0], 0, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
print_return_node :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
print_return_node :: (node : *AST_Node, indentation : int, builder : *String_Builder) {
|
||||||
indent(builder, indentation);
|
indent(builder, indentation);
|
||||||
append(builder, "(return ");
|
append(builder, "(return ");
|
||||||
|
|
||||||
pretty_print_children(node, 0, builder);
|
pretty_print_children(node, indentation, builder);
|
||||||
|
|
||||||
append(builder, ")");
|
append(builder, ")");
|
||||||
}
|
}
|
||||||
@@ -238,11 +251,11 @@ pretty_print_if :: (node : *AST_Node, indentation : int, builder : *String_Build
|
|||||||
append(builder, "\n");
|
append(builder, "\n");
|
||||||
|
|
||||||
body := node.children[1];
|
body := node.children[1];
|
||||||
pretty_print_node(body, indentation + 1, builder);
|
pretty_print_node(body, indentation, builder);
|
||||||
|
|
||||||
if node.children.count == 3 {
|
if node.children.count == 3 {
|
||||||
append(builder, "\n");
|
append(builder, "\n");
|
||||||
pretty_print_node(node.children[2], indentation + 1, builder);
|
pretty_print_node(node.children[2], indentation, builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
append(builder, ")");
|
append(builder, ")");
|
||||||
@@ -252,7 +265,7 @@ print_expression_statement :: (node : *AST_Node, indentation : int, builder : *S
|
|||||||
indent(builder, indentation);
|
indent(builder, indentation);
|
||||||
|
|
||||||
if node.children[0] {
|
if node.children[0] {
|
||||||
pretty_print_node(node.children[0], indentation, builder);
|
pretty_print_node(node.children[0], 0, builder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,7 +275,7 @@ pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Bui
|
|||||||
print_return_node(node, indentation, builder);
|
print_return_node(node, indentation, builder);
|
||||||
}
|
}
|
||||||
case .If; {
|
case .If; {
|
||||||
pretty_print_if(node, indentation + 2, builder);
|
pretty_print_if(node, indentation + 4, builder);
|
||||||
}
|
}
|
||||||
case .Struct;
|
case .Struct;
|
||||||
case .ArgList; {
|
case .ArgList; {
|
||||||
@@ -278,7 +291,7 @@ pretty_print_node :: (node : *AST_Node, indentation : int, builder : *String_Bui
|
|||||||
pretty_print_field(node, indentation, builder);
|
pretty_print_field(node, indentation, builder);
|
||||||
}
|
}
|
||||||
case .Block; {
|
case .Block; {
|
||||||
pretty_print_children(node, indentation + 2, builder, flags = .NewLine);
|
pretty_print_block(node, indentation, builder);
|
||||||
}
|
}
|
||||||
case .Binary; {
|
case .Binary; {
|
||||||
pretty_print_binary(node, indentation, builder);
|
pretty_print_binary(node, indentation, builder);
|
||||||
@@ -369,12 +382,27 @@ pretty_print_declaration :: (declaration : *AST_Node, indentation : int, builder
|
|||||||
print_to_builder(builder, " (@%)", hint.string_value);
|
print_to_builder(builder, " (@%)", hint.string_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if declaration.children.count > 0 {
|
if declaration.children.count > 0 {
|
||||||
print_to_builder(builder, "\n");
|
print_to_builder(builder, "\n");
|
||||||
pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine);
|
if declaration.kind == .Function {
|
||||||
|
field_list := declaration.children[0];
|
||||||
|
pretty_print_fieldlist(field_list, indentation + 1, builder);
|
||||||
|
append(builder, "\n");
|
||||||
|
|
||||||
|
if declaration.children.count > 1 {
|
||||||
|
body := declaration.children[1];
|
||||||
|
pretty_print_node(body, indentation + 1, builder);
|
||||||
|
}
|
||||||
|
} else if declaration.kind == .Struct {
|
||||||
|
pretty_print_node(declaration.children[0], indentation + 1, builder);
|
||||||
|
} else {
|
||||||
|
pretty_print_node(declaration.children[0], indentation + 1, builder);
|
||||||
|
}
|
||||||
|
|
||||||
|
// print_to_builder(builder, "\n");
|
||||||
|
// pretty_print_children(declaration, indentation + 1, builder, flags = .NewLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
append(builder, ")");
|
append(builder, ")");
|
||||||
|
|||||||
10
Parsing.jai
10
Parsing.jai
@@ -188,17 +188,19 @@ unexpected_token :: (state : *Parse_State, token : Token, message : string) {
|
|||||||
builder : String_Builder;
|
builder : String_Builder;
|
||||||
init_string_builder(*builder,, temp);
|
init_string_builder(*builder,, temp);
|
||||||
|
|
||||||
print_to_builder(*builder, "%\n", message);
|
print_to_builder(*builder, "%\n\n", message);
|
||||||
|
|
||||||
location : Source_Range;
|
location : Source_Range;
|
||||||
location.begin = token;
|
location.begin = token;
|
||||||
location.begin.source = location.begin.source - location.begin.column;
|
location.begin.index -= location.begin.column;
|
||||||
|
location.begin.source -= location.begin.column;
|
||||||
|
location.begin.length += location.begin.column;
|
||||||
location.begin.column = 0;
|
location.begin.column = 0;
|
||||||
|
|
||||||
location.main_token = token;
|
location.main_token = token;
|
||||||
|
location.end = token;
|
||||||
|
|
||||||
advance(state);
|
// advance(state);
|
||||||
location.end = state.current;
|
|
||||||
|
|
||||||
indent(*builder, 1);
|
indent(*builder, 1);
|
||||||
cyan(*builder);
|
cyan(*builder);
|
||||||
|
|||||||
Reference in New Issue
Block a user