2024-09-23 04:39:35 -07:00
|
|
|
#ifndef INCLUDED_PARSE_H
|
|
|
|
#define INCLUDED_PARSE_H
|
|
|
|
|
2024-08-15 02:11:26 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t line;
|
|
|
|
size_t col;
|
|
|
|
char *context;
|
|
|
|
char *desc;
|
2024-09-23 04:39:35 -07:00
|
|
|
bool at_end;
|
2024-08-15 02:11:26 -07:00
|
|
|
|
|
|
|
void *next;
|
|
|
|
} ParseError;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
FILE *src;
|
|
|
|
|
|
|
|
size_t line;
|
|
|
|
size_t col;
|
|
|
|
|
|
|
|
ParseError *error_head;
|
|
|
|
ParseError *error_tail;
|
|
|
|
size_t error_count;
|
|
|
|
} TokenStream;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TOKEN_TYPE_EOF,
|
|
|
|
TOKEN_TYPE_UNKNOWN,
|
|
|
|
TOKEN_TYPE_COMMENT,
|
|
|
|
TOKEN_TYPE_PAREN,
|
|
|
|
TOKEN_TYPE_BRACKET,
|
|
|
|
TOKEN_TYPE_SYMBOL,
|
|
|
|
TOKEN_TYPE_PROPERTY,
|
|
|
|
TOKEN_TYPE_QUOTE,
|
2024-09-23 04:39:35 -07:00
|
|
|
TOKEN_TYPE_BACKQUOTE,
|
|
|
|
TOKEN_TYPE_SPLICE,
|
|
|
|
TOKEN_TYPE_COMMA,
|
2024-08-15 02:11:26 -07:00
|
|
|
TOKEN_TYPE_CHAR,
|
|
|
|
TOKEN_TYPE_NUMBER,
|
|
|
|
TOKEN_TYPE_STRING,
|
|
|
|
} TokenType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
TokenType type;
|
|
|
|
char *text;
|
|
|
|
size_t buf_len;
|
|
|
|
size_t len;
|
|
|
|
size_t line;
|
|
|
|
size_t col;
|
|
|
|
} Token;
|
|
|
|
|
2024-09-23 04:39:35 -07:00
|
|
|
const char *token_type_to_str(TokenType type) __attribute__((unused));
|
|
|
|
|
2024-08-15 02:11:26 -07:00
|
|
|
// src is taken by this function
|
|
|
|
TokenStream *make_token_stream(FILE *src);
|
|
|
|
void destroy_token_stream(TokenStream *stream);
|
|
|
|
// return the number of errors after parsing
|
|
|
|
size_t token_stream_next(TokenStream *stream, Token *token);
|
|
|
|
void token_free(Token *token);
|
|
|
|
// return the number of errors left
|
|
|
|
ParseError *token_stream_error(TokenStream *stream);
|
|
|
|
void parse_error_free(ParseError *error);
|
2024-09-23 04:39:35 -07:00
|
|
|
bool token_stream_is_eof(TokenStream *stream);
|
2024-08-15 02:11:26 -07:00
|
|
|
|
2024-09-23 04:39:35 -07:00
|
|
|
#endif
|