-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparser_state.hpp
More file actions
59 lines (46 loc) · 1.44 KB
/
parser_state.hpp
File metadata and controls
59 lines (46 loc) · 1.44 KB
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
#pragma once
#include "parser/lexer.hpp"
#include "parser/unicode_index.hpp"
#include <optional>
#include <stack>
#include <string>
#include <utility>
namespace mfl::parser
{
struct scope_settings
{
font_choice font = font_choice::normal;
};
class parser_state
{
public:
explicit parser_state(lexer& lex);
[[nodiscard]] tokens lexer_token() const;
void consume_token(const tokens tok);
[[nodiscard]] std::string lexer_value() const;
[[nodiscard]] std::string consume_lexer_value() const;
[[nodiscard]] std::pair<tokens, std::string> lexer_state() const;
void set_font_choice(const font_choice choice);
[[nodiscard]] font_choice get_font_choice() const;
void set_error(const std::string& error_text);
[[nodiscard]] std::optional<std::string> error() const;
void push_scope();
void pop_scope();
private:
lexer& lexer_;
std::stack<scope_settings> scopes_;
std::optional<std::string> error_;
};
class scoped_state
{
public:
scoped_state(parser_state& state, const scope_settings& settings);
~scoped_state();
scoped_state(const scoped_state&) = delete;
scoped_state& operator=(const scoped_state&) = delete;
scoped_state(scoped_state&&) = delete;
scoped_state& operator=(scoped_state&&) = delete;
private:
parser_state& state_;
};
}