-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.h
53 lines (46 loc) · 1.53 KB
/
parse.h
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
//
// Created by koji on 1/9/22.
//
#ifndef FEMTO_RE_PARSE_H
#define FEMTO_RE_PARSE_H
#include <vector>
#include "token.h"
#include "node.h"
#include "render.h"
enum InsertionMode {
MD_INITIAL,
MD_BEFORE_HTML,
MD_BEFORE_HEAD,
MD_IN_HEAD,
MD_AFTER_HEAD,
MD_IN_BODY,
MD_AFTER_BODY,
MD_AFTER_AFTER_BODY
};
class Parser {
public:
Document document;
// https://html.spec.whatwg.org/multipage/parsing.html#the-insertion-mode
InsertionMode insertion_mode = {MD_INITIAL};
void parse(std::shared_ptr<Server> server);
std::shared_ptr<Element> head_element_pointer;
explicit Parser(Tokenizer tokenizer, std::istream& istream): tokenizer(tokenizer), istream(istream) {}
std::shared_ptr<RenderObject> render_root;
std::shared_ptr<RenderObject> latest_render_object;
private:
Tokenizer tokenizer;
std::istream& istream;
std::shared_ptr<Token> token;
std::vector<std::shared_ptr<Element>> stack_of_open_elements;
void parse_at_initial(std::shared_ptr<Server> server);
void parse_at_before_html(std::shared_ptr<Server> server);
HTMLHeadElement parse_at_before_head();
void parse_at_in_head(HTMLHeadElement& head_element);
std::shared_ptr<HTMLBodyElement> parse_at_after_head();
void parse_at_in_body(std::shared_ptr<HTMLBodyElement> body_element_pointer);
void parse_at_after_body();
void parse_at_after_after_body();
std::shared_ptr<Node> current_node();
void insert_html_element_for_the_token(std::shared_ptr<Element> element);
};
#endif //FEMTO_RE_PARSE_H