68 lines
1.4 KiB
C
68 lines
1.4 KiB
C
#ifndef INCLUDED_PARSE_H
|
|
#define INCLUDED_PARSE_H
|
|
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
size_t line;
|
|
size_t col;
|
|
char *context;
|
|
char *desc;
|
|
bool at_end;
|
|
|
|
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,
|
|
TOKEN_TYPE_BACKQUOTE,
|
|
TOKEN_TYPE_SPLICE,
|
|
TOKEN_TYPE_COMMA,
|
|
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;
|
|
|
|
const char *token_type_to_str(TokenType type) __attribute__((unused));
|
|
|
|
// 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);
|
|
bool token_stream_is_eof(TokenStream *stream);
|
|
|
|
#endif
|