62 lines
1.4 KiB
C
62 lines
1.4 KiB
C
#include "lex.h"
|
|
|
|
#include "token.h"
|
|
|
|
#define LEX_TOKEN_DEF(i, n) {.id = (i), .name = (n)}
|
|
|
|
static struct lex_token_def keywords[] = {
|
|
LEX_TOKEN_DEF(KW_FUNC, "func"),
|
|
};
|
|
static const size_t nr_keywords = sizeof keywords / sizeof keywords[0];
|
|
|
|
static struct lex_token_def symbols[] = {
|
|
LEX_TOKEN_DEF(SYM_SQUOTE, "'"),
|
|
LEX_TOKEN_DEF(SYM_DQUOTE, "\""),
|
|
LEX_TOKEN_DEF(SYM_LEFT_BRACE, "{"),
|
|
LEX_TOKEN_DEF(SYM_RIGHT_BRACE, "}"),
|
|
LEX_TOKEN_DEF(SYM_LEFT_BRACKET, "["),
|
|
LEX_TOKEN_DEF(SYM_RIGHT_BRACKET, "]"),
|
|
LEX_TOKEN_DEF(SYM_LEFT_PAREN, "("),
|
|
LEX_TOKEN_DEF(SYM_RIGHT_PAREN, ")"),
|
|
};
|
|
static const size_t nr_symbols = sizeof symbols / sizeof symbols[0];
|
|
|
|
enum bshell_status lex_ctx_init(struct lex_ctx *ctx, struct line_source *src)
|
|
{
|
|
memset(ctx, 0x0, sizeof *ctx);
|
|
|
|
ctx->lex_status = BSHELL_SUCCESS;
|
|
ctx->lex_src = src;
|
|
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
enum bshell_status lex_ctx_cleanup(struct lex_ctx *ctx)
|
|
{
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
static struct lex_token *dequeue_token(struct lex_ctx *ctx)
|
|
{
|
|
fx_queue_entry *entry = fx_queue_first(&ctx->lex_tokens);
|
|
return fx_unbox(struct lex_token, entry, tok_entry);
|
|
}
|
|
|
|
static enum bshell_status pump_tokens(struct lex_ctx *ctx)
|
|
{
|
|
return BSHELL_SUCCESS;
|
|
}
|
|
|
|
struct lex_token *lex_ctx_peek(struct lex_ctx *ctx)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void lex_ctx_advance(struct lex_ctx *ctx)
|
|
{
|
|
struct lex_token *tok = dequeue_token(ctx);
|
|
if (tok) {
|
|
lex_token_destroy(tok);
|
|
}
|
|
}
|