oga 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +13 -0
  3. data/LICENSE +19 -0
  4. data/README.md +171 -0
  5. data/doc/DCO.md +25 -0
  6. data/doc/changelog.md +7 -0
  7. data/doc/css/common.css +76 -0
  8. data/doc/migrating_from_nokogiri.md +169 -0
  9. data/ext/c/extconf.rb +13 -0
  10. data/ext/c/lexer.c +1518 -0
  11. data/ext/c/lexer.h +8 -0
  12. data/ext/c/lexer.rl +121 -0
  13. data/ext/c/liboga.c +6 -0
  14. data/ext/c/liboga.h +11 -0
  15. data/ext/java/Liboga.java +14 -0
  16. data/ext/java/org/liboga/xml/Lexer.java +829 -0
  17. data/ext/java/org/liboga/xml/Lexer.rl +151 -0
  18. data/ext/ragel/base_lexer.rl +323 -0
  19. data/lib/oga.rb +43 -0
  20. data/lib/oga/html/parser.rb +25 -0
  21. data/lib/oga/oga.rb +27 -0
  22. data/lib/oga/version.rb +3 -0
  23. data/lib/oga/xml/attribute.rb +111 -0
  24. data/lib/oga/xml/cdata.rb +24 -0
  25. data/lib/oga/xml/character_node.rb +39 -0
  26. data/lib/oga/xml/comment.rb +24 -0
  27. data/lib/oga/xml/doctype.rb +91 -0
  28. data/lib/oga/xml/document.rb +99 -0
  29. data/lib/oga/xml/element.rb +340 -0
  30. data/lib/oga/xml/lexer.rb +399 -0
  31. data/lib/oga/xml/namespace.rb +42 -0
  32. data/lib/oga/xml/node.rb +175 -0
  33. data/lib/oga/xml/node_set.rb +313 -0
  34. data/lib/oga/xml/parser.rb +556 -0
  35. data/lib/oga/xml/processing_instruction.rb +39 -0
  36. data/lib/oga/xml/pull_parser.rb +166 -0
  37. data/lib/oga/xml/querying.rb +32 -0
  38. data/lib/oga/xml/text.rb +16 -0
  39. data/lib/oga/xml/traversal.rb +48 -0
  40. data/lib/oga/xml/xml_declaration.rb +76 -0
  41. data/lib/oga/xpath/evaluator.rb +1748 -0
  42. data/lib/oga/xpath/lexer.rb +2043 -0
  43. data/lib/oga/xpath/node.rb +10 -0
  44. data/lib/oga/xpath/parser.rb +535 -0
  45. data/oga.gemspec +45 -0
  46. metadata +221 -0
