jiffy 1.0.1

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 (83) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +18 -0
  4. data/LICENSE +20 -0
  5. data/README.md +144 -0
  6. data/bin/jiffy +46 -0
  7. data/jiffy.gemspec +104 -0
  8. data/lib/jiffy/json_outputter.rb +62 -0
  9. data/lib/jiffy/parsers/json.rb +293 -0
  10. data/lib/jiffy/parsers/json.rl +56 -0
  11. data/lib/jiffy/parsers/json_array.rb +306 -0
  12. data/lib/jiffy/parsers/json_array.rl +45 -0
  13. data/lib/jiffy/parsers/json_common.rl +24 -0
  14. data/lib/jiffy/parsers/json_float.rb +269 -0
  15. data/lib/jiffy/parsers/json_float.rl +37 -0
  16. data/lib/jiffy/parsers/json_object.rb +348 -0
  17. data/lib/jiffy/parsers/json_object.rl +58 -0
  18. data/lib/jiffy/parsers/json_string.rb +267 -0
  19. data/lib/jiffy/parsers/json_string.rl +41 -0
  20. data/lib/jiffy/parsers/json_value.rb +346 -0
  21. data/lib/jiffy/parsers/json_value.rl +78 -0
  22. data/lib/jiffy/version.rb +3 -0
  23. data/lib/jiffy.rb +50 -0
  24. data/test/jiffy_test.rb +47 -0
  25. data/test/negative-examples/hexadecimal.json +3 -0
  26. data/test/negative-examples/infinity-value.json +3 -0
  27. data/test/negative-examples/leading-comma.json +3 -0
  28. data/test/negative-examples/leading-zero.json +3 -0
  29. data/test/negative-examples/line-break.json +4 -0
  30. data/test/negative-examples/missing-colon.json +3 -0
  31. data/test/negative-examples/nan-value,json +3 -0
  32. data/test/negative-examples/positive-float.json +3 -0
  33. data/test/negative-examples/positive-integer.json +3 -0
  34. data/test/negative-examples/single-quote.json +3 -0
  35. data/test/negative-examples/string-as-root.json +1 -0
  36. data/test/negative-examples/tab-character.json +3 -0
  37. data/test/negative-examples/trailing-array-seperator.json +3 -0
  38. data/test/negative-examples/trailing-object-seperator.json +3 -0
  39. data/test/negative-examples/true-as-root.json +1 -0
  40. data/test/negative-examples/unclosed-array.json +2 -0
  41. data/test/negative-examples/unclosed-object.json +2 -0
  42. data/test/positive-examples/array-as-root.json +3 -0
  43. data/test/positive-examples/array-nested-inside-array.json +5 -0
  44. data/test/positive-examples/array-nested-inside-object.json +5 -0
  45. data/test/positive-examples/false-value.json +3 -0
  46. data/test/positive-examples/null-value.json +3 -0
  47. data/test/positive-examples/number-1.json +3 -0
  48. data/test/positive-examples/number-10.json +3 -0
  49. data/test/positive-examples/number-11.json +3 -0
  50. data/test/positive-examples/number-12.json +3 -0
  51. data/test/positive-examples/number-13.json +3 -0
  52. data/test/positive-examples/number-14.json +3 -0
  53. data/test/positive-examples/number-15.json +3 -0
  54. data/test/positive-examples/number-16.json +3 -0
  55. data/test/positive-examples/number-17.json +3 -0
  56. data/test/positive-examples/number-18.json +3 -0
  57. data/test/positive-examples/number-19.json +3 -0
  58. data/test/positive-examples/number-2.json +3 -0
  59. data/test/positive-examples/number-20.json +3 -0
  60. data/test/positive-examples/number-3.json +3 -0
  61. data/test/positive-examples/number-4.json +3 -0
  62. data/test/positive-examples/number-5.json +3 -0
  63. data/test/positive-examples/number-6.json +3 -0
  64. data/test/positive-examples/number-7.json +3 -0
  65. data/test/positive-examples/number-8.json +3 -0
  66. data/test/positive-examples/number-9.json +3 -0
  67. data/test/positive-examples/object-as-root.json +3 -0
  68. data/test/positive-examples/object-nested-inside-array.json +5 -0
  69. data/test/positive-examples/object-nested-inside-object.json +5 -0
  70. data/test/positive-examples/seperated-array-values.json +4 -0
  71. data/test/positive-examples/seperated-object-properties.json +4 -0
  72. data/test/positive-examples/string-backspace.json +3 -0
  73. data/test/positive-examples/string-carriage-return.json +3 -0
  74. data/test/positive-examples/string-formfeed.json +3 -0
  75. data/test/positive-examples/string-horizontal-tab.json +3 -0
  76. data/test/positive-examples/string-newline.json +3 -0
  77. data/test/positive-examples/string-quotation.json +3 -0
  78. data/test/positive-examples/string-reverse-solidus.json +3 -0
  79. data/test/positive-examples/string-solidus.json +3 -0
  80. data/test/positive-examples/string-trivial.json +3 -0
  81. data/test/positive-examples/string-unicode.json +3 -0
  82. data/test/positive-examples/true-value.json +3 -0
  83. metadata +155 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe32595cfa71cdbb4d6ab8aadab3da303ced671f
