fix(lexer): includes + typo + clang format
This commit is contained in:
parent
8262fdece8
commit
58fd9d530e
2 changed files with 10 additions and 9 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
@ -28,10 +29,9 @@ static void save_state(char *stream, ssize_t i)
|
||||||
*/
|
*/
|
||||||
static bool is_special_char(char c)
|
static bool is_special_char(char c)
|
||||||
{
|
{
|
||||||
return c == '\'' || c == '\n' || c == ';' || c == 'EOF';
|
return c == '\'' || c == '\n' || c == ';' || c == EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* @brief: if a special character is found at [begin],
|
/* @brief: if a special character is found at [begin],
|
||||||
* [tok->token_type] is set accordingly
|
* [tok->token_type] is set accordingly
|
||||||
*
|
*
|
||||||
|
|
@ -40,7 +40,7 @@ static void set_token_spechar(struct token *tok, char *begin, ssize_t size)
|
||||||
{
|
{
|
||||||
if (size != 1)
|
if (size != 1)
|
||||||
return;
|
return;
|
||||||
if (begin[0] == 'EOF')
|
if (begin[0] == EOF)
|
||||||
{
|
{
|
||||||
tok->type = TOKEN_EOF;
|
tok->type = TOKEN_EOF;
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,6 @@ static void set_token_spechar(struct token *tok, char *begin, ssize_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* @brief: if a keyword is found at [begin],
|
/* @brief: if a keyword is found at [begin],
|
||||||
* [tok->token_type] is set accordingly
|
* [tok->token_type] is set accordingly
|
||||||
*
|
*
|
||||||
|
|
@ -90,10 +89,12 @@ static void set_token_keyword(struct token *tok, char *begin, ssize_t size)
|
||||||
*/
|
*/
|
||||||
static void set_token_word(struct token *tok, char *begin, ssize_t size)
|
static void set_token_word(struct token *tok, char *begin, ssize_t size)
|
||||||
{
|
{
|
||||||
if (tok->token_type == TOKEN_NULL)
|
if (tok->type == TOKEN_NULL)
|
||||||
{
|
{
|
||||||
char *token_data = calloc(size + 1, sizeof(char));
|
tok->data = calloc(size + 1, sizeof(char));
|
||||||
strncpy(res, begin, size);
|
if (tok->data == NULL)
|
||||||
|
return;
|
||||||
|
strncpy(tok->data, begin, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ enum token_type
|
||||||
struct token
|
struct token
|
||||||
{
|
{
|
||||||
enum token_type type;
|
enum token_type type;
|
||||||
char* data;
|
char *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -57,7 +57,7 @@ struct token *new_token(char *begin, ssize_t size);
|
||||||
/* @brief: frees the token given in argument
|
/* @brief: frees the token given in argument
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void free_token(struct token* tok);
|
void free_token(struct token *tok);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief: checks if the stream used for the last token creation is empty.
|
* @brief: checks if the stream used for the last token creation is empty.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue