]> git.corax.cc Git - ccc/commitdiff
tokenize: Add token_new_from_char() helper function
authorMatthias Kruk <m@m10k.eu>
Sat, 30 May 2020 09:23:14 +0000 (18:23 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 30 May 2020 09:23:14 +0000 (18:23 +0900)
src/token.c
src/token.h

index cafc7ac1d82a7ef038ff5956c47f4ef4b9d5fcec..c1a515d2a99e5bcae176511d9c3eb73b747f5470 100644 (file)
@@ -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);
index a6cc972be452f12699ae35d51254e6c08ab57fbf..afd6a891d458821a104470762521d0e31ac9b586 100644 (file)
@@ -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*);