From 2387461e21a01d4fe64901012a837e79d3bffa68 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Mon, 25 Mar 2024 15:59:09 +0100 Subject: [PATCH] feat(lexer): match backticks --- src/lexer/lexer.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 92046ac..c737e2c 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -138,7 +138,7 @@ void mrk_lexer_emit(mrk_token *out, mrk_lexer *lexer, mrk_token_type type) { } void mrk_lexer_advance_text(mrk_lexer *lexer) { - const char *special_chars = "*\n[]()\\"; + const char *special_chars = "*\n[]()\\`"; while (!mrk_lexer_done(lexer)) { if (strchr(special_chars, mrk_lexer_peek(lexer)) == NULL) { @@ -281,6 +281,15 @@ void mrk_lexer_lex_start_of_line(mrk_token *out, mrk_lexer *lexer) { case '\t': mrk_lexer_emit(out, lexer, mrk_token_type_indent); break; + case '`': + if (mrk_lexer_peek_str(lexer, "``")) { + mrk_lexer_advance_n(lexer, 2); + mrk_lexer_emit(out, lexer, mrk_token_type_triple_backtick); + } else { + mrk_lexer_advance(lexer); + mrk_lexer_emit(out, lexer, mrk_token_type_backtick); + } + break; default: { // Match ordered list headers if (isdigit(c)) { @@ -363,6 +372,10 @@ void mrk_lexer_lex_middle_of_line(mrk_token *out, mrk_lexer *lexer) { mrk_lexer_emit(out, lexer, mrk_token_type_text); } } break; + case '`': + mrk_lexer_advance(lexer); + mrk_lexer_emit(out, lexer, mrk_token_type_backtick); + break; default: mrk_lexer_advance_text(lexer); mrk_lexer_emit(out, lexer, mrk_token_type_text);