From dc3cfc5fbe1e102a460f72837d5095f5e783f608 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 4 Mar 2024 19:13:51 +0100 Subject: [PATCH] feat(lexer): parse equal signs --- include/mrk/lexer.h | 1 + src/lexer/lexer.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/mrk/lexer.h b/include/mrk/lexer.h index ae4baa3..d8782fa 100644 --- a/include/mrk/lexer.h +++ b/include/mrk/lexer.h @@ -19,6 +19,7 @@ typedef enum mrk_token_type { mrk_token_type_dashes, mrk_token_type_underscores, mrk_token_type_stars, + mrk_token_type_equals, mrk_token_type_blank_line, mrk_token_type_space, mrk_token_type_line_break, diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 7d56aa9..3dd2463 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -124,7 +124,8 @@ mrk_lexer_err mrk_lexer_next(mrk_token *out, mrk_lexer *lexer) { char c = mrk_lexer_advance(lexer); switch (c) { // All these characters have multiple meanings depending on their location - // in the file and how many there are + // in the file and how many there are, so the lexer can only match them as + // one or more grouped characters case '#': mrk_lexer_advance_eq(lexer, c); mrk_lexer_emit(out, lexer, mrk_token_type_pounds); @@ -145,6 +146,10 @@ mrk_lexer_err mrk_lexer_next(mrk_token *out, mrk_lexer *lexer) { mrk_lexer_advance_eq(lexer, c); mrk_lexer_emit(out, lexer, mrk_token_type_stars); break; + case '=': + mrk_lexer_advance_eq(lexer, c); + mrk_lexer_emit(out, lexer, mrk_token_type_equals); + break; // Two consecutive newlines constitute a blank line, otherwise they're // ignored as whitespace case '\n':