AST building #2
41
include/compiler/treeifier/ast.hh
Normal file
41
include/compiler/treeifier/ast.hh
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include "compiler/treeifier/tokenizer.hh"
|
||||
#include "utils/data.hh"
|
||||
#include "utils/slice.hh"
|
||||
#include "lang/common.hh"
|
||||
|
||||
using namespace std::string_literals;
|
||||
using namespace ppc;
|
||||
|
||||
namespace ppc::comp::tree::ast {
|
||||
class constr_parser_t {
|
||||
private:
|
||||
std::string name;
|
||||
public:
|
||||
const std::string &name() { return name; }
|
||||
virtual bool parse(messages::msg_stack_t &messages, vec_slice_t<tok::token_t> &tokens, data::map_t &out) = 0;
|
||||
};
|
||||
|
||||
class group_parser_t : constr_parser_t {
|
||||
private:
|
||||
struct named_parser {
|
||||
constr_parser_t *parser;
|
||||
std::string name;
|
||||
};
|
||||
std::list<constr_parser_t*> parsers;
|
||||
std::unordered_map<std::string, constr_parser_t*> insertion_points;
|
||||
public:
|
||||
void add_insertion_point(constr_parser_t &parser, const std::string &name);
|
||||
void add(constr_parser_t &parser);
|
||||
void add(const std::string &ins_point, constr_parser_t &parser);
|
||||
|
||||
bool parse(messages::msg_stack_t &messages, data::map_t &out);
|
||||
|
||||
group_parser_t();
|
||||
};
|
||||
}
|
1
src/compiler/treeifier/ast.cc
Normal file
1
src/compiler/treeifier/ast.cc
Normal file
@ -0,0 +1 @@
|
||||
#include "compiler/treeifier/ast.hh"
|
Loading…
Reference in New Issue
Block a user