9 const struct ps_token_arr* tokens,
const struct ps_file_ctx* file_ctx) {
29 if (ts->
index + n < ts->tokens->length) {
55 ast_sprintf(
"Expected '%s' here, received '%s' instead",
65#define _PS_MATCH_N_ERROR_FIX_MSG \
66 ast_sprintf("Expected one of %zu options here, received '%s' instead", \
67 count, ps_token_type_to_string(current->type))
76 ast_sprintf(
"Expected one of %zu options here", count));
84 for (
usize i = 0; i < count; i++) {
85 if (current->
type == types[i]) {
97#undef _PS_MATCH_N_ERROR_FIX_MSG
106 ps_error(PS_SCOPE_ERROR, code == -1 ? PS_ECODE_UNEXPECTED_TKN : code,
108 ast_sprintf(
"Unexpected end of file %s", ctx), fix, NULL);
#define ps_assert(cond, msg)
Asserts the given condition cond, aborting via ps_abort with the given msg otherwise.
Defines an arena allocator for the compiler.
#define ast_sprintf(fmt,...)
Error reporting and displaying utilities.
Defines safe file I/O functions.
Represents an error or source-referencing display message.
Information captured in a file necessary for effective info/error reporting.
Processes tokens in a stream.
usize index
inv: 0 < index <= tokens->length.
const struct ps_token_arr * tokens
The tokens in the stream.
const struct ps_file_ctx * file_ctx
The file context for the stream.
STR ps_token_type_to_string(enum ps_token_type type)
Returns: the string representation of the given token type type.
ps_token_type
The type of a token.
void ps_tstream_eof_error(struct ps_tstream *ts, int code, STR ctx, STR fix)
Reports an end-of-file error with the given context ctx, using the last token in ts for location.
struct ps_token * ps_tstream_match(struct ps_tstream *ts, enum ps_token_type type, STR ctx)
Attempts to match the next token with the given token type.
#define _PS_MATCH_N_ERROR_FIX_MSG
void ps_tstream_init(struct ps_tstream *ts, const struct ps_token_arr *tokens, const struct ps_file_ctx *file_ctx)
Points tstream to the first token in tokens and reads from it there on.
bool ps_tstream_is_eof(struct ps_tstream *ts)
Whether tstream has no more tokens.
struct ps_token * ps_tstream_current(struct ps_tstream *ts)
The current token in tstream.
struct ps_token * ps_tstream_peek(struct ps_tstream *ts, usize n, enum ps_token_type type)
If the nth next token in ts is of the given type, returns it.
struct ps_token * ps_tstream_match_any(struct ps_tstream *ts, enum ps_token_type types[], usize count, STR ctx)
Attempts to match the next token with one of the given token types.
void ps_tstream_advance_n(struct ps_tstream *ts, isize n)
Advances tstream to its nth next token.
#define ps_tstream_advance(tstream)
Advances tstream the next token.