libmya 0.1.0
Library to parse Mya language.
Loading...
Searching...
No Matches
token.c
Go to the documentation of this file.
1#include <string.h>
2
3#include "dstring.h"
4#include "token.h"
5
6void
7token_init(token_t* token, const char* lexeme, token_type_t type, unsigned int line, unsigned int column)
8{
9 token->type = type;
10 token->line = line;
11 token->column = column;
12 token->value = 0;
13
14 dstring_init(&token->lexeme, 25); // 25 is big enough to fit the major of the tokens.
15 dstring_copy(&token->lexeme, lexeme);
16}
void dstring_init(dstring_t *string, unsigned int buffer_size)
Initializes a dynamic string (dstring).
Definition dstring.c:10
void dstring_copy(dstring_t *string, const char *source)
Copies the content of source to the dstring.
Definition dstring.c:46
Struct for a Mya token.
Definition token.h:32
long long int value
Integer value of the token on TK_NUMBER tokens.
Definition token.h:36
token_type_t type
Token type.
Definition token.h:33
dstring_t lexeme
Lexeme of the token.
Definition token.h:37
unsigned int line
Token line inside the module.
Definition token.h:34
unsigned int column
Column of the token position on the line.
Definition token.h:35
void token_init(token_t *token, const char *lexeme, token_type_t type, unsigned int line, unsigned int column)
Initializes a token struct.
Definition token.c:7
enum token_type token_type_t
Enumeration of token types.
struct token token_t
Struct for a Mya token.