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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db0148117c4f1e97e7a59f11c194b3ad895a993e972d9d13cd9a705764e2fd8d
4
- data.tar.gz: 218b29012c65b31f756d0ad021e53004d304c7b8cef140fbb9efaeefb542d868
3
+ metadata.gz: df5a17869e913257724d807549b613959e6249ccf09d44b40da9f340e42e2b3d
4
+ data.tar.gz: 7a727978ca94518a3f1d8557ecf2c47387a191018ee7f68185911cdfe1f1c1f8
5
5
  SHA512:
6
- metadata.gz: 954f20f2dad9611b23aa7f40f284a9b1b6121dc434ae7e2d3c252f5292c95130d479906a814048cc46ee4080e2edd6f1e5b5a977a9d1f3c2bdc8638583960ea3
7
- data.tar.gz: 12f33ea0ff37354f8ae892e809777c8b34e87e552fc8b6a1d58ff7586bb72d0bb4086fc6192840efdbb7f7ef727d20833d9b7111c00f5732e40d6a04d7074aaf
6
+ metadata.gz: a63ec74287d1ffe70d3ed379928ee5df56376b9ea451e62a6ca5b60e539aca1e22948ad4d0a717fab6dfc42625e0dab5f53ae8a4b830bd30fe86a24ce4886062
7
+ data.tar.gz: 640753c339348f29a58fbe8c6023653368757c9a405c41813df3d93cb713b9db0bf86760b9371cd104f900fbed9d6e726716a68f64b332ec96cf42a6b4d283a8
@@ -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
@@ -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
- message = "Unexpected token '#{@current_token.value}'"\
52
- " at line #{@current_token.line} column #{@current_token.start} of the JSON data"
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
 
@@ -1,3 +1,3 @@
1
1
  module Jsonerino
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
@@ -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.1
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-28 00:00:00.000000000 Z
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