You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.6 KiB
C
94 lines
2.6 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* tokenizer.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: hroussea <hroussea@student.42lyon.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/03/01 23:15:53 by hroussea #+# #+# */
|
|
/* Updated: 2021/04/28 16:57:49 by hroussea ### ########lyon.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef TOKENIZER_H
|
|
# define TOKENIZER_H
|
|
|
|
# include <stdlib.h>
|
|
# include <libft/vector.h>
|
|
# include <mlxglue/mlxglue.h>
|
|
|
|
typedef enum e_token_type {
|
|
TOKEN_IDENTIFIER,
|
|
TOKEN_PATH,
|
|
TOKEN_NUMBER,
|
|
TOKEN_NEWLINE,
|
|
TOKEN_EMPTYLINE,
|
|
TOKEN_PARSE_END,
|
|
TOKEN_MAPLINE,
|
|
TOKEN_COMMA,
|
|
TOKEN_NONE,
|
|
} t_token_type;
|
|
|
|
typedef enum e_parser_state {
|
|
STATE_PARSE_NUMBER,
|
|
STATE_PARSE_PATH,
|
|
STATE_PARSE_PATH_ESCAPE,
|
|
STATE_PARSE_IDENTIFIER,
|
|
STATE_PARSE_NEWLINE,
|
|
STATE_PARSE_EMPTYLINE,
|
|
STATE_PARSE_COMMA,
|
|
STATE_PARSE_ERROR,
|
|
STATE_END_DATA,
|
|
STATE_FIND_START_DATA,
|
|
STATE_FIND_START_TOKEN,
|
|
} t_parser_state;
|
|
|
|
typedef struct s_token {
|
|
t_token_type type;
|
|
unsigned int line;
|
|
unsigned int column;
|
|
unsigned int offset;
|
|
t_vector *vec;
|
|
} t_token;
|
|
|
|
typedef struct s_tokenizer {
|
|
t_parser_state state;
|
|
char *input;
|
|
unsigned int line;
|
|
unsigned int column;
|
|
unsigned int offset;
|
|
char *msg;
|
|
} t_tokenizer;
|
|
|
|
typedef struct s_cubheader {
|
|
t_u32 res_width;
|
|
t_u32 res_height;
|
|
t_bool res_done;
|
|
char *path_north;
|
|
char *path_south;
|
|
char *path_east;
|
|
char *path_west;
|
|
char *path_sprite;
|
|
t_u32 ceil_r;
|
|
t_u32 ceil_g;
|
|
t_u32 ceil_b;
|
|
t_bool ceil_done;
|
|
t_u32 floor_r;
|
|
t_u32 floor_g;
|
|
t_u32 floor_b;
|
|
t_bool floor_done;
|
|
} t_cubheader;
|
|
|
|
int tokenizer_consume(t_tokenizer *tknz, t_token *token);
|
|
void tokenizer_start(t_tokenizer *tknz, char *input);
|
|
void check_end_of_data(t_tokenizer *tknz, t_token *token);
|
|
void find_next_token(t_tokenizer *tknz, t_token *token);
|
|
void goto_first_data(t_tokenizer *tknz, t_token *token);
|
|
void state_machine(t_tokenizer *tknz, t_token *token);
|
|
|
|
void dispatch_by_id(t_tokenizer *tknz, t_cubheader *header,
|
|
t_token *token, char *path);
|
|
void parse_expression(t_tokenizer *tknz, t_cubheader *header, char *path);
|
|
|
|
#endif
|