Files
2026-05-23 19:01:51 -04:00

69 lines
1.2 KiB
C

/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause
*/
#ifndef CESCAL_TOKBUF_H
#define CESCAL_TOKBUF_H 1
#include <stdint.h>
#include <stddef.h>
#include "cescal/token.h"
#define TOKBUF_CAP 4
struct tokbuf {
struct token *buf;
size_t cap;
uint8_t head;
};
/*
* Initialize the token buffer
*
* @tokbuf: Token buffer to initialize
*
* Returns zero on success
*/
int tokbuf_init(struct tokbuf *tokbuf);
/*
* Push a token onto the token buffer
*
* @tokbuf: Token buffer to push to
* @tok: Token to push
*
* Returns zero on success
*/
int tokbuf_push(struct tokbuf *tokbuf, struct token *tok);
/*
* Pop a token from the token buffer
*
* @tokbuf: Token buffer to pop from
* @res: Result is written here
*
* Returns zero on success
*/
int tokbuf_pop(struct tokbuf *tokbuf, struct token *res);
/*
* Peek at the token buffer from a negative offset backwards
*
* @tokbuf: Token buffer to read from
* @noff: Negative offset
* @res: Result is written here
*
* Returns zero on success
*/
int tokbuf_noff(struct tokbuf *tokbuf, size_t noff, struct token *res);
/*
* Destroy a token buffer
*
* @tokbuf: Token buffer to destroy
*/
void tokbuf_destroy(struct tokbuf *tokbuf);
#endif /* !CESCAL_TOKBUF_H */