summaryrefslogtreecommitdiff
path: root/source/fajr_parser/fajr_parser.h
blob: d83dde2b1ad50385a1458df3f238686d28be247b (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
56
57
58
59
60
#ifndef EDITOR_PARSER_H
#define EDITOR_PARSER_H

typedef enum syntax_node_type syntax_node_type;
enum syntax_node_type
{
    SyntaxNodeLiteral,
    SyntaxNodeIdentifier,
    SyntaxNodeBinary,

    SyntaxNodeAssignment,
    SyntaxNodeReturn,
    SyntaxNodeFunction,
    SyntaxNodeUnwanted,
};

typedef struct syntax_node syntax_node;
struct syntax_node
{
    syntax_node *First;
    syntax_node *Last;
    syntax_node *Parent;
    syntax_node *Next;

    token *Token;

    syntax_node_type Type;
};

typedef struct concrete_syntax_tree concrete_syntax_tree;
struct concrete_syntax_tree
{
    syntax_node *Root;
    syntax_node *Current;
};

// TODO(nasr): implement this later together with file handling
read_only global_variable
syntax_node nil_syntax_node =
{
.First  = &nil_syntax_node,
.Last   = &nil_syntax_node,
.Parent = &nil_syntax_node,
.Next   = &nil_syntax_node,
.Token  = &nil_token,
};

read_only global_variable
concrete_syntax_tree nil_concrete_syntax_tree =
{
.Root    = &nil_syntax_node,
.Current = &nil_syntax_node,
};

#define PeekForward(Node, Type, NilNode) \
    for(; (Node) && (Node) != &(NilNode); (Node) = (Node)->Next) \
        if((Node)->Token->Type == (Type)) \
            break;

#endif // EDITOR_PARSER_H