oga 0.1.1-java

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