feat(lexer): match backticks

main
Jef Roosens 2024-03-25 15:59:09 +01:00
parent 7227e953ae
commit 2387461e21
Signed by: Jef Roosens
GPG Key ID: 02D4C0997E74717B
1 changed files with 14 additions and 1 deletions

View File

@ -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);