4
+ data.tar.gz: 3db1aeb55a7e6f78ce15a19d2240e4bcb530134c
5
+ SHA512:
6
+ metadata.gz: 4a759a9452c53cdefe2e9d724a53eddb415491104ec8af2c9f1ed1e85d94a6186fdc157352467d61af87052bb283a179d7aaad29bb53e284de0468a19f8f0ac9
7
+ data.tar.gz: e51d267574c1953e73b56d9c96050a2b59ef3d121142900306cfb66a420bc87c5fb3feb39917d8e413be4cfba9bc4d098e32f1872d94a0f7c71a32003b911d0b
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jiffy (1.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.3.3)
10
+ rake (10.3.2)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ jiffy!
17
+ minitest
18
+ rake
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 Jonas Amundsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ Jiffy
2
+ =====
3
+
4
+ [![Build Status](https://travis-ci.org/badeball/jiffy.png)](https://travis-ci.org/badeball/jiffy)
5
+
6
+ A streaming-based JSON formatter in Ruby that utilizes Ragel in order to parse
7
+ and continuously format JSON data. This allows it to achieve a somewhat
8
+ constant memory usage, independent of the input size. This is contrary to
9
+ libraries that translates JSON into its own internal AST or those which simply
10
+ uses JSON#pretty_generate.
11
+
12
+ ## Installation
13
+
14
+ The utility can be installed using `gem`, but is also packaged for Arch Linux.
15
+
16
+ ```
17
+ $ gem install jiffy
18
+ ```
19
+
20
+ It can be installed system-wide using the following options.
21
+
22
+ ```
23
+ $ gem install --no-user-install -i "$(ruby -e'puts Gem.default_dir')" -n /usr/bin jiffy
24
+ ```
25
+
26
+ ### Arch Linux
27
+
28
+ ```
29
+ $ yaourt -Syua ruby-jiffy
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ```ruby
35
+ require 'jiffy'
36
+
37
+ Jiffy.new(in: 'some.json').format
38
+
39
+ # {
40
+ # "menu": {
41
+ # "id": "file",
42
+ # "value": "File",
43
+ # "popup": {
44
+ # "menuitem": [
45
+ # {
46
+ # "value": "New",
47
+ # "onclick": "CreateNewDoc()"
48
+ # },
49
+ # {
50
+ # "value": "Open",
51
+ # "onclick": "OpenDoc()"
52
+ # },
53
+ # {
54
+ # "value": "Close",
55
+ # "onclick": "CloseDoc()"
56
+ # }
57
+ # ]
58
+ # }
59
+ # }
60
+ # }
61
+ ```
62
+
63
+ One can also chose to specify an IO object as input stream.
64
+
65
+ ```ruby
66
+ Jiffy.new(in: File.open('some.json')).format
67
+ ```
68
+
69
+ It is also possible to specify an IO object as output stream.
70
+
71
+ ```ruby
72
+ require 'stringio'
73
+
74
+ out = StringIO.new
75
+
76
+ Jiffy.new(in: 'some.json', out: out).format
77
+ ```
78
+
79
+ ### Command line usage
80
+
81
+ With this tool, one can immediately get a sense of the JSON-structure of a file
82
+ of any size. The executable can read from a file specified as an argument or
83
+ read from standard input.
84
+
85
+ ```
86
+ $ jiffy incredibly-large.json | less
87
+ ```
88
+
89
+ ```
90
+ $ cat incredibly-large.json | jiffy | less
91
+ ```
92
+
93
+ ## Compatibility
94
+
95
+ Tested against the following Ruby versions.
96
+
97
+ * 2.0.0
98
+ * 2.1.0
99
+ * 2.1.1
100
+ * 2.1.2
101
+ * 2.1.3
102
+ * 2.1.4
103
+ * 2.1.5
104
+
105
+ ## Changelog
106
+
107
+ ### 1.0.1
108
+
109
+ * The application is renamed Jiffy.
110
+ * The executable may now read from standard input.
111
+ * SIGTERM and SIGINT is now handled properly and a ruby stacktrace is now shown.
112
+
113
+ ### 1.0.0
114
+
115
+ * ArgumentError is raised instead of custom error classes for each argument.
116
+ * Fixing an issue where unparseable values would raise NameError and not UnparseableError.
117
+ * Unexpected end of input is now properly handled and an UnparseableError is raised.
118
+ * Removing parsing of NaN and Infinity.
119
+
120
+ ### 0.0.6
121
+
122
+ * Correcting an issue where a file was missing from the gemspec.
123
+
124
+ ### 0.0.5
125
+
126
+ * Adding a command line option to show the version number.
127
+
128
+ ### 0.0.4
129
+
130
+ * Fixing an issue where using an IO object as input source would always raise
131
+ an error.
132
+
133
+ ### 0.0.3
134
+
135
+ * Added install instructions to the README.
136
+ * #2: Added command line help text to the executable.
137
+
138
+ ### 0.0.2
139
+
140
+ * #1: The executable now handles closed pipes.
141
+
142
+ ### 0.0.1
143
+
144
+ * Initial work on the project.
data/bin/jiffy ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'jiffy'
5
+ require 'jiffy/version'
6
+
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Usage: jiffy [options] [FILE]"
9
+ opts.separator "Standard input is read when FILE is not present"
10
+ opts.separator ""
11
+
12
+ opts.on_tail("-h", "--help", "Show this message") do
13
+ puts opts
14
+ exit
15
+ end
16
+
17
+ opts.on_tail("-v", "--version", "Print the version number of format-json") do
18
+ puts "jiffy #{Jiffy::VERSION}"
19
+ exit
20
+ end
21
+ end
22
+
23
+ opts.parse!
24
+
25
+ Signal.trap("INT") do
26
+ puts "Aborted"
27
+ exit 1
28
+ end
29
+
30
+ Signal.trap("TERM") do
31
+ puts "Aborted"
32
+ exit 1
33
+ end
34
+
35
+ begin
36
+ if ARGV.empty?
37
+ Jiffy.new(in: STDIN).format
38
+ else
39
+ Jiffy.new(in: ARGF).format
40
+ end
41
+ rescue Jiffy::UnparseableError => e
42
+ $stderr.puts e
43
+ exit! 1
44
+ rescue Errno::EPIPE
45
+ # Do nothing
46
+ end
data/jiffy.gemspec ADDED
@@ -0,0 +1,104 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'jiffy', 'version')
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jiffy'
5
+ s.version = Jiffy::VERSION
6
+ s.license = 'MIT'
7
+ s.date = '2014-12-03'
8
+
9
+ s.summary = 'A streaming-based JSON formatter in Ruby.'
10
+ s.description = 'Jiffy utilizes Ragel in order to parse and continuously format JSON data. This allows it to achieve a constant memory usage, independent of the input size.'
11
+
12
+ s.authors = ['Jonas Amundsen']
13
+ s.email = ['jonasba+gem@gmail.com']
14
+ s.homepage = 'https://github.com/badeball/jiffy'
15
+
16
+ s.executables = 'jiffy'
17
+
18
+ s.files = %w[
19
+ bin/jiffy
20
+ lib/jiffy/parsers/json.rb
21
+ lib/jiffy/parsers/json.rl
22
+ lib/jiffy/parsers/json_array.rb
23
+ lib/jiffy/parsers/json_array.rl
24
+ lib/jiffy/parsers/json_common.rl
25
+ lib/jiffy/parsers/json_float.rb
26
+ lib/jiffy/parsers/json_float.rl
27
+ lib/jiffy/parsers/json_object.rb
28
+ lib/jiffy/parsers/json_object.rl
29
+ lib/jiffy/parsers/json_string.rb
30
+ lib/jiffy/parsers/json_string.rl
31
+ lib/jiffy/parsers/json_value.rb
32
+ lib/jiffy/parsers/json_value.rl
33
+ lib/jiffy/json_outputter.rb
34
+ lib/jiffy/version.rb
35
+ lib/jiffy.rb
36
+ test/negative-examples/hexadecimal.json
37
+ test/negative-examples/infinity-value.json
38
+ test/negative-examples/leading-comma.json
39
+ test/negative-examples/leading-zero.json
40
+ test/negative-examples/line-break.json
41
+ test/negative-examples/missing-colon.json
42
+ test/negative-examples/nan-value,json
43
+ test/negative-examples/positive-float.json
44
+ test/negative-examples/positive-integer.json
45
+ test/negative-examples/single-quote.json
46
+ test/negative-examples/string-as-root.json
47
+ test/negative-examples/tab-character.json
48
+ test/negative-examples/trailing-array-seperator.json
49
+ test/negative-examples/trailing-object-seperator.json
50
+ test/negative-examples/true-as-root.json
51
+ test/negative-examples/unclosed-array.json
52
+ test/negative-examples/unclosed-object.json
53
+ test/positive-examples/array-as-root.json
54
+ test/positive-examples/array-nested-inside-array.json
55
+ test/positive-examples/array-nested-inside-object.json
56
+ test/positive-examples/false-value.json
57
+ test/positive-examples/null-value.json
58
+ test/positive-examples/number-1.json
59
+ test/positive-examples/number-10.json
60
+ test/positive-examples/number-11.json
61
+ test/positive-examples/number-12.json
62
+ test/positive-examples/number-13.json
63
+ test/positive-examples/number-14.json
64
+ test/positive-examples/number-15.json
65
+ test/positive-examples/number-16.json
66
+ test/positive-examples/number-17.json
67
+ test/positive-examples/number-18.json
68
+ test/positive-examples/number-19.json
69
+ test/positive-examples/number-2.json
70
+ test/positive-examples/number-20.json
71
+ test/positive-examples/number-3.json
72
+ test/positive-examples/number-4.json
73
+ test/positive-examples/number-5.json
74
+ test/positive-examples/number-6.json
75
+ test/positive-examples/number-7.json
76
+ test/positive-examples/number-8.json
77
+ test/positive-examples/number-9.json
78
+ test/positive-examples/object-as-root.json
79
+ test/positive-examples/object-nested-inside-array.json
80
+ test/positive-examples/object-nested-inside-object.json
81
+ test/positive-examples/seperated-array-values.json
82
+ test/positive-examples/seperated-object-properties.json
83
+ test/positive-examples/string-backspace.json
84
+ test/positive-examples/string-carriage-return.json
85
+ test/positive-examples/string-formfeed.json
86
+ test/positive-examples/string-horizontal-tab.json
87
+ test/positive-examples/string-newline.json
88
+ test/positive-examples/string-quotation.json
89
+ test/positive-examples/string-reverse-solidus.json
90
+ test/positive-examples/string-solidus.json
91
+ test/positive-examples/string-trivial.json
92
+ test/positive-examples/string-unicode.json
93
+ test/positive-examples/true-value.json
94
+ test/jiffy_test.rb
95
+ Gemfile
96
+ Gemfile.lock
97
+ jiffy.gemspec
98
+ LICENSE
99
+ README.md
100
+ ]
101
+
102
+ s.add_development_dependency('minitest')
103
+ s.add_development_dependency('rake')
104
+ end
@@ -0,0 +1,62 @@
1
+ class Jiffy
2
+ class JsonOutputter
3
+ attr_accessor :out, :indent
4
+
5
+ def initialize(options)
6
+ self.out = options[:out] || $stdout
7
+
8
+ raise ArgumentError, 'Invalid output source' unless out.respond_to? :print
9
+
10
+ self.indent = 0
11
+ end
12
+
13
+ def process_token(token, payload = nil)
14
+ case token
15
+ when :begin_object
16
+ output '{', indent: 1, newline_after: true
17
+ when :end_object
18
+ output '}', indent: -1, newline_before: true
19
+ when :begin_array
20
+ output '[', indent: 1, newline_after: true
21
+ when :end_array
22
+ output ']', indent: -1, newline_before: true
23
+ when :value_separator
24
+ output ',', newline_after: true
25
+ when :name_separator
26
+ output ': '
27
+ when :begin_string, :end_string
28
+ output '"'
29
+ when :null
30
+ output 'null'
31
+ when :nan
32
+ output 'NaN'
33
+ when :inf
34
+ output 'Infinity'
35
+ when :true
36
+ output 'true'
37
+ when :false
38
+ output 'false'
39
+ when :char
40
+ output payload
41
+ when :number
42
+ output payload.to_s
43
+ else
44
+ puts "Unknown token: #{token.inspect}"
45
+ end
46
+ end
47
+
48
+ alias_method :t, :process_token
49
+
50
+ def output(content, options = {})
51
+ self.indent += options[:indent] if options[:indent]
52
+
53
+ if options[:newline_before]
54
+ out.print "\n" << ' ' * self.indent
55
+ end
56
+
57
+ out.print content
58
+
59
+ out.print "\n" << ' ' * self.indent if options[:newline_after]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,293 @@
1
+
2
+ # line 1 "json.rl"
3
+
4
+ # line 27 "json.rl"
5
+
6
+
7
+ class Jiffy
8
+ module Parsers
9
+ module Json
10
+ def initialize(*args)
11
+
12
+ # line 13 "json.rb"
13
+ class << self
14
+ attr_accessor :_json_actions
15
+ private :_json_actions, :_json_actions=
16
+ end
17
+ self._json_actions = [
18
+ 0, 1, 0, 1, 1
19
+ ]
20
+
21
+ class << self
22
+ attr_accessor :_json_key_offsets
23
+ private :_json_key_offsets, :_json_key_offsets=
24
+ end
25
+ self._json_key_offsets = [
26
+ 0, 0, 7, 9, 10, 12, 13, 15,
27
+ 16, 18, 19
28
+ ]
29
+
30
+ class << self
31
+ attr_accessor :_json_trans_keys
32
+ private :_json_trans_keys, :_json_trans_keys=
33
+ end
34
+ self._json_trans_keys = [
35
+ 13, 32, 47, 91, 123, 9, 10, 42,
36
+ 47, 42, 42, 47, 10, 42, 47, 42,
37
+ 42, 47, 10, 13, 32, 47, 9, 10,
38
+ 0
39
+ ]
40
+
41
+ class << self
42
+ attr_accessor :_json_single_lengths
43
+ private :_json_single_lengths, :_json_single_lengths=
44
+ end
45
+ self._json_single_lengths = [
46
+ 0, 5, 2, 1, 2, 1, 2, 1,
47
+ 2, 1, 3
48
+ ]
49
+
50
+ class << self
51
+ attr_accessor :_json_range_lengths
52
+ private :_json_range_lengths, :_json_range_lengths=
53
+ end
54
+ self._json_range_lengths = [
55
+ 0, 1, 0, 0, 0, 0, 0, 0,
56
+ 0, 0, 1
57
+ ]
58
+
59
+ class << self
60
+ attr_accessor :_json_index_offsets
61
+ private :_json_index_offsets, :_json_index_offsets=
62
+ end
63
+ self._json_index_offsets = [
64
+ 0, 0, 7, 10, 12, 15, 17, 20,
65
+ 22, 25, 27
66
+ ]
67
+
68
+ class << self
69
+ attr_accessor :_json_indicies
70
+ private :_json_indicies, :_json_indicies=
71
+ end
72
+ self._json_indicies = [
73
+ 0, 0, 2, 3, 4, 0, 1, 5,
74
+ 6, 1, 7, 5, 7, 0, 5, 0,
75
+ 6, 8, 9, 1, 10, 8, 10, 11,
76
+ 8, 11, 9, 11, 11, 12, 11, 1,
77
+ 0
78
+ ]
79
+
80
+ class << self
81
+ attr_accessor :_json_trans_targs
82
+ private :_json_trans_targs, :_json_trans_targs=
83
+ end
84
+ self._json_trans_targs = [
85
+ 1, 0, 2, 10, 10, 3, 5, 4,
86
+ 7, 9, 8, 10, 6
87
+ ]
88
+
89
+ class << self
90
+ attr_accessor :_json_trans_actions
91
+ private :_json_trans_actions, :_json_trans_actions=
92
+ end
93
+ self._json_trans_actions = [
94
+ 0, 0, 0, 3, 1, 0, 0, 0,
95
+ 0, 0, 0, 0, 0
96
+ ]
97
+
98
+ class << self
99
+ attr_accessor :json_start
100
+ end
101
+ self.json_start = 1;
102
+ class << self
103
+ attr_accessor :json_first_final
104
+ end
105
+ self.json_first_final = 10;
106
+ class << self
107
+ attr_accessor :json_error
108
+ end
109
+ self.json_error = 0;
110
+
111
+ class << self
112
+ attr_accessor :json_en_main
113
+ end
114
+ self.json_en_main = 1;
115
+
116
+
117
+ # line 34 "json.rl"
118
+ super
119
+ end
120
+
121
+ def parse_json
122
+ pe = :ignored
123
+ eof = :ignored
124
+ leftover = []
125
+
126
+
127
+ # line 128 "json.rb"
128
+ begin
129
+ p ||= 0
130
+ pe ||= data.length
131
+ cs = json_start
132
+ end
133
+
134
+ # line 43 "json.rl"
135
+
136
+ while chunk = io.read(1_000_000)
137
+ self.data = leftover + chunk.unpack("c*")
138
+ p ||= 0
139
+ pe = data.length
140
+
141
+
142
+ # line 143 "json.rb"
143
+ begin
144
+ _klen, _trans, _keys, _acts, _nacts = nil
145
+ _goto_level = 0
146
+ _resume = 10
147
+ _eof_trans = 15
148
+ _again = 20
149
+ _test_eof = 30
150
+ _out = 40
151
+ while true
152
+ _trigger_goto = false
153
+ if _goto_level <= 0
154
+ if p == pe
155
+ _goto_level = _test_eof
156
+ next
157
+ end
158
+ if cs == 0
159
+ _goto_level = _out
160
+ next
161
+ end
162
+ end
163
+ if _goto_level <= _resume
164
+ _keys = _json_key_offsets[cs]
165
+ _trans = _json_index_offsets[cs]
166
+ _klen = _json_single_lengths[cs]
167
+ _break_match = false
168
+
169
+ begin
170
+ if _klen > 0
171
+ _lower = _keys
172
+ _upper = _keys + _klen - 1
173
+
174
+ loop do
175
+ break if _upper < _lower
176
+ _mid = _lower + ( (_upper - _lower) >> 1 )
177
+
178
+ if data[p].ord < _json_trans_keys[_mid]
179
+ _upper = _mid - 1
180
+ elsif data[p].ord > _json_trans_keys[_mid]
181
+ _lower = _mid + 1
182
+ else
183
+ _trans += (_mid - _keys)
184
+ _break_match = true
185
+ break
186
+ end
187
+ end # loop
188
+ break if _break_match
189
+ _keys += _klen
190
+ _trans += _klen
191
+ end
192
+ _klen = _json_range_lengths[cs]
193
+ if _klen > 0
194
+ _lower = _keys
195
+ _upper = _keys + (_klen << 1) - 2
196
+ loop do
197
+ break if _upper < _lower
198
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
199
+ if data[p].ord < _json_trans_keys[_mid]
200
+ _upper = _mid - 2
201
+ elsif data[p].ord > _json_trans_keys[_mid+1]
202
+ _lower = _mid + 2
203
+ else
204
+ _trans += ((_mid - _keys) >> 1)
205
+ _break_match = true
206
+ break
207
+ end
208
+ end # loop
209
+ break if _break_match
210
+ _trans += _klen
211
+ end
212
+ end while false
213
+ _trans = _json_indicies[_trans]
214
+ cs = _json_trans_targs[_trans]
215
+ if _json_trans_actions[_trans] != 0
216
+ _acts = _json_trans_actions[_trans]
217
+ _nacts = _json_actions[_acts]
218
+ _acts += 1
219
+ while _nacts > 0
220
+ _nacts -= 1
221
+ _acts += 1
222
+ case _json_actions[_acts - 1]
223
+ when 0 then
224
+ # line 5 "json.rl"
225
+ begin
226
+
227
+ if np = parse_json_object(p, pe)
228
+ begin p = (( np))-1; end
229
+
230
+ else
231
+ p = p - 1;
232
+ begin
233
+ p += 1
234
+ _trigger_goto = true
235
+ _goto_level = _out
236
+ break
237
+ end
238
+
239
+ end
240
+ end
241
+ when 1 then
242
+ # line 14 "json.rl"
243
+ begin
244
+
245
+ if np = parse_json_array(p, pe)
246
+ begin p = (( np))-1; end
247
+
248
+ else
249
+ p = p - 1;
250
+ begin
251
+ p += 1
252
+ _trigger_goto = true
253
+ _goto_level = _out
254
+ break
255
+ end
256
+
257
+ end
258
+ end
259
+ # line 260 "json.rb"
260
+ end # action switch
261
+ end
262
+ end
263
+ if _trigger_goto
264
+ next
265
+ end
266
+ end
267
+ if _goto_level <= _again
268
+ if cs == 0
269
+ _goto_level = _out
270
+ next
271
+ end
272
+ p += 1
273
+ if p != pe
274
+ _goto_level = _resume
275
+ next
276
+ end
277
+ end
278
+ if _goto_level <= _test_eof
279
+ end
280
+ if _goto_level <= _out
281
+ break
282
+ end
283
+ end
284
+ end
285
+
286
+ # line 50 "json.rl"
287
+ end
288
+
289
+ raise_unparseable p unless p == pe
290
+ end
291
+ end
292
+ end
293
+ end