summaryrefslogtreecommitdiff
path: root/src/lex.h
blob: 9e600d75f25724f3dd483bdb21512499620f0efc (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
#ifndef ANIMTOOL_LEX_H_
#define ANIMTOOL_LEX_H_

#include "util/container.h"
#include "util/str.h"
#include "source.h"
#include "op.h"

enum token_type
{
    TOKEN_NUMBER,
    TOKEN_STRING,
    TOKEN_VAR,
    TOKEN_IDENT,
    TOKEN_OP,
};

struct token
{
    struct range loc;
    enum token_type type;
    union
    {
        double number;
        str string;
        str var;
        str ident;
        struct
        {
            enum op_type type;
            struct range name_loc;
            array(struct token) children;
        } op;
    };
};

bool lex_token(struct source *source, struct token *tok);
void free_token(struct token *tok);

#endif