From 235f52b3ab72c5184fe29454682ea9b53b674c79 Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 30 May 2020 18:23:14 +0900 Subject: [PATCH] tokenize: Add token_new_from_char() helper function --- src/token.c | 19 +++++++++++++++++++ src/token.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/token.c b/src/token.c index cafc7ac..c1a515d 100644 --- a/src/token.c +++ b/src/token.c @@ -32,6 +32,25 @@ struct token *token_new2(const int line, const int col, const char *val) return(tok); } +struct token *token_new_from_char(const int line, const int col, const char chr) +{ + struct token *tok; + + tok = token_new(); + + if(tok) { + char val[2]; + + val[0] = chr; + val[1] = 0; + + token_setpos(tok, line, col); + assert(token_setvalue(tok, val) == 0); + } + + return(tok); +} + void token_free(struct token *tok) { free(tok); diff --git a/src/token.h b/src/token.h index a6cc972..afd6a89 100644 --- a/src/token.h +++ b/src/token.h @@ -12,6 +12,7 @@ struct token { struct token *token_new2(const int, const int, const char*); struct token *token_new(void); +struct token *token_new_from_char(const int, const int, const char); void token_free(struct token*); void token_setpos(struct token*, const int, const int); int token_setvalue(struct token*, const char*); -- 2.47.3