From 3d90dbeaa9cf13058ed349ba7beb2532c571c7fb Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Thu, 30 Aug 2018 14:09:56 +0200 Subject: first iteration --- src/tokenize.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/tokenize.c') diff --git a/src/tokenize.c b/src/tokenize.c index 5040a7c..8445a71 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -63,6 +63,22 @@ eat_hex(struct tokenizer *tokenizer) } } +internal void +eat_string(struct tokenizer *tokenizer) +{ + /* + * NOTE(koekeishiya): This is NOT proper string parsing code, as we do + * not check for escaped '"' here. At the time of writing, this is only + * supposed to be used for parsing names of processes, and such names + * should not contain escaped quotes at all. We are lazy and simply do + * the most basic implementation that fulfills our current requirement. + */ + + while (*tokenizer->at && *tokenizer->at != '"') { + advance(tokenizer); + } +} + internal inline bool isidentifier(char c) { @@ -130,6 +146,19 @@ get_token(struct tokenizer *tokenizer) case ',': { token.type = Token_Comma; } break; case '<': { token.type = Token_Insert; } break; case '@': { token.type = Token_Capture; } break; + case '[': { token.type = Token_BeginList; } break; + case ']': { token.type = Token_EndList; } break; + case '"': { + token.text = tokenizer->at; + token.line = tokenizer->line; + token.cursor = tokenizer->cursor; + + eat_string(tokenizer); + token.length = tokenizer->at - token.text; + token.type = Token_String; + + advance(tokenizer); + } break; case '#': { eat_comment(tokenizer); token = get_token(tokenizer); -- cgit v1.2.3