Skip to content

Commit

Permalink
Add an option to dump the tokens from the tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mingodad committed Feb 21, 2024
1 parent e64ae41 commit 036ebce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ struct options
*/
bool visual_studio_ouput_format;

/*
-dump-tokens
*/
bool dump_tokens;

/*
-o filename
defines the ouputfile when 1 file is used
Expand Down Expand Up @@ -9826,6 +9831,12 @@ int fill_options(struct options* options,
continue;
}

if (strcmp(argv[i], "-dump-tokens") == 0)
{
options->dump_tokens = true;
continue;
}

printf("unknown option '%s'", argv[i]);
return 1;
}
Expand Down Expand Up @@ -28226,6 +28237,11 @@ int compile_one_file(const char* file_name,

tokens = tokenizer(&tctx, content, file_name, 0, TK_FLAG_NONE);

if (options->dump_tokens)
{
print_tokens(tokens.head);
}

ast.token_list = preprocessor(&prectx, &tokens, 0);
if (prectx.n_errors > 0) throw;

Expand Down Expand Up @@ -28435,7 +28451,7 @@ int compile(int argc, const char** argv, struct report* report)
if (argv[i][0] == '-')
continue;
no_files++;
char output_file[400] = { 0 };
char output_file[MYMAX_PATH] = { 0 };

if (!options.no_output)
{
Expand Down
6 changes: 6 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ int fill_options(struct options* options,
continue;
}

if (strcmp(argv[i], "-dump-tokens") == 0)
{
options->dump_tokens = true;
continue;
}

printf("unknown option '%s'", argv[i]);
return 1;
}
Expand Down
5 changes: 5 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ struct options
*/
bool visual_studio_ouput_format;

/*
-dump-tokens
*/
bool dump_tokens;

/*
-o filename
defines the ouputfile when 1 file is used
Expand Down
7 changes: 6 additions & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -6734,6 +6734,11 @@ int compile_one_file(const char* file_name,

tokens = tokenizer(&tctx, content, file_name, 0, TK_FLAG_NONE);

if (options->dump_tokens)
{
print_tokens(tokens.head);
}

ast.token_list = preprocessor(&prectx, &tokens, 0);
if (prectx.n_errors > 0) throw;

Expand Down Expand Up @@ -6943,7 +6948,7 @@ int compile(int argc, const char** argv, struct report* report)
if (argv[i][0] == '-')
continue;
no_files++;
char output_file[400] = { 0 };
char output_file[MYMAX_PATH] = { 0 };

if (!options.no_output)
{
Expand Down

1 comment on commit 036ebce

@thradams
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update print_help() function
and
manual.md

(build generates the manual.html automatically)

Please sign in to comment.