summaryrefslogtreecommitdiffstats
path: root/src/libixion/lexer_tokens.hpp
blob: 61109a6886e7f0a5ffea04bfee85c81b07a65770 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef INCLUDED_IXION_LEXER_TOKENS_HPP
#define INCLUDED_IXION_LEXER_TOKENS_HPP

#include <ixion/env.hpp>

#include <vector>
#include <memory>
#include <variant>
#include <string_view>

namespace ixion {

enum class lexer_opcode_t
{
    // data types
    value,
    string,
    name,

    // arithmetic operators
    plus,
    minus,
    divide,
    multiply,
    exponent,

    // string operators
    concat,

    // relational operators
    equal,
    less,
    greater,

    // parentheses, separators
    open,
    close,
    sep,
    array_open,
    array_close,
    array_row_sep,
};

const char* get_opcode_name(lexer_opcode_t oc);

struct lexer_token
{
    using value_type = std::variant<double, std::string_view>;

    lexer_opcode_t opcode;
    value_type value;

    lexer_token(lexer_opcode_t _opcode);
    lexer_token(lexer_opcode_t _opcode, std::string_view _value);
    lexer_token(double _value);
};

std::ostream& operator<<(std::ostream& os, const lexer_token& t);

using lexer_tokens_t = std::vector<lexer_token>;

std::string print_tokens(const lexer_tokens_t& tokens, bool verbose);

} // namespace ixion

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */