Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
keyvank committed Nov 12, 2024
1 parent 41b0349 commit c1ba1b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ typed_token *next_op(char **inp_ptr, int is_newline)
int skip_whitespaces(char **inp_ptr)
{
char *inp = *inp_ptr;
int is_newline = 1;
int is_newline = *inp == '\n';
while (*inp != 0 && (*inp == ' ' || *inp == '\n' || *inp == '\t'))
{
is_newline = (*inp == '\n');
Expand Down
32 changes: 18 additions & 14 deletions preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ char *get_path(const char *path, const char *ipath)
return realpath;
}

typed_token *chain_tokens(linked_list *tkns)
{
list_node *curr = tkns->first;
typed_token *res_first = (typed_token *)curr->value;
typed_token *curr_tkn = res_first;
while (curr)
{
curr = curr->next;
if (curr)
{
curr_tkn->next = (typed_token *)curr->value;
curr_tkn = curr_tkn->next;
}
}
return res_first;
}

typed_token *preprocess(typed_token *tkns,
const char *path, int depth)
{
Expand Down Expand Up @@ -359,18 +376,5 @@ typed_token *preprocess(typed_token *tkns,
if (filename)
free(filename);

list_node *curr = result->first;
typed_token *res_first = (typed_token *)curr->value;
typed_token *curr_tkn = res_first;
while (curr)
{
curr = curr->next;
if (curr)
{
curr_tkn->next = (typed_token *)curr->value;
curr_tkn = curr_tkn->next;
}
}

return res_first;
return chain_tokens(result);
}

0 comments on commit c1ba1b2

Please sign in to comment.