summaryrefslogtreecommitdiff
path: root/core/parser.c
blob: 6cf0a4e23db5fc6fef77cd272873a9cc1ab24974 (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
49
50
51
52
53
54
55
/*
 * Copyright (c) 2026, Apollo Telephone Laboratories.
 * Provided under the BSD-3 clause.
 */

#include <stdint.h>
#include <stddef.h>
#include <atas/lexer.h>

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

/* Literal token */
#define LITTOK(TOK) \
    "'" TOK "'"

/*
 * Safe macro to index toktab
 */
#define TOK_STR(TT)     \
    ((TT) >= TT_MAX)    \
        ? "bad"         \
        : toktab[(TT)]

/*
 * Lookup table to convert token constants into
 * strings.
 */
static const char *toktab[] = {
    [TT_NONE]       = SYMTOK("NONE"),
    [TT_COMMA]      = LITTOK(",")
};

int
atas_parse(struct atas_state *state)
{
    int error;
    struct atas_token tok;

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

    for (;;) {
        error = atas_lexer_scan(state, &tok);
        if (error < 0) {
            break;
        }

        printf("got token %s\n", TOK_STR(tok.type));
    }

    return 0;
}