Skip to content

Commit

Permalink
Merge pull request #110 from ChAoSUnItY/front-end-separate
Browse files Browse the repository at this point in the history
Implement parser for `#include` preprocessor directive
  • Loading branch information
jserv authored Feb 23, 2024
2 parents f1d9374 + 001ab29 commit 23701e3
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ int get_size(var_t *var, type_t *type)
return type->size;
}

/* abort when invalidate is true and the line contains character other than
* whitespace */
void skip_line(int invalidate)
{
/* FIXME: Comments will causes current validation failed. */
skip_whitespace();
do {
if (invalidate && !is_whitespace(peek_char(0)) &&
!is_newline(peek_char(0))) {
error("Expects whitespace after preprocessor directive");
}
} while (read_char(0) != '\n');
}

/* Skips lines where preprocessor match is false, this will stop once next
* token is either `T_cppd_elif`, `T_cppd_else` or `cppd_endif`.
*/
Expand Down Expand Up @@ -114,10 +100,23 @@ int read_preproc_directive()
char token[MAX_ID_LEN];

if (lex_peek(T_cppd_include, token)) {
skip_line(0); /* FIXME: remove this line after syntax parsing is
implemented */
lex_expect(T_cppd_include);
/* TODO: parse include syntax here */

/* Basic #define syntax validation */
if (lex_peek(T_string, NULL)) {
/* #define "header.h" */
lex_expect(T_string);
} else {
/* #define <stdlib.h> */
lex_expect(T_lt);

while (!lex_peek(T_gt, NULL)) {
next_token = lex_token();
}

lex_expect(T_gt);
}

return 1;
}
if (lex_accept(T_cppd_define)) {
Expand Down

0 comments on commit 23701e3

Please sign in to comment.