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
@@ -0,0 +1,227 @@
|
|
1
|
+
# Released under the MIT License.
|
2
|
+
# Copyright, 2016-2024, by Samuel Williams.
|
3
|
+
|
4
|
+
%%{
|
5
|
+
machine markup;
|
6
|
+
|
7
|
+
action identifier_begin {
|
8
|
+
identifier_begin = p
|
9
|
+
}
|
10
|
+
|
11
|
+
action identifier_end {
|
12
|
+
identifier_end = p
|
13
|
+
}
|
14
|
+
|
15
|
+
action pcdata_begin {
|
16
|
+
pcdata = ""
|
17
|
+
has_entities = false
|
18
|
+
}
|
19
|
+
|
20
|
+
action pcdata_end {
|
21
|
+
}
|
22
|
+
|
23
|
+
action text_begin {
|
24
|
+
}
|
25
|
+
|
26
|
+
action text_end {
|
27
|
+
pcdata = MarkupString.raw(pcdata) unless has_entities
|
28
|
+
|
29
|
+
delegate.text(pcdata)
|
30
|
+
}
|
31
|
+
|
32
|
+
action characters_begin {
|
33
|
+
characters_begin = p
|
34
|
+
}
|
35
|
+
|
36
|
+
action characters_end {
|
37
|
+
characters_end = p
|
38
|
+
|
39
|
+
pcdata << data.byteslice(characters_begin...characters_end)
|
40
|
+
}
|
41
|
+
|
42
|
+
action entity_error {
|
43
|
+
raise ParseError.new("could not parse entity", buffer, p)
|
44
|
+
}
|
45
|
+
|
46
|
+
action entity_begin {
|
47
|
+
entity_begin = p
|
48
|
+
}
|
49
|
+
|
50
|
+
action entity_name {
|
51
|
+
entity_end = p
|
52
|
+
|
53
|
+
name = data.byteslice(entity_begin...entity_end)
|
54
|
+
|
55
|
+
has_entities = true
|
56
|
+
pcdata << entities[name]
|
57
|
+
}
|
58
|
+
|
59
|
+
action entity_hex {
|
60
|
+
entity_end = p
|
61
|
+
|
62
|
+
has_entities = true
|
63
|
+
pcdata << data.byteslice(entity_begin...entity_end).to_i(16)
|
64
|
+
}
|
65
|
+
|
66
|
+
action entity_number {
|
67
|
+
entity_end = p
|
68
|
+
|
69
|
+
has_entities = true
|
70
|
+
pcdata << data.byteslice(entity_begin...entity_end).to_i(10)
|
71
|
+
}
|
72
|
+
|
73
|
+
action doctype_begin {
|
74
|
+
doctype_begin = p
|
75
|
+
}
|
76
|
+
|
77
|
+
action doctype_end {
|
78
|
+
doctype_end = p
|
79
|
+
|
80
|
+
delegate.doctype(data.byteslice(doctype_begin...doctype_end))
|
81
|
+
}
|
82
|
+
|
83
|
+
action doctype_error {
|
84
|
+
raise ParseError.new("could not parse doctype", buffer, p)
|
85
|
+
}
|
86
|
+
|
87
|
+
action comment_begin {
|
88
|
+
comment_begin = p
|
89
|
+
}
|
90
|
+
|
91
|
+
action comment_end {
|
92
|
+
comment_end = p
|
93
|
+
|
94
|
+
delegate.comment(data.byteslice(comment_begin...comment_end))
|
95
|
+
}
|
96
|
+
|
97
|
+
action comment_error {
|
98
|
+
raise ParseError.new("could not parse comment", buffer, p)
|
99
|
+
}
|
100
|
+
|
101
|
+
action instruction_begin {
|
102
|
+
instruction_begin = p
|
103
|
+
}
|
104
|
+
|
105
|
+
action instruction_text_begin {
|
106
|
+
}
|
107
|
+
|
108
|
+
action instruction_text_end {
|
109
|
+
}
|
110
|
+
|
111
|
+
action instruction_end {
|
112
|
+
delegate.instruction(data.byteslice(instruction_begin, p-instruction_begin))
|
113
|
+
}
|
114
|
+
|
115
|
+
action instruction_error {
|
116
|
+
raise ParseError.new("could not parse instruction", buffer, p)
|
117
|
+
}
|
118
|
+
|
119
|
+
action tag_name {
|
120
|
+
self_closing = false
|
121
|
+
|
122
|
+
delegate.open_tag_begin(data.byteslice(identifier_begin...identifier_end), identifier_begin)
|
123
|
+
}
|
124
|
+
|
125
|
+
action tag_opening_begin {
|
126
|
+
}
|
127
|
+
|
128
|
+
action tag_self_closing {
|
129
|
+
self_closing = true
|
130
|
+
}
|
131
|
+
|
132
|
+
action attribute_begin {
|
133
|
+
has_value = false
|
134
|
+
pcdata = ""
|
135
|
+
}
|
136
|
+
|
137
|
+
action attribute_value {
|
138
|
+
has_value = true
|
139
|
+
}
|
140
|
+
|
141
|
+
action attribute_empty {
|
142
|
+
has_value = true
|
143
|
+
}
|
144
|
+
|
145
|
+
action attribute {
|
146
|
+
if has_value
|
147
|
+
pcdata = MarkupString.raw(pcdata) unless has_entities
|
148
|
+
|
149
|
+
value = pcdata
|
150
|
+
else
|
151
|
+
value = true
|
152
|
+
end
|
153
|
+
|
154
|
+
delegate.attribute(data.byteslice(identifier_begin...identifier_end), value)
|
155
|
+
}
|
156
|
+
|
157
|
+
action tag_opening_end {
|
158
|
+
delegate.open_tag_end(self_closing)
|
159
|
+
}
|
160
|
+
|
161
|
+
action tag_closing_begin {
|
162
|
+
}
|
163
|
+
|
164
|
+
action tag_closing_end {
|
165
|
+
delegate.close_tag(data.byteslice(identifier_begin...identifier_end), identifier_begin)
|
166
|
+
}
|
167
|
+
|
168
|
+
action tag_error {
|
169
|
+
raise ParseError.new("could not parse tag", buffer, p)
|
170
|
+
}
|
171
|
+
|
172
|
+
action cdata_begin {
|
173
|
+
cdata_begin = p
|
174
|
+
}
|
175
|
+
|
176
|
+
action cdata_end {
|
177
|
+
cdata_end = p
|
178
|
+
|
179
|
+
delegate.cdata(data.byteslice(cdata_begin...cdata_end))
|
180
|
+
}
|
181
|
+
|
182
|
+
action cdata_error {
|
183
|
+
raise ParseError.new("could not parse cdata", buffer, p)
|
184
|
+
}
|
185
|
+
|
186
|
+
# This magic ensures that we process bytes.
|
187
|
+
getkey bytes[p];
|
188
|
+
|
189
|
+
include markup "xrb/markup.rl";
|
190
|
+
}%%
|
191
|
+
|
192
|
+
require_relative '../error'
|
193
|
+
|
194
|
+
module XRB
|
195
|
+
module Fallback
|
196
|
+
%% write data;
|
197
|
+
|
198
|
+
def self.parse_markup(buffer, delegate, entities)
|
199
|
+
data = buffer.read
|
200
|
+
bytes = data.bytes
|
201
|
+
|
202
|
+
p = 0
|
203
|
+
# Must set pe here or it gets incorrectly set to data.length
|
204
|
+
pe = eof = data.bytesize
|
205
|
+
stack = []
|
206
|
+
|
207
|
+
pcdata = nil
|
208
|
+
characters_begin = characters_end = nil
|
209
|
+
entity_begin = entity_end = nil
|
210
|
+
identifier_begin = identifier_end = nil
|
211
|
+
doctype_begin = doctype_end = nil
|
212
|
+
comment_begin = comment_end = nil
|
213
|
+
instruction_begin = instruction_end = nil
|
214
|
+
cdata_begin = cdata_end = nil
|
215
|
+
has_entities = has_value = false
|
216
|
+
|
217
|
+
%% write init;
|
218
|
+
%% write exec;
|
219
|
+
|
220
|
+
if p != eof
|
221
|
+
raise ParseError.new("could not consume all input", buffer, p)
|
222
|
+
end
|
223
|
+
|
224
|
+
return nil
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|