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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +1 -0
  3. data/bake/xrb/entities.rb +60 -0
  4. data/bake/xrb/parsers.rb +66 -0
  5. data/ext/Makefile +270 -0
  6. data/ext/XRB_Extension.bundle +0 -0
  7. data/ext/escape.o +0 -0
  8. data/ext/extconf.h +5 -0
  9. data/ext/extconf.rb +21 -0
  10. data/ext/markup.o +0 -0
  11. data/ext/mkmf.log +122 -0
  12. data/ext/query.o +0 -0
  13. data/ext/tag.o +0 -0
  14. data/ext/template.o +0 -0
  15. data/ext/xrb/escape.c +152 -0
  16. data/ext/xrb/escape.h +15 -0
  17. data/ext/xrb/markup.c +1949 -0
  18. data/ext/xrb/markup.h +6 -0
  19. data/ext/xrb/markup.rl +226 -0
  20. data/ext/xrb/query.c +619 -0
  21. data/ext/xrb/query.h +6 -0
  22. data/ext/xrb/query.rl +82 -0
  23. data/ext/xrb/tag.c +204 -0
  24. data/ext/xrb/tag.h +21 -0
  25. data/ext/xrb/template.c +1114 -0
  26. data/ext/xrb/template.h +6 -0
  27. data/ext/xrb/template.rl +77 -0
  28. data/ext/xrb/xrb.c +72 -0
  29. data/ext/xrb/xrb.h +132 -0
  30. data/ext/xrb.o +0 -0
  31. data/lib/xrb/buffer.rb +103 -0
  32. data/lib/xrb/builder.rb +229 -0
  33. data/lib/xrb/entities.rb +2137 -0
  34. data/lib/xrb/entities.xrb +15 -0
  35. data/lib/xrb/error.rb +81 -0
  36. data/lib/xrb/fallback/markup.rb +1657 -0
  37. data/lib/xrb/fallback/markup.rl +227 -0
  38. data/lib/xrb/fallback/query.rb +548 -0
  39. data/lib/xrb/fallback/query.rl +88 -0
  40. data/lib/xrb/fallback/template.rb +829 -0
  41. data/lib/xrb/fallback/template.rl +80 -0
  42. data/lib/xrb/markup.rb +56 -0
  43. data/lib/xrb/native.rb +15 -0
  44. data/lib/xrb/parsers.rb +16 -0
  45. data/lib/xrb/query.rb +80 -0
  46. data/lib/xrb/reference.rb +108 -0
  47. data/lib/xrb/strings.rb +47 -0
  48. data/lib/xrb/tag.rb +115 -0
  49. data/lib/xrb/template.rb +128 -0
  50. data/lib/xrb/uri.rb +100 -0
  51. data/lib/xrb/version.rb +8 -0
  52. data/lib/xrb.rb +11 -0
  53. data/license.md +23 -0
  54. data/readme.md +34 -0
  55. data.tar.gz.sig +0 -0
  56. metadata +118 -58
  57. metadata.gz.sig +2 -0
  58. data/README +0 -60
  59. data/app/helpers/ui_helper.rb +0 -80
  60. data/app/models/xrb/element.rb +0 -9
  61. data/lib/xrb/engine.rb +0 -4
  62. data/rails/init.rb +0 -1
  63. data/xrb.gemspec +0 -12
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+
6
+ module XRB
7
+ # We only support a small subset of markup entities.
8
+ module Entities
9
+ HTML5 = {
10
+ <?r self.each do |string, metadata| ?>
11
+ #{string.gsub(/^&|;$/, '').inspect} => #{metadata['characters'].dump}, # #{metadata['characters'].inspect}
12
+ <?r end ?>
13
+ }
14
+ end
15
+ end
data/lib/xrb/error.rb ADDED
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2016-2024, by Samuel Williams.
5
+
6
+ require_relative 'buffer'
7
+
8
+ module XRB
9
+ class Error < StandardError
10
+ end
11
+
12
+ class ParseError < Error
13
+ def initialize(message, buffer, offset)
14
+ super(message)
15
+
16
+ @buffer = buffer
17
+ @offset = offset
18
+ end
19
+
20
+ def location
21
+ @location ||= Location.new(@buffer.read, @offset)
22
+ end
23
+
24
+ attr :buffer
25
+ attr :path
26
+
27
+ def to_s
28
+ "#{buffer.path}#{location}: #{super}\n#{location.line_text}"
29
+ end
30
+ end
31
+
32
+ class Location
33
+ def initialize(input, offset)
34
+ raise ArgumentError.new("Offset #{index} is past end of input #{input.bytesize}") if offset > input.bytesize
35
+
36
+ @offset = offset
37
+ @line_index = 0
38
+ line_offset = next_line_offset = 0
39
+
40
+ input.each_line do |line|
41
+ line_offset = next_line_offset
42
+ next_line_offset += line.bytesize
43
+
44
+ # Is our input offset within this line?
45
+ if next_line_offset >= offset
46
+ @line_text = line.chomp
47
+ @line_range = line_offset...next_line_offset
48
+ break
49
+ else
50
+ @line_index += 1
51
+ end
52
+ end
53
+ end
54
+
55
+ def to_i
56
+ @offset
57
+ end
58
+
59
+ def to_s
60
+ "[#{self.line_number}:#{self.line_offset}]"
61
+ end
62
+
63
+ # The line that contains the @offset (base 0 indexing).
64
+ attr :line_index
65
+
66
+ # The line index, but base-1.
67
+ def line_number
68
+ @line_index + 1
69
+ end
70
+
71
+ # The byte offset to the start of that line.
72
+ attr :line_range
73
+
74
+ # The number of bytes from the start of the line to the given offset in the input.
75
+ def line_offset
76
+ @offset - @line_range.min
77
+ end
78
+
79
+ attr :line_text
80
+ end
81
+ end