libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
tstream.h File Reference

Token stream processing. More...

#include "def.h"
#include "frontend/lexer/token.h"

Go to the source code of this file.

Data Structures

struct  ps_tstream
 Processes tokens in a stream. More...
 

Macros

#define ps_tstream_advance(tstream)   ps_tstream_advance_n(tstream, 1)
 Advances tstream the next token.
 

Functions

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_tokenps_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_tokenps_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_tokenps_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_tokenps_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.
 

Detailed Description

Token stream processing.

Author
Ethan Uppal

Definition in file tstream.h.

Macro Definition Documentation

◆ ps_tstream_advance

#define ps_tstream_advance (   tstream)    ps_tstream_advance_n(tstream, 1)

Advances tstream the next token.

Definition at line 51 of file tstream.h.

Function Documentation

◆ ps_tstream_advance_n()

void ps_tstream_advance_n ( struct ps_tstream ts,
isize  n 
)
inline

Advances tstream to its nth next token.

Definition at line 23 of file tstream.c.

◆ ps_tstream_current()

struct ps_token * ps_tstream_current ( struct ps_tstream ts)
inline

The current token in tstream.

Definition at line 19 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()

bool ps_tstream_is_eof ( struct ps_tstream ts)
inline

Whether tstream has no more tokens.

Definition at line 15 of file tstream.c.

◆ ps_tstream_match()

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.

Returns NULL and generates an error on failure.

Parameters
ctxThe context to use for error messages.

Definition at line 36 of file tstream.c.

◆ ps_tstream_match_any()

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.

Returns NULL and generates an error on failure.

Parameters
ctxThe context to use for error messages.

Definition at line 69 of file tstream.c.

◆ ps_tstream_peek()

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.

Otherwise, returns NULL.

Definition at line 27 of file tstream.c.