libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
tstream.h
Go to the documentation of this file.
1
8#pragma once
9
10#include "def.h"
11#include "frontend/lexer/token.h" // ps_token
12
16struct ps_tstream {
19
21 const struct ps_token_arr* tokens;
22
24 const struct ps_file_ctx* file_ctx;
25};
26
30void ps_tstream_init(struct ps_tstream* ts, const struct ps_token_arr* tokens,
31 const struct ps_file_ctx* file_ctx);
32
36bool ps_tstream_is_eof(struct ps_tstream* ts);
37
41struct ps_token* ps_tstream_current(struct ps_tstream* ts);
42
46void ps_tstream_advance_n(struct ps_tstream* ts, isize n);
47
51#define ps_tstream_advance(tstream) ps_tstream_advance_n(tstream, 1)
52
57struct ps_token* ps_tstream_peek(struct ps_tstream* ts, usize n,
58 enum ps_token_type type);
59
66struct ps_token* ps_tstream_match(struct ps_tstream* ts,
67 enum ps_token_type type, STR ctx);
68
76 enum ps_token_type types[], usize count, STR ctx);
Base definitions.
#define STR
Definition def.h:40
#define isize
Definition def.h:49
#define usize
Definition def.h:50
Information captured in a file necessary for effective info/error reporting.
Definition io.h:15
Represents a token.
Definition token.h:34
enum ps_token_type type
Definition token.h:36
Processes tokens in a stream.
Definition tstream.h:16
usize index
inv: 0 < index <= tokens->length.
Definition tstream.h:18
const struct ps_token_arr * tokens
The tokens in the stream.
Definition tstream.h:21
const struct ps_file_ctx * file_ctx
The file context for the stream.
Definition tstream.h:24
Defines a token.
ps_token_type
The type of a token.
Definition token.h:18
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.
Definition tstream.c:36
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.
Definition tstream.c:8
bool ps_tstream_is_eof(struct ps_tstream *ts)
Whether tstream has no more tokens.
Definition tstream.c:15
struct ps_token * ps_tstream_current(struct ps_tstream *ts)
The current token in tstream.
Definition tstream.c:19
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.
Definition tstream.c:27
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.
Definition tstream.c:69
void ps_tstream_advance_n(struct ps_tstream *ts, isize n)
Advances tstream to its nth next token.
Definition tstream.c:23