summaryrefslogtreecommitdiff
path: root/core/parser.c
blob: 727d5e1905ba21dc7e6e52527a2c5af6fa3df1b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 2026, Apollo Telephone Laboratories.
 * Provided under the BSD-3 clause.
 */

#include "defconf/parser.h"
#include "defconf/lexer.h"
#include "defconf/token.h"

/* Symbolic token */
#define SYMTOK(TOKSTR) \
    "[" TOKSTR "]"

/* Literal token */
#define TOKLIT(TOKSTR)  \
    "'" TOKSTR "'"

/* Safe macro to convert token type to string */
#define TOKSTR(TT)      \
    ((TT) >= _TT_MAX)   \
        ? "bad"         \
        : toktab[(TT)]

/* Token to string table */
static const char *toktab[_TT_MAX] = {
    [TT_NONE]       = SYMTOK("none"),
    [TT_DEFINE]     = SYMTOK("define"),
    [TT_TRUE]       = TOKLIT("true"),
    [TT_FALSE]      = TOKLIT("false"),
    [TT_INTLIT]     = SYMTOK("int"),
    [TT_IDENT]      = SYMTOK("ident")
};

int
parse_begin(struct defconf_state *state)
{
    struct token tok;

    if (state == NULL) {
        return -1;
    }

    while (lexer_scan(state, &tok) == 0) {
        printf("got %s\n", TOKSTR(tok.type));
    }

    return 0;
}