Go to the source code of this file.
|
| 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.
|
| |
| void | ps_tstream_advance_n (struct ps_tstream *ts, isize n) |
| | Advances tstream to its nth next token.
|
| |
| 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 (struct ps_tstream *ts, enum ps_token_type type, STR ctx) |
| | Attempts to match the next token with the given token type.
|
| |
| 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_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.
|
| |
◆ _PS_MATCH_N_ERROR_FIX_MSG
| #define _PS_MATCH_N_ERROR_FIX_MSG |
Value: ast_sprintf(
"Expected one of %zu options here, received '%s' instead", \
#define ast_sprintf(fmt,...)
STR ps_token_type_to_string(enum ps_token_type type)
Returns: the string representation of the given token type type.
Definition at line 65 of file tstream.c.
◆ ps_tstream_advance_n()
Advances tstream to its nth next token.
Definition at line 23 of file tstream.c.
◆ ps_tstream_current()
The current token in tstream.
Definition at line 19 of file tstream.c.
◆ ps_tstream_eof_error()
| 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.
- Precondition
- The token stream
ts must be non-empty.
- Parameters
-
| code | The error code for the error. Supply -1 for a default error code. |
Definition at line 99 of file tstream.c.
◆ ps_tstream_init()
| void ps_tstream_init |
( |
struct ps_tstream * |
ts, |
|
|
const struct ps_token_arr * |
tokens, |
|
|
const struct ps_file_ctx * |
file_ctx |
|
) |
| |
|
inline |
Points tstream to the first token in tokens and reads from it there on.
Definition at line 8 of file tstream.c.
◆ ps_tstream_is_eof()
Whether tstream has no more tokens.
Definition at line 15 of file tstream.c.
◆ ps_tstream_match()
Attempts to match the next token with the given token type.
Returns NULL and generates an error on failure.
- Parameters
-
| ctx | The context to use for error messages. |
Definition at line 36 of file tstream.c.
◆ ps_tstream_match_any()
Attempts to match the next token with one of the given token types.
Returns NULL and generates an error on failure.
- Parameters
-
| ctx | The context to use for error messages. |
Definition at line 69 of file tstream.c.
◆ ps_tstream_peek()
If the nth next token in ts is of the given type, returns it.
Otherwise, returns NULL.
Definition at line 27 of file tstream.c.