aboutsummaryrefslogtreecommitdiff
path: root/include/lang_analysis/symbol_property.h
blob: 826640876c47d419c0ba441155f06a2db7b63085 (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

#pragma once

#include <unordered_map>
#include <string>

#include "lang_analysis/enum_type.h"

namespace ov4
{

class T_property
{
public:
    bool continuable = true;

    // -1 means it's NOT operator
    // any positive values mean it's operator
    int pivot_priority = -1;

    // require: MUST
    // accept: optional, but if it doesn't accept, but there is indeed a child, then error
    child_existence_type left;
    child_existence_type right;

    enum_token_type enum_type = TEXT;
};

inline const std::unordered_map<std::string, T_property> symbol_property = {

    // bracket
    {"(",    {.continuable = false, .enum_type = LEFT_BRACKET}},
    {")",    {.continuable = false, .enum_type = RIGHT_BRACKET}},

    // operator
    {"&",    {.continuable = true,  .pivot_priority = 2000, .left = child_existence_type::EXIST,     .right = child_existence_type::NOT_EXIST, .enum_type = ASYNC}},
    {"|",    {.continuable = true,  .pivot_priority = 100,  .left = child_existence_type::EXIST,     .right = child_existence_type::EXIST,     .enum_type = PIPE}},
    {"&&",   {.continuable = true,  .pivot_priority = 1000, .left = child_existence_type::EXIST,     .right = child_existence_type::EXIST,     .enum_type = LOGIC_AND}},
    {"||",   {.continuable = true,  .pivot_priority = 1000, .left = child_existence_type::EXIST,     .right = child_existence_type::EXIST,     .enum_type = LOGIC_OR}},

    {";",    {.continuable = false, .pivot_priority = 2000, .left = child_existence_type::EXIST,     .right = child_existence_type::OPTIONAL,  .enum_type = SEMICOLON}},

};

std::string symbol_enum2string(enum_token_type e);

bool symbol_contains_enum_type(enum_token_type e);
    
}