@@ -0,0 +1,10 @@
1
+ module Oga
2
+ module XPath
3
+ ##
4
+ # AST node for XPath expressions.
5
+ #
6
+ class Node < AST::Node
7
+
8
+ end # Node
9
+ end # XPath
10
+ end # Oga
@@ -0,0 +1,535 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.12
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ module Oga
9
+ module XPath
10
+ class Parser < Racc::Parser
11
+
12
+ ##
13
+ # @param [String] data The input to parse.
14
+ #
15
+ def initialize(data)
16
+ @data = data
17
+ @lexer = Lexer.new(data)
18
+ end
19
+
20
+ ##
21
+ # Creates a new XPath node.
22
+ #
23
+ # @param [Symbol] type
24
+ # @param [Array] children
25
+ # @return [Oga::XPath::Node]
26
+ #
27
+ def s(type, *children)
28
+ return Node.new(type, children)
29
+ end
30
+
31
+ ##
32
+ # Yields the next token from the lexer.
33
+ #
34
+ # @yieldparam [Array]
35
+ #
36
+ def yield_next_token
37
+ @lexer.advance do |*args|
38
+ yield args
39
+ end
40
+
41
+ yield [false, false]
42
+ end
43
+
44
+ ##
45
+ # Parses the input and returns the corresponding AST.
46
+ #
47
+ # @example
48
+ # parser = Oga::XPath::Parser.new('//foo')
49
+ # ast = parser.parse
50
+ #
51
+ # @return [Oga::XPath::Node]
52
+ #
53
+ def parse
54
+ ast = yyparse(self, :yield_next_token)
55
+
56
+ return ast
57
+ end
58
+ # vim: set ft=racc:
59
+ ##### State transition tables begin ###
60
+
61
+ racc_action_table = [
62
+ 20, 48, 20, 23, 22, 19, 18, 19, 18, 49,
63
+ 20, 14, 21, 23, 22, 19, 18, 19, 18, 53,
64
+ 20, 14, 21, 23, 22, 19, 18, 24, 20, 71,
65
+ 73, 14, 21, 19, 18, -12, 40, 24, 20, -13,
66
+ -14, 23, 22, 19, 18, 40, 40, 24, 20, 14,
67
+ 21, 23, 22, 19, 18, 47, 77, 25, 20, 14,
68
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
69
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
70
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
71
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
72
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
73
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
74
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
75
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
76
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
77
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
78
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
79
+ 21, 23, 22, 19, 18, 24, nil, nil, 20, 14,
80
+ 21, 23, 22, 19, 18, 24, nil, nil, 26, 14,
81
+ 21, 29, 30, 31, nil, 24, 76, nil, nil, nil,
82
+ 39, 38, nil, nil, nil, 24, nil, 26, 27, 28,
83
+ 29, 30, 31, 32, 33, 34, 35, 36, 37, 39,
84
+ 38, 75, nil, nil, nil, nil, 26, 27, 28, 29,
85
+ 30, 31, 32, 33, 34, 35, 36, 37, 39, 38,
86
+ 26, nil, nil, 29, 30, 31, 32, 33, 34, 35,
87
+ 36, 37, 39, 38, 26, 27, nil, 29, 30, 31,
88
+ 32, 33, 34, 35, 36, 37, 39, 38, 26, 27,
89
+ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
90
+ 39, 38, 26, nil, nil, 29, 30, 31, nil, nil,
91
+ 34, 35, 36, 37, 39, 38, 26, nil, nil, 29,
92
+ 30, 31, 26, nil, nil, 29, 30, 31, 39, 38,
93
+ 34, 35, 36, 37, 39, 38, 26, nil, nil, 29,
94
+ 30, 31, 26, nil, nil, 29, 30, 31, 39, 38,
95
+ nil, nil, nil, nil, 39, 38 ]
96
+
97
+ racc_action_check = [
98
+ 0, 19, 40, 0, 0, 0, 0, 40, 40, 19,
99
+ 76, 0, 0, 76, 76, 76, 76, 20, 20, 25,
100
+ 49, 76, 76, 49, 49, 49, 49, 0, 14, 48,
101
+ 49, 49, 49, 14, 14, 3, 44, 76, 47, 5,
102
+ 8, 47, 47, 47, 47, 68, 12, 49, 39, 47,
103
+ 47, 39, 39, 39, 39, 16, 74, 1, 38, 39,
104
+ 39, 38, 38, 38, 38, 47, nil, nil, 37, 38,
105
+ 38, 37, 37, 37, 37, 39, nil, nil, 31, 37,
106
+ 37, 31, 31, 31, 31, 38, nil, nil, 35, 31,
107
+ 31, 35, 35, 35, 35, 37, nil, nil, 34, 35,
108
+ 35, 34, 34, 34, 34, 31, nil, nil, 33, 34,
109
+ 34, 33, 33, 33, 33, 35, nil, nil, 32, 33,
110
+ 33, 32, 32, 32, 32, 34, nil, nil, 26, 32,
111
+ 32, 26, 26, 26, 26, 33, nil, nil, 27, 26,
112
+ 26, 27, 27, 27, 27, 32, nil, nil, 28, 27,
113
+ 27, 28, 28, 28, 28, 26, nil, nil, 29, 28,
114
+ 28, 29, 29, 29, 29, 27, nil, nil, 30, 29,
115
+ 29, 30, 30, 30, 30, 28, nil, nil, 36, 30,
116
+ 30, 36, 36, 36, 36, 29, nil, nil, 65, 36,
117
+ 36, 65, 65, 65, nil, 30, 72, nil, nil, nil,
118
+ 65, 65, nil, nil, nil, 36, nil, 72, 72, 72,
119
+ 72, 72, 72, 72, 72, 72, 72, 72, 72, 72,
120
+ 72, 70, nil, nil, nil, nil, 70, 70, 70, 70,
121
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
122
+ 55, nil, nil, 55, 55, 55, 55, 55, 55, 55,
123
+ 55, 55, 55, 55, 56, 56, nil, 56, 56, 56,
124
+ 56, 56, 56, 56, 56, 56, 56, 56, 2, 2,
125
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
126
+ 2, 2, 60, nil, nil, 60, 60, 60, nil, nil,
127
+ 60, 60, 60, 60, 60, 60, 62, nil, nil, 62,
128
+ 62, 62, 61, nil, nil, 61, 61, 61, 62, 62,
129
+ 61, 61, 61, 61, 61, 61, 63, nil, nil, 63,
130
+ 63, 63, 64, nil, nil, 64, 64, 64, 63, 63,
131
+ nil, nil, nil, nil, 64, 64 ]
132
+
133
+ racc_action_pointer = [
134
+ -2, 57, 253, 22, nil, 26, nil, nil, 27, nil,
135
+ nil, nil, 33, nil, 26, nil, 46, nil, nil, -2,
136
+ 10, nil, nil, nil, nil, 19, 126, 136, 146, 156,
137
+ 166, 76, 116, 106, 96, 86, 176, 66, 56, 46,
138
+ 0, nil, nil, nil, 23, nil, nil, 36, 22, 18,
139
+ nil, nil, nil, nil, nil, 225, 239, nil, nil, nil,
140
+ 267, 287, 281, 301, 307, 173, nil, nil, 32, nil,
141
+ 211, nil, 192, nil, 44, nil, 8, nil, nil ]
142
+
143
+ racc_action_default = [
144
+ -2, -54, -1, -3, -4, -5, -6, -7, -8, -9,
145
+ -10, -11, -54, -17, -54, -20, -21, -23, -24, -25,
146
+ -43, -50, -51, -52, -53, -54, -54, -54, -54, -54,
147
+ -54, -54, -54, -54, -54, -54, -54, -54, -54, -54,
148
+ -54, -12, -13, -14, -19, -18, -22, -54, -54, -54,
149
+ -42, -44, -45, 79, -28, -29, -30, -31, -32, -33,
150
+ -34, -35, -36, -37, -38, -39, -40, -41, -15, -16,
151
+ -54, -26, -48, -46, -54, -27, -54, -47, -49 ]
152
+
153
+ racc_goto_table = [
154
+ 2, 51, 46, 50, 1, nil, nil, nil, nil, nil,
155
+ nil, nil, nil, 74, nil, 42, 41, 43, 45, 44,
156
+ nil, nil, nil, 52, nil, nil, 54, 55, 56, 57,
157
+ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
158
+ 78, 42, 41, 43, 69, 68, nil, 70 ]
159
+
160
+ racc_goto_check = [
161
+ 2, 14, 16, 18, 1, nil, nil, nil, nil, nil,
162
+ nil, nil, nil, 19, nil, 5, 3, 8, 13, 12,
163
+ nil, nil, nil, 8, nil, nil, 2, 2, 2, 2,
164
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
165
+ 19, 5, 3, 8, 13, 12, nil, 2 ]
166
+
167
+ racc_goto_pointer = [
168
+ nil, 4, 0, 2, nil, 1, nil, nil, 3, nil,
169
+ nil, nil, 5, 4, -19, nil, -14, nil, -17, -36 ]
170
+
171
+ racc_goto_default = [
172
+ nil, nil, 72, 3, 4, 5, 6, 7, 8, 9,
173
+ 10, 11, 12, 13, 15, 16, nil, 17, nil, nil ]
174
+
175
+ racc_reduce_table = [
176
+ 0, 0, :racc_error,
177
+ 1, 31, :_reduce_1,
178
+ 0, 31, :_reduce_2,
179
+ 1, 32, :_reduce_none,
180
+ 1, 32, :_reduce_none,
181
+ 1, 32, :_reduce_none,
182
+ 1, 32, :_reduce_none,
183
+ 1, 32, :_reduce_none,
184
+ 1, 32, :_reduce_none,
185
+ 1, 32, :_reduce_none,
186
+ 1, 32, :_reduce_none,
187
+ 1, 32, :_reduce_none,
188
+ 1, 42, :_reduce_none,
189
+ 1, 42, :_reduce_none,
190
+ 1, 42, :_reduce_none,
191
+ 3, 43, :_reduce_15,
192
+ 3, 43, :_reduce_16,
193
+ 1, 39, :_reduce_17,
194
+ 2, 40, :_reduce_18,
195
+ 2, 40, :_reduce_19,
196
+ 1, 33, :_reduce_20,
197
+ 1, 44, :_reduce_21,
198
+ 2, 44, :_reduce_22,
199
+ 1, 44, :_reduce_23,
200
+ 1, 47, :_reduce_24,
201
+ 1, 45, :_reduce_25,
202
+ 3, 45, :_reduce_26,
203
+ 3, 46, :_reduce_27,
204
+ 3, 34, :_reduce_28,
205
+ 3, 34, :_reduce_29,
206
+ 3, 34, :_reduce_30,
207
+ 3, 34, :_reduce_31,
208
+ 3, 34, :_reduce_32,
209
+ 3, 34, :_reduce_33,
210
+ 3, 34, :_reduce_34,
211
+ 3, 34, :_reduce_35,
212
+ 3, 34, :_reduce_36,
213
+ 3, 34, :_reduce_37,
214
+ 3, 34, :_reduce_38,
215
+ 3, 34, :_reduce_39,
216
+ 3, 34, :_reduce_40,
217
+ 3, 34, :_reduce_41,
218
+ 2, 35, :_reduce_42,
219
+ 1, 35, :_reduce_43,
220
+ 1, 48, :_reduce_none,
221
+ 1, 48, :_reduce_none,
222
+ 3, 38, :_reduce_46,
223
+ 4, 38, :_reduce_47,
224
+ 1, 49, :_reduce_48,
225
+ 3, 49, :_reduce_49,
226
+ 1, 36, :_reduce_50,
227
+ 1, 37, :_reduce_51,
228
+ 1, 37, :_reduce_52,
229
+ 1, 41, :_reduce_53 ]
230
+
231
+ racc_reduce_n = 54
232
+
233
+ racc_shift_n = 79
234
+
235
+ racc_token_table = {
236
+ false => 0,
237
+ :error => 1,
238
+ :T_AXIS => 2,
239
+ :T_COLON => 3,
240
+ :T_COMMA => 4,
241
+ :T_FLOAT => 5,
242
+ :T_INT => 6,
243
+ :T_IDENT => 7,
244
+ :T_TYPE_TEST => 8,
245
+ :T_LBRACK => 9,
246
+ :T_RBRACK => 10,
247
+ :T_LPAREN => 11,
248
+ :T_RPAREN => 12,
249
+ :T_SLASH => 13,
250
+ :T_STRING => 14,
251
+ :T_PIPE => 15,
252
+ :T_AND => 16,
253
+ :T_OR => 17,
254
+ :T_ADD => 18,
255
+ :T_DIV => 19,
256
+ :T_MOD => 20,
257
+ :T_EQ => 21,
258
+ :T_NEQ => 22,
259
+ :T_LT => 23,
260
+ :T_GT => 24,
261
+ :T_LTE => 25,
262
+ :T_GTE => 26,
263
+ :T_SUB => 27,
264
+ :T_MUL => 28,
265
+ :T_VAR => 29 }
266
+
267
+ racc_nt_base = 30
268
+
269
+ racc_use_result_var = false
270
+
271
+ Racc_arg = [
272
+ racc_action_table,
273
+ racc_action_check,
274
+ racc_action_default,
275
+ racc_action_pointer,
276
+ racc_goto_table,
277
+ racc_goto_check,
278
+ racc_goto_default,
279
+ racc_goto_pointer,
280
+ racc_nt_base,
281
+ racc_reduce_table,
282
+ racc_token_table,
283
+ racc_shift_n,
284
+ racc_reduce_n,
285
+ racc_use_result_var ]
286
+
287
+ Racc_token_to_s_table = [
288
+ "$end",
289
+ "error",
290
+ "T_AXIS",
291
+ "T_COLON",
292
+ "T_COMMA",
293
+ "T_FLOAT",
294
+ "T_INT",
295
+ "T_IDENT",
296
+ "T_TYPE_TEST",
297
+ "T_LBRACK",
298
+ "T_RBRACK",
299
+ "T_LPAREN",
300
+ "T_RPAREN",
301
+ "T_SLASH",
302
+ "T_STRING",
303
+ "T_PIPE",
304
+ "T_AND",
305
+ "T_OR",
306
+ "T_ADD",
307
+ "T_DIV",
308
+ "T_MOD",
309
+ "T_EQ",
310
+ "T_NEQ",
311
+ "T_LT",
312
+ "T_GT",
313
+ "T_LTE",
314
+ "T_GTE",
315
+ "T_SUB",
316
+ "T_MUL",
317
+ "T_VAR",
318
+ "$start",
319
+ "xpath",
320
+ "expression",
321
+ "node_test_as_axis",
322
+ "operator",
323
+ "axis",
324
+ "string",
325
+ "number",
326
+ "call",
327
+ "path",
328
+ "absolute_path",
329
+ "variable",
330
+ "path_member",
331
+ "path_members",
332
+ "node_test",
333
+ "node_name",
334
+ "predicate",
335
+ "type_test",
336
+ "axis_value",
337
+ "call_args" ]
338
+
339
+ Racc_debug_parser = false
340
+
341
+ ##### State transition tables end #####
342
+
343
+ # reduce 0 omitted
344
+
345
+ def _reduce_1(val, _values)
346
+ val[0]
347
+ end
348
+
349
+ def _reduce_2(val, _values)
350
+ nil
351
+ end
352
+
353
+ # reduce 3 omitted
354
+
355
+ # reduce 4 omitted
356
+
357
+ # reduce 5 omitted
358
+
359
+ # reduce 6 omitted
360
+
361
+ # reduce 7 omitted
362
+
363
+ # reduce 8 omitted
364
+
365
+ # reduce 9 omitted
366
+
367
+ # reduce 10 omitted
368
+
369
+ # reduce 11 omitted
370
+
371
+ # reduce 12 omitted
372
+
373
+ # reduce 13 omitted
374
+
375
+ # reduce 14 omitted
376
+
377
+ def _reduce_15(val, _values)
378
+ [val[0], val[2]]
379
+ end
380
+
381
+ def _reduce_16(val, _values)
382
+ [val[0], *val[2]]
383
+ end
384
+
385
+ def _reduce_17(val, _values)
386
+ s(:path, *val[0])
387
+ end
388
+
389
+ def _reduce_18(val, _values)
390
+ s(:absolute_path, *val[1])
391
+ end
392
+
393
+ def _reduce_19(val, _values)
394
+ s(:absolute_path, val[1])
395
+ end
396
+
397
+ def _reduce_20(val, _values)
398
+ s(:axis, 'child', val[0])
399
+ end
400
+
401
+ def _reduce_21(val, _values)
402
+ s(:test, *val[0])
403
+ end
404
+
405
+ def _reduce_22(val, _values)
406
+ s(:test, *val[0], val[1])
407
+ end
408
+
409
+ def _reduce_23(val, _values)
410
+ val[0]
411
+ end
412
+
413
+ def _reduce_24(val, _values)
414
+ s(:type_test, val[0])
415
+ end
416
+
417
+ def _reduce_25(val, _values)
418
+ [nil, val[0]]
419
+ end
420
+
421
+ def _reduce_26(val, _values)
422
+ [val[0], val[2]]
423
+ end
424
+
425
+ def _reduce_27(val, _values)
426
+ val[1]
427
+ end
428
+
429
+ def _reduce_28(val, _values)
430
+ s(:pipe, val[0], val[2])
431
+ end
432
+
433
+ def _reduce_29(val, _values)
434
+ s(:and, val[0], val[2])
435
+ end
436
+
437
+ def _reduce_30(val, _values)
438
+ s(:or, val[0], val[2])
439
+ end
440
+
441
+ def _reduce_31(val, _values)
442
+ s(:add, val[0], val[2])
443
+ end
444
+
445
+ def _reduce_32(val, _values)
446
+ s(:div, val[0], val[2])
447
+ end
448
+
449
+ def _reduce_33(val, _values)
450
+ s(:mod, val[0], val[2])
451
+ end
452
+
453
+ def _reduce_34(val, _values)
454
+ s(:eq, val[0], val[2])
455
+ end
456
+
457
+ def _reduce_35(val, _values)
458
+ s(:neq, val[0], val[2])
459
+ end
460
+
461
+ def _reduce_36(val, _values)
462
+ s(:lt, val[0], val[2])
463
+ end
464
+
465
+ def _reduce_37(val, _values)
466
+ s(:gt, val[0], val[2])
467
+ end
468
+
469
+ def _reduce_38(val, _values)
470
+ s(:lte, val[0], val[2])
471
+ end
472
+
473
+ def _reduce_39(val, _values)
474
+ s(:gte, val[0], val[2])
475
+ end
476
+
477
+ def _reduce_40(val, _values)
478
+ s(:mul, val[0], val[2])
479
+ end
480
+
481
+ def _reduce_41(val, _values)
482
+ s(:sub, val[0], val[2])
483
+ end
484
+
485
+ def _reduce_42(val, _values)
486
+ s(:axis, val[0], val[1])
487
+ end
488
+
489
+ def _reduce_43(val, _values)
490
+ s(:axis, val[0])
491
+ end
492
+
493
+ # reduce 44 omitted
494
+
495
+ # reduce 45 omitted
496
+
497
+ def _reduce_46(val, _values)
498
+ s(:call, val[0])
499
+ end
500
+
501
+ def _reduce_47(val, _values)
502
+ s(:call, val[0], *val[2])
503
+ end
504
+
505
+ def _reduce_48(val, _values)
506
+ val
507
+ end
508
+
509
+ def _reduce_49(val, _values)
510
+ val[2].unshift(val[0])
511
+ end
512
+
513
+ def _reduce_50(val, _values)
514
+ s(:string, val[0])
515
+ end
516
+
517
+ def _reduce_51(val, _values)
518
+ s(:int, val[0])
519
+ end
520
+
521
+ def _reduce_52(val, _values)
522
+ s(:float, val[0])
523
+ end
524
+
525
+ def _reduce_53(val, _values)
526
+ s(:var, val[0])
527
+ end
528
+
529
+ def _reduce_none(val, _values)
530
+ val[0]
531
+ end
532
+
533
+ end # class Parser
534
+ end # module XPath
535
+ end # module Oga