From: Matthias Kruk Date: Sat, 30 May 2020 09:23:14 +0000 (+0900) Subject: tokenize: Add token_new_from_char() helper function X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=235f52b3ab72c5184fe29454682ea9b53b674c79;p=ccc tokenize: Add token_new_from_char() helper function --- 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*);