feat(lexer): implementing assignements
This commit is contained in:
parent
e1291107d4
commit
f0a7173b11
3 changed files with 41 additions and 6 deletions
|
|
@ -78,6 +78,21 @@ static bool update_lexing_mode(char *stream, ssize_t i,
|
|||
return *lexing_mode != mode_before_update;
|
||||
}
|
||||
|
||||
/* @brief: updates the flags only_digits and equal_count
|
||||
* according to the character at stream[i].
|
||||
*/
|
||||
static void update_flags(char *stream, ssize_t i, struct lexer_context *ctx)
|
||||
{
|
||||
if (stream[i] == '=')
|
||||
{
|
||||
ctx->equal_count++;
|
||||
}
|
||||
else if (!isdigit(stream[i]) && ctx->only_digits)
|
||||
{
|
||||
ctx->only_digits = false;
|
||||
}
|
||||
}
|
||||
|
||||
struct token *peek_token(struct lexer_context *ctx)
|
||||
{
|
||||
// we already created the upcoming token during the previous call to peek()
|
||||
|
|
@ -100,6 +115,7 @@ struct token *peek_token(struct lexer_context *ctx)
|
|||
if (!update_lexing_mode(stream, i, &lexing_mode)
|
||||
&& lexing_mode == LEXER_NORMAL)
|
||||
{
|
||||
update_flags(stream, i, ctx);
|
||||
if (is_special_char(stream, i))
|
||||
{
|
||||
if (i == 0) // where we create spe_char token
|
||||
|
|
@ -121,7 +137,7 @@ struct token *peek_token(struct lexer_context *ctx)
|
|||
i++;
|
||||
}
|
||||
|
||||
struct token *tok = new_token(stream, i, ctx->only_digits);
|
||||
struct token *tok = new_token(stream, i, ctx->only_digits, ctx->equal_count);
|
||||
// if token is comment, we don't want it
|
||||
|
||||
if (tok->type == TOKEN_COMMENT)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue