-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSACtest.cpp
More file actions
212 lines (175 loc) · 4.82 KB
/
SACtest.cpp
File metadata and controls
212 lines (175 loc) · 4.82 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "SimpAC.h"
#include <cstring>
#include <cstdio>
const char * css_test1 = ""
"A,B,C:c(a,s),D{ font-family: \"Microsoft YaHei\"; }"
"#btn0 { font-family: Microsoft YaHei; }"
"#btn1 { image: url('https://a.b.c/d.png') 30 }"
"\0"
" .css * :hover , #ele {/*asd*/"
" color: red ; "
"}"
;
const auto css_inline = u8R"(background-color:red;background-color:blue)";
const auto css_test = u8R"(
button#button, #layout .button{
-moz-appearance: none;
transition: 0.5s;
background-color: red;
background-color: blue;
}
#layout button:hover {
background-color: yellow "sad";
color: rgb(255,20,0) ;
background-image: url('../images/2 5.png') ;
font: italic bold .8em/ 1.2 Arial;
}
.imgButton {
-moz-appearance: none;
border-width: 3px;
border-image-source: url(../images/btn.png);
border-image-slice: 3 fill;
}
)"
;
using namespace SimpAC;
struct Css final : SimpAC::CACStream {
virtual void add_comment(StrPair) noexcept override;
virtual void add_selector(BasicSelectors, StrPair) noexcept override;
virtual void add_selector_combinator(Combinators) noexcept override;
virtual void add_selector_comma() noexcept override;
virtual void begin_properties() noexcept override;
virtual void end_properties() noexcept override;
virtual void begin_property(StrPair) noexcept override;
virtual void add_value(StrPair) noexcept override;
virtual void add_func_value(FuncValue, StrPair) noexcept override;
virtual void add_attribute_selector(BasicSelectors, StrPair, StrPair) noexcept override;
static void printf(StrPair);
};
int main() {
Css parser;
//parser.Load({ css_test, css_test + std::strlen(css_test) });
parser.Load({ css_inline, css_inline + std::strlen(css_inline) }, true);
//std::printf("\nPRESS 'O' to OUTPUT FUNC-LIST\n");
const char ch = std::getchar();
//if (ch == 'O' || ch == 'o') {
// std::getchar();
//}
return 0;
}
void Css::printf(StrPair view) {
const int len = view.second - view.first;
std::printf("%.*s", len, view.first);
}
void Css::add_comment(StrPair view) noexcept {
std::printf("add_comment: ");
this->printf(view);
std::putchar('\n');
}
#ifdef SAC_ATTRIBUTE_SELECTOR
void Css::add_attribute_selector(BasicSelectors sel, StrPair a, StrPair b) noexcept {
auto type = "";
switch (sel)
{
case Selectors_AttributeSet:
type = "[x]";
b.second = b.first;
break;
case Selectors_AttributeExact:
type = "[x=y]";
break;
case Selectors_AttributeList:
type = "[x~=y]";
break;
case Selectors_AttributeHyphen:
type = "[x|=y]";
break;
case Selectors_AttributeContain:
type = "[x*=y]";
break;
case Selectors_AttributeBegin:
type = "[x^=y]";
break;
case Selectors_AttributeEnd:
type = "[x&=y]";
break;
}
std::printf("add_selector: ");
this->printf(a);
std::printf(type);
this->printf(b);
std::putchar('\n');
}
#endif
void Css::add_selector(BasicSelectors sel, StrPair view) noexcept {
auto t = "";
switch (sel)
{
case Selectors_Type:
t = "<element>";
break;
case Selectors_Class:
t = "<class>";
break;
case Selectors_Id:
t = "<id>";
break;
case Selectors_Universal:
t = "<*>";
break;
case Selectors_PseudoClass:
t = "<p-class>";
break;
case Selectors_PseudoElement:
t = "<p-element>";
break;
}
std::printf("add_selector: %s", t);
this->printf(view);
std::putchar('\n');
}
void Css::add_selector_combinator(Combinators c) noexcept {
const char* str = "";
switch (c)
{
case Combinators_AdjacentSibling:
str = "A + B";
break;
case Combinators_GeneralSibling:
str = "A ~ B";
break;
case Combinators_Child:
str = "A > B";
break;
case Combinators_Descendant:
str = "A B";
break;
}
std::printf("add_selector_combinator: %s\n", str);
}
void Css::add_selector_comma() noexcept {
std::printf("add_selector_comma\n");
}
void Css::begin_properties() noexcept {
std::printf("begin_properties {\n");
}
void Css::end_properties() noexcept {
std::printf("} end_properties\n\n");
}
void Css::begin_property(StrPair view) noexcept {
std::printf(" begin_propertie: ");
this->printf(view);
std::putchar('\n');
}
void Css::add_value(StrPair view) noexcept {
std::printf(" --add_value: ");
this->printf(view);
std::putchar('\n');
}
void Css::add_func_value(FuncValue value, StrPair raw_func) noexcept {
std::printf(" --add_value: ");
this->printf(raw_func);
std::putchar(':');
this->printf(StrPair{ value.first, value.first + value.length });
std::putchar('\n');
} //