tweak: print children better in ast

This commit is contained in:
NunoSempere 2023-04-30 10:30:31 -04:00
parent 1a1b5c956a
commit 67992e364c
2 changed files with 17 additions and 3 deletions

BIN
mumble

Binary file not shown.

View File

@ -32,14 +32,27 @@ int main(int argc, char** argv)
if (input == NULL) { if (input == NULL) {
// ^ catches Ctrl+D // ^ catches Ctrl+D
loop = 0; loop = 0;
puts("");
} else { } else {
/* Attempt to Parse the user Input */ /* Attempt to Parse the user Input */
mpc_result_t result; mpc_result_t result;
if (mpc_parse("<stdin>", input, Mumble, &result)) { if (mpc_parse("<stdin>", input, Mumble, &result)) {
/* On Success Print the AST */ /* On Success Print the AST */
mpc_ast_print(result.output); // mpc_ast_print(result.output);
mpc_ast_delete(result.output); /* Load AST from output */
mpc_ast_t* ast = result.output;
char* no_contents = "None";
printf("\n");
printf("Tag: %s\n", ast->tag);
printf("Contents: %s\n", strcmp(ast->contents, "") ? ast->contents : no_contents);
printf("Number of children: %i\n", ast->children_num);
/* Print the children */
for(int i=0; i < ast->children_num; i++){
mpc_ast_t* child_i = ast->children[i];
printf("Child #%d\n", i);
printf("\tTag: %s\n", child_i->tag);
printf("\tContents: %s\n", strcmp(child_i->contents, "") ? child_i->contents : no_contents);
printf("\tNumber of children: %i\n", child_i->children_num);
}
} else { } else {
/* Otherwise Print the Error */ /* Otherwise Print the Error */
mpc_err_print(result.error); mpc_err_print(result.error);
@ -49,6 +62,7 @@ int main(int argc, char** argv)
add_history(input); add_history(input);
// can't add if input is NULL // can't add if input is NULL
} }
puts("");
free(input); free(input);
} }