jsonerino 0.2.1 → 0.2.2
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 +4 -4
- data/bin/jsonerino.rb +47 -0
- data/lib/jsonerino/parser.rb +5 -2
- data/lib/jsonerino/version.rb +1 -1
- data/spec/jsonerino/parse_error_spec.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df5a17869e913257724d807549b613959e6249ccf09d44b40da9f340e42e2b3d
|
4
|
+
data.tar.gz: 7a727978ca94518a3f1d8557ecf2c47387a191018ee7f68185911cdfe1f1c1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a63ec74287d1ffe70d3ed379928ee5df56376b9ea451e62a6ca5b60e539aca1e22948ad4d0a717fab6dfc42625e0dab5f53ae8a4b830bd30fe86a24ce4886062
|
7
|
+
data.tar.gz: 640753c339348f29a58fbe8c6023653368757c9a405c41813df3d93cb713b9db0bf86760b9371cd104f900fbed9d6e726716a68f64b332ec96cf42a6b4d283a8
|
data/bin/jsonerino.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/bash ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
require_relative '../lib/jsonerino'
|
6
|
+
|
7
|
+
COLORS = ["\u001b[31m", "\u001b[32m"].freeze # [red, green]
|
8
|
+
def colorize(str, color)
|
9
|
+
color + str + "\u001b[0m"
|
10
|
+
end
|
11
|
+
|
12
|
+
path = ARGV[0] || Dir.pwd
|
13
|
+
|
14
|
+
abort('The specified file doesn\'t exist') if !File.exist?(path) && !File.exist?(File.join(Dir.pwd, path))
|
15
|
+
|
16
|
+
path = (Pathname.new path).absolute? ? path : File.join(Dir.pwd, path)
|
17
|
+
|
18
|
+
puts
|
19
|
+
|
20
|
+
if File.file?(path)
|
21
|
+
begin
|
22
|
+
contents = File.read(path)
|
23
|
+
Jsonerino.parse contents
|
24
|
+
rescue StandardError => e
|
25
|
+
puts colorize("The parsing of '#{path}' has failed with error", COLORS[0])
|
26
|
+
puts colorize(e.message, COLORS[0])
|
27
|
+
else
|
28
|
+
puts colorize("The parsing of `#{path}` has succeeded. The file contains valid JSON data", COLORS[1])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
files = Dir["#{path}/**/*.json"]
|
32
|
+
files.each do |filename|
|
33
|
+
puts "Attempting to parse #{filename}...\n\n"
|
34
|
+
begin
|
35
|
+
contents = File.read(filename)
|
36
|
+
Jsonerino.parse contents
|
37
|
+
rescue StandardError => e
|
38
|
+
puts colorize("The parsing of '#{filename}' has failed with error", COLORS[0])
|
39
|
+
puts colorize(e, COLORS[0])
|
40
|
+
else
|
41
|
+
puts colorize("The parsing of `#{filename}` has succeeded. The file contains valid JSON data", COLORS[1])
|
42
|
+
end
|
43
|
+
puts "\n"
|
44
|
+
puts '-' * 40
|
45
|
+
puts "\n\n"
|
46
|
+
end
|
47
|
+
end
|
data/lib/jsonerino/parser.rb
CHANGED
@@ -8,6 +8,7 @@ module Jsonerino
|
|
8
8
|
def initialize(lexer)
|
9
9
|
@lexer = lexer
|
10
10
|
@current_token = lexer.next_token
|
11
|
+
@previous_token = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def parse
|
@@ -43,13 +44,15 @@ module Jsonerino
|
|
43
44
|
end
|
44
45
|
|
45
46
|
value = @current_token.value
|
47
|
+
@previous_token = @current_token
|
46
48
|
@current_token = @lexer.next_token
|
47
49
|
value
|
48
50
|
end
|
49
51
|
|
50
52
|
def raise_unexpected_token
|
51
|
-
|
52
|
-
|
53
|
+
token = @current_token.nil? ? @previous_token : @current_token
|
54
|
+
message = "Unexpected token '#{token.value}'"\
|
55
|
+
" at line #{token.line} column #{token.start} of the JSON data"
|
53
56
|
raise JsonParseError.new, message
|
54
57
|
end
|
55
58
|
|
data/lib/jsonerino/version.rb
CHANGED
@@ -12,9 +12,9 @@ describe Jsonerino do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'Should print out the unexpected token that caused the error' do
|
15
|
-
expect { Jsonerino.parse('{"foo" }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token '}'/)
|
15
|
+
expect { Jsonerino.parse('{"foo" }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token '\}'/)
|
16
16
|
expect { Jsonerino.parse('{"foo": : }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token ':'/)
|
17
|
-
expect { Jsonerino.parse('{"foo": ] }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token ']'/)
|
17
|
+
expect { Jsonerino.parse('{"foo": ] }') }.to raise_error(Jsonerino::JsonParseError, /Unexpected token '\]'/)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'Should throw end of input error when end of input is reached'\
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonerino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WinterCore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,7 +69,8 @@ dependencies:
|
|
69
69
|
description: JSON parser
|
70
70
|
email:
|
71
71
|
- hogobbl@gmail.com
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- jsonerino.rb
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- Gemfile.lock
|
83
84
|
- README.md
|
84
85
|
- Rakefile
|
86
|
+
- bin/jsonerino.rb
|
85
87
|
- jsonerino.gemspec
|
86
88
|
- lib/jsonerino.rb
|
87
89
|
- lib/jsonerino/ast.rb
|