json-parser 0.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.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Dario Rexin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = recur
2
+
3
+ * http://github.com/drexin/json-parser
4
+
5
+ == Description:
6
+
7
+ A simple JSON parser
8
+
9
+ == Install
10
+
11
+ sudo gem install json-parser
12
+
13
+ == Usage
14
+
15
+ require 'json'
16
+
17
+ str = {"foo" => "bar", "int" => 3, "arr" => [1,2,3] }
18
+
19
+ puts JSON.parse(str)
20
+
21
+ == License:
22
+
23
+ The MIT License
24
+
25
+ Copyright (c) 2010 Dario Rexin
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ "Software"), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
41
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
42
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
43
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
44
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ #
2
+ # To change this template, choose Tools | Templates
3
+ # and open the template in the editor.
4
+
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+ require 'rake/rdoctask'
10
+ require 'rspec/core/rake_task'
11
+
12
+ Rake::RDocTask.new do |rdoc|
13
+ files =['LICENSE', 'lib/**/*.rb']
14
+ rdoc.rdoc_files.add(files)
15
+ rdoc.title = "json-parser Docs"
16
+ rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
17
+ rdoc.options << '--line-numbers'
18
+ end
19
+
20
+ desc "Run all specs"
21
+ RSpec::Core::RakeTask.new('spec') do |t|
22
+ t.rspec_opts = ["--color"]
23
+ end
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'json-parser/generator'
5
+ require 'json-parser/parser'
6
+
7
+ module JSON
8
+ def self.parse(str)
9
+ Generator.new.apply(Parser.new.parse(str))
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ require 'parslet'
2
+
3
+ module JSON
4
+ class Generator < Parslet::Transform
5
+ rule(:integer => simple(:integer)) { integer.to_i }
6
+ rule(:null => simple(:null)) { nil }
7
+ rule(:float => simple(:float)) { float.to_f }
8
+ rule(:string => simple(:string)) { string }
9
+ rule(:boolean => simple(:boolean)) { boolean == "true" }
10
+ rule(:array => subtree(:arr)) { arr }
11
+ rule(:key => simple(:key), :value => subtree(:value)) { {key => value} }
12
+ rule(:hash => subtree(:values)) { values.inject{|a,b| a.merge(b)} }
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ require 'parslet'
2
+
3
+ module JSON
4
+ class Parser < Parslet::Parser
5
+ rule(:string) { str('"') >>
6
+ (
7
+ str('\\') >> any |
8
+ str('"').absnt? >> any
9
+ ).repeat.as(:string) >>
10
+ str('"') }
11
+ rule(:float) { (integer.maybe >> str('.') >> unsigned_int).as(:float) }
12
+ rule(:unsigned_int) { match('[0-9]').repeat(1) }
13
+ rule(:integer) { (str('-').maybe >> unsigned_int).as(:integer) }
14
+ rule(:number) { integer | float }
15
+ rule(:boolean) { (str('true') | str('false')).as(:boolean) }
16
+ rule(:null) { str('null').as(:null) }
17
+ rule(:space) { match('\s').repeat(1) }
18
+ rule(:space?) { space.maybe }
19
+ rule(:value) { string | number | array | boolean | null | hash }
20
+ rule(:array) { str('[') >> (value.repeat(1,1) >> (space? >> (str(',') >> space? >> value)).repeat).maybe.as(:array) >> str(']') }
21
+ rule(:hash_entry) { (string.as(:key) >> space? >> str(":") >> space? >> value.as(:value)) }
22
+ rule(:hash) { space? >> (str('{') >> space? >> (
23
+ hash_entry.repeat(1,1) >> (
24
+ str(",") >> space? >> hash_entry
25
+ ).repeat
26
+ ).maybe.as(:hash) >> space? >> str('}')) >> space? }
27
+ rule(:json) { space? >> array | hash >> space? }
28
+ root(:json)
29
+ end
30
+ end
31
+
@@ -0,0 +1,3 @@
1
+ module JSON
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json-parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Dario Rexin
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-02-07 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: parslet
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 1
31
+ - 1
32
+ version: 1.1.1
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: A simple JSON parser
36
+ email: dario.rexin@r3-tech.de
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - LICENSE
46
+ - Rakefile
47
+ - lib/json-parser/generator.rb
48
+ - lib/json-parser/parser.rb
49
+ - lib/json-parser/version.rb
50
+ - lib/json-parser.rb
51
+ - README.rdoc
52
+ has_rdoc: true
53
+ homepage: http://github.com/drexin/json-parser
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: "#{s.name}-#{s.version}"
84
+ test_files: []
85
+