xrb 0.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +1 -0
- data/bake/xrb/entities.rb +60 -0
- data/bake/xrb/parsers.rb +66 -0
- data/ext/Makefile +270 -0
- data/ext/XRB_Extension.bundle +0 -0
- data/ext/escape.o +0 -0
- data/ext/extconf.h +5 -0
- data/ext/extconf.rb +21 -0
- data/ext/markup.o +0 -0
- data/ext/mkmf.log +122 -0
- data/ext/query.o +0 -0
- data/ext/tag.o +0 -0
- data/ext/template.o +0 -0
- data/ext/xrb/escape.c +152 -0
- data/ext/xrb/escape.h +15 -0
- data/ext/xrb/markup.c +1949 -0
- data/ext/xrb/markup.h +6 -0
- data/ext/xrb/markup.rl +226 -0
- data/ext/xrb/query.c +619 -0
- data/ext/xrb/query.h +6 -0
- data/ext/xrb/query.rl +82 -0
- data/ext/xrb/tag.c +204 -0
- data/ext/xrb/tag.h +21 -0
- data/ext/xrb/template.c +1114 -0
- data/ext/xrb/template.h +6 -0
- data/ext/xrb/template.rl +77 -0
- data/ext/xrb/xrb.c +72 -0
- data/ext/xrb/xrb.h +132 -0
- data/ext/xrb.o +0 -0
- data/lib/xrb/buffer.rb +103 -0
- data/lib/xrb/builder.rb +229 -0
- data/lib/xrb/entities.rb +2137 -0
- data/lib/xrb/entities.xrb +15 -0
- data/lib/xrb/error.rb +81 -0
- data/lib/xrb/fallback/markup.rb +1657 -0
- data/lib/xrb/fallback/markup.rl +227 -0
- data/lib/xrb/fallback/query.rb +548 -0
- data/lib/xrb/fallback/query.rl +88 -0
- data/lib/xrb/fallback/template.rb +829 -0
- data/lib/xrb/fallback/template.rl +80 -0
- data/lib/xrb/markup.rb +56 -0
- data/lib/xrb/native.rb +15 -0
- data/lib/xrb/parsers.rb +16 -0
- data/lib/xrb/query.rb +80 -0
- data/lib/xrb/reference.rb +108 -0
- data/lib/xrb/strings.rb +47 -0
- data/lib/xrb/tag.rb +115 -0
- data/lib/xrb/template.rb +128 -0
- data/lib/xrb/uri.rb +100 -0
- data/lib/xrb/version.rb +8 -0
- data/lib/xrb.rb +11 -0
- data/license.md +23 -0
- data/readme.md +34 -0
- data.tar.gz.sig +0 -0
- metadata +118 -58
- metadata.gz.sig +2 -0
- data/README +0 -60
- data/app/helpers/ui_helper.rb +0 -80
- data/app/models/xrb/element.rb +0 -9
- data/lib/xrb/engine.rb +0 -4
- data/rails/init.rb +0 -1
- data/xrb.gemspec +0 -12
data/ext/xrb/markup.h
ADDED
data/ext/xrb/markup.rl
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
|
2
|
+
#include "markup.h"
|
3
|
+
|
4
|
+
%%{
|
5
|
+
machine XRB_markup_parser;
|
6
|
+
|
7
|
+
# Track the location of an identifier (tag name, attribute name, etc)
|
8
|
+
action identifier_begin {
|
9
|
+
identifier.begin = p;
|
10
|
+
}
|
11
|
+
|
12
|
+
action identifier_end {
|
13
|
+
identifier.end = p;
|
14
|
+
}
|
15
|
+
|
16
|
+
action pcdata_begin {
|
17
|
+
pcdata = Qnil;
|
18
|
+
has_entities = 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
action pcdata_end {
|
22
|
+
}
|
23
|
+
|
24
|
+
action text_begin {
|
25
|
+
}
|
26
|
+
|
27
|
+
action text_end {
|
28
|
+
rb_funcall(delegate, id_text, 1, XRB_markup_safe(pcdata, has_entities));
|
29
|
+
}
|
30
|
+
|
31
|
+
action characters_begin {
|
32
|
+
characters.begin = p;
|
33
|
+
}
|
34
|
+
|
35
|
+
action characters_end {
|
36
|
+
characters.end = p;
|
37
|
+
|
38
|
+
XRB_append_token(&pcdata, encoding, characters);
|
39
|
+
}
|
40
|
+
|
41
|
+
action entity_error {
|
42
|
+
XRB_raise_error("could not parse entity", buffer, p-s);
|
43
|
+
}
|
44
|
+
|
45
|
+
action entity_begin {
|
46
|
+
entity.begin = p;
|
47
|
+
}
|
48
|
+
|
49
|
+
action entity_name {
|
50
|
+
entity.end = p;
|
51
|
+
|
52
|
+
has_entities = 1;
|
53
|
+
|
54
|
+
XRB_append(&pcdata, encoding,
|
55
|
+
rb_funcall(entities, id_key_get, 1, XRB_Token_string(entity, encoding))
|
56
|
+
);
|
57
|
+
}
|
58
|
+
|
59
|
+
action entity_hex {
|
60
|
+
entity.end = p;
|
61
|
+
|
62
|
+
has_entities = 1;
|
63
|
+
|
64
|
+
codepoint = strtoul(entity.begin, (char **)&entity.end, 16);
|
65
|
+
|
66
|
+
XRB_append_codepoint(&pcdata, encoding, codepoint);
|
67
|
+
}
|
68
|
+
|
69
|
+
action entity_number {
|
70
|
+
entity.end = p;
|
71
|
+
|
72
|
+
has_entities = 1;
|
73
|
+
|
74
|
+
codepoint = strtoul(entity.begin, (char **)&entity.end, 10);
|
75
|
+
|
76
|
+
XRB_append_codepoint(&pcdata, encoding, codepoint);
|
77
|
+
}
|
78
|
+
|
79
|
+
action doctype_begin {
|
80
|
+
doctype.begin = p;
|
81
|
+
}
|
82
|
+
|
83
|
+
action doctype_end {
|
84
|
+
doctype.end = p;
|
85
|
+
|
86
|
+
rb_funcall(delegate, id_doctype, 1, XRB_Token_string(doctype, encoding));
|
87
|
+
}
|
88
|
+
|
89
|
+
action doctype_error {
|
90
|
+
XRB_raise_error("could not parse doctype", buffer, p-s);
|
91
|
+
}
|
92
|
+
|
93
|
+
action comment_begin {
|
94
|
+
comment.begin = p;
|
95
|
+
}
|
96
|
+
|
97
|
+
action comment_end {
|
98
|
+
comment.end = p;
|
99
|
+
|
100
|
+
rb_funcall(delegate, id_comment, 1, XRB_Token_string(comment, encoding));
|
101
|
+
}
|
102
|
+
|
103
|
+
action comment_error {
|
104
|
+
XRB_raise_error("could not parse comment", buffer, p-s);
|
105
|
+
}
|
106
|
+
|
107
|
+
action instruction_begin {
|
108
|
+
instruction.begin = p;
|
109
|
+
}
|
110
|
+
|
111
|
+
action instruction_text_begin {
|
112
|
+
}
|
113
|
+
|
114
|
+
action instruction_text_end {
|
115
|
+
}
|
116
|
+
|
117
|
+
action instruction_end {
|
118
|
+
instruction.end = p;
|
119
|
+
|
120
|
+
rb_funcall(delegate, id_instruction, 1, XRB_Token_string(instruction, encoding));
|
121
|
+
}
|
122
|
+
|
123
|
+
action instruction_error {
|
124
|
+
XRB_raise_error("could not parse instruction", buffer, p-s);
|
125
|
+
}
|
126
|
+
|
127
|
+
action tag_name {
|
128
|
+
// Reset self-closing state - we don't know yet.
|
129
|
+
self_closing = 0;
|
130
|
+
|
131
|
+
rb_funcall(delegate, id_open_tag_begin, 2, XRB_Token_string(identifier, encoding), ULONG2NUM(identifier.begin-s));
|
132
|
+
}
|
133
|
+
|
134
|
+
action tag_opening_begin {
|
135
|
+
}
|
136
|
+
|
137
|
+
action tag_self_closing {
|
138
|
+
self_closing = 1;
|
139
|
+
}
|
140
|
+
|
141
|
+
action attribute_begin {
|
142
|
+
has_value = 0;
|
143
|
+
}
|
144
|
+
|
145
|
+
action attribute_value {
|
146
|
+
has_value = 1;
|
147
|
+
}
|
148
|
+
|
149
|
+
action attribute_empty {
|
150
|
+
has_value = 2;
|
151
|
+
}
|
152
|
+
|
153
|
+
action attribute {
|
154
|
+
if (has_value == 1) {
|
155
|
+
rb_funcall(delegate, id_attribute, 2, XRB_Token_string(identifier, encoding), XRB_markup_safe(pcdata, has_entities));
|
156
|
+
} else if (has_value == 2) {
|
157
|
+
rb_funcall(delegate, id_attribute, 2, XRB_Token_string(identifier, encoding), empty_string);
|
158
|
+
} else {
|
159
|
+
rb_funcall(delegate, id_attribute, 2, XRB_Token_string(identifier, encoding), Qtrue);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
action tag_opening_end {
|
164
|
+
rb_funcall(delegate, id_open_tag_end, 1, self_closing == 1 ? Qtrue : Qfalse);
|
165
|
+
}
|
166
|
+
|
167
|
+
action tag_closing_begin {
|
168
|
+
}
|
169
|
+
|
170
|
+
action tag_closing_end {
|
171
|
+
rb_funcall(delegate, id_close_tag, 2, XRB_Token_string(identifier, encoding), ULONG2NUM(identifier.begin-s));
|
172
|
+
}
|
173
|
+
|
174
|
+
action tag_error {
|
175
|
+
XRB_raise_error("could not parse tag", buffer, p-s);
|
176
|
+
}
|
177
|
+
|
178
|
+
action cdata_begin {
|
179
|
+
cdata.begin = p;
|
180
|
+
}
|
181
|
+
|
182
|
+
action cdata_end {
|
183
|
+
cdata.end = p;
|
184
|
+
|
185
|
+
rb_funcall(delegate, id_cdata, 1, XRB_Token_string(cdata, encoding));
|
186
|
+
}
|
187
|
+
|
188
|
+
action cdata_error {
|
189
|
+
XRB_raise_error("could not parse cdata", buffer, p-s);
|
190
|
+
}
|
191
|
+
|
192
|
+
include markup "xrb/markup.rl";
|
193
|
+
|
194
|
+
write data;
|
195
|
+
}%%
|
196
|
+
|
197
|
+
VALUE XRB_Native_parse_markup(VALUE self, VALUE buffer, VALUE delegate, VALUE entities) {
|
198
|
+
VALUE string = rb_funcall(buffer, id_read, 0);
|
199
|
+
|
200
|
+
rb_encoding *encoding = rb_enc_get(string);
|
201
|
+
|
202
|
+
VALUE pcdata = Qnil;
|
203
|
+
|
204
|
+
VALUE empty_string = rb_obj_freeze(rb_enc_str_new(0, 0, encoding));
|
205
|
+
|
206
|
+
const char *s, *p, *pe, *eof;
|
207
|
+
unsigned long cs, top = 0, stack[2] = {0};
|
208
|
+
unsigned long codepoint = 0;
|
209
|
+
|
210
|
+
XRB_Token identifier = {0}, cdata = {0}, characters = {0}, entity = {0}, doctype = {0}, comment = {0}, instruction = {0};
|
211
|
+
unsigned self_closing = 0, has_value = 0, has_entities = 0;
|
212
|
+
|
213
|
+
s = p = RSTRING_PTR(string);
|
214
|
+
eof = pe = p + RSTRING_LEN(string);
|
215
|
+
|
216
|
+
%%{
|
217
|
+
write init;
|
218
|
+
write exec;
|
219
|
+
}%%
|
220
|
+
|
221
|
+
if (p != eof) {
|
222
|
+
XRB_raise_error("could not parse all input", buffer, p-s);
|
223
|
+
}
|
224
|
+
|
225
|
+
return Qnil;
|
226
|
+
}
|