diff --git a/frontend/cmd/compile.c b/frontend/cmd/compile.c index d6d33d7..16ddb49 100644 --- a/frontend/cmd/compile.c +++ b/frontend/cmd/compile.c @@ -11,15 +11,14 @@ enum { ARG_SOURCE_FILE = 200, - OPT_LEX_ONLY, - OPT_VERBOSE, + OPT_SHOW_LEX_TOKENS, + OPT_SHOW_AST_NODES, }; static int compile_file(const char *path, const b_arglist *args) { - bool lex_only - = b_arglist_get_count(args, OPT_LEX_ONLY, B_COMMAND_INVALID_ID) > 0; - int verbose = b_arglist_get_count(args, OPT_VERBOSE, B_COMMAND_INVALID_ID); + bool show_lex = b_arglist_get_count(args, OPT_SHOW_LEX_TOKENS, B_COMMAND_INVALID_ID) > 0; + bool show_ast = b_arglist_get_count(args, OPT_SHOW_AST_NODES, B_COMMAND_INVALID_ID) > 0; FILE *fp = fopen(path, "r"); if (!fp) { @@ -63,15 +62,10 @@ static int compile_file(const char *path, const b_arglist *args) break; } - if (verbose >= 2) { + if (show_lex) { print_lex_token(tok); } - if (lex_only) { - ivy_token_destroy(tok); - continue; - } - status = ivy_parser_push_token(parser, tok); if (status != IVY_OK) { @@ -86,11 +80,10 @@ static int compile_file(const char *path, const b_arglist *args) int r = (status == IVY_OK || status == IVY_ERR_EOF) ? 0 : -1; ivy_file_close(src); - if (!lex_only && r == 0 && verbose >= 1) { + if (r == 0 && show_ast) { struct ivy_ast_node *root = ivy_parser_root_node(parser); struct ivy_ast_node_iterator it = {0}; ivy_ast_node_iterate(root, &it, print_ast_node); - // ivy_ast_node_print(root); } if (lex) { @@ -133,22 +126,22 @@ B_COMMAND(CMD_COMPILE, CMD_ROOT) B_COMMAND_FLAGS(B_COMMAND_SHOW_HELP_BY_DEFAULT); B_COMMAND_FUNCTION(compile); - B_COMMAND_OPTION(OPT_LEX_ONLY) + B_COMMAND_OPTION(OPT_SHOW_LEX_TOKENS) { - B_OPTION_LONG_NAME("lex-only"); - B_OPTION_SHORT_NAME('L'); + B_OPTION_LONG_NAME("show-lex"); + B_OPTION_SHORT_NAME('l'); B_OPTION_DESC( "print the lexical tokens generated from the input " "files."); } - B_COMMAND_OPTION(OPT_VERBOSE) + B_COMMAND_OPTION(OPT_SHOW_AST_NODES) { - B_OPTION_LONG_NAME("verbose"); - B_OPTION_SHORT_NAME('v'); + B_OPTION_LONG_NAME("show-ast"); + B_OPTION_SHORT_NAME('a'); B_OPTION_DESC( - "print detailed log output. this option can be used " - "multiple times to increase verbosity."); + "print the abstract syntax tree generated from the " + "input files."); } B_COMMAND_ARG(ARG_SOURCE_FILE)