-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.h
More file actions
89 lines (72 loc) · 1.72 KB
/
parser.h
File metadata and controls
89 lines (72 loc) · 1.72 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL2/SDL.h>
#ifndef BROWSER_PARSER_H
#define BROWSER_PARSER_H
#define MAX_TAGS 2000
static char *tag_names[] = {
"div", "span", "strong", "img", "title", "section", "pre", "script", "p",
"a", "h1", "h2", "h3", "ul", "li", "em", "br"};
static const int supported_count = sizeof(tag_names) / sizeof(tag_names[0]);
static char *convert_names[] = {"©", "<", ">",
"&", """, "'"};
static char *convert_values[] = {"©", "<", ">", "&", "\"", "'"};
static const int convert_count =
sizeof(convert_names) / sizeof(convert_names[0]);
typedef enum {
START_TAG,
END_TAG,
START_TAG_ONLY,
PLAIN_TEXT,
TK_EOF
} TokenKind;
typedef enum {
TAG_DIV,
TAG_SPAN,
TAG_STRONG,
TAG_IMG,
TAG_TITLE,
TAG_SECTION,
TAG_PRE,
TAG_SCRIPT,
TAG_P,
TAG_A,
TAG_H1,
TAG_H2,
TAG_H3,
TAG_UL,
TAG_LI,
TAG_EM,
TAG_BR
} TagKind;
typedef enum { FONT_NORMAL, FONT_BOLD, FONT_ITALIC } FontKind;
typedef enum { TEXT_NONE, TEXT_UNDERLINE } TextDecoration;
typedef enum { DISPLAY_NONE, DISPLAY_BLOCK, DISPLAY_INLINE } Display;
typedef struct CssProperty CssProperty;
struct CssProperty {
SDL_Color color;
int font_size;
FontKind font_weight;
FontKind font_style;
TextDecoration text_decoration;
Display display;
};
typedef struct Token Token;
struct Token {
TokenKind kind;
Token *next;
Token *parent;
TagKind tag;
CssProperty *css_property;
char text[4000];
char html_id[200];
char html_class[200];
};
void error(char *fmt, ...);
void warning(char *fmt, ...);
Token *parse_html(char *file_name);
#endif