rison-rb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +30 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +82 -0
- data/Rakefile +16 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rison.rb +66 -0
- data/lib/rison/array/dumper.rb +18 -0
- data/lib/rison/array/parser.rb +610 -0
- data/lib/rison/array/parser.y +131 -0
- data/lib/rison/dumper.rb +34 -0
- data/lib/rison/object/dumper.rb +18 -0
- data/lib/rison/object/parser.rb +606 -0
- data/lib/rison/object/parser.y +131 -0
- data/lib/rison/parser.rb +596 -0
- data/lib/rison/parser.y +130 -0
- data/lib/rison/version.rb +3 -0
- data/rison-rb.gemspec +33 -0
- metadata +126 -0
data/lib/rison/parser.y
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
class Rison::Parser
|
2
|
+
rule
|
3
|
+
|
4
|
+
target: value
|
5
|
+
|
6
|
+
object: LPAREN RPAREN { result = {} }
|
7
|
+
| LPAREN members RPAREN { result = val[1] }
|
8
|
+
|
9
|
+
members: pair
|
10
|
+
| pair COMMA members { result = val[0].merge(val[2]) }
|
11
|
+
|
12
|
+
pair: key COLON value { result = { val[0] => val[2] } }
|
13
|
+
|
14
|
+
array: EXCLAM LPAREN RPAREN { result = [] }
|
15
|
+
| EXCLAM LPAREN elements RPAREN { result = val[2] }
|
16
|
+
|
17
|
+
elements: value { result = [val[0]] }
|
18
|
+
| value COMMA elements { result = val[2].unshift(val[0]) }
|
19
|
+
|
20
|
+
key: id | string
|
21
|
+
|
22
|
+
value: id | string | number | object | array | bool | null
|
23
|
+
|
24
|
+
bool: EXCLAM T { result = true }
|
25
|
+
| EXCLAM F { result = false }
|
26
|
+
|
27
|
+
null: EXCLAM N { result = nil }
|
28
|
+
|
29
|
+
id: idstart
|
30
|
+
| idstart idchars { result = val[0] + val[1] }
|
31
|
+
|
32
|
+
idchars: idchar
|
33
|
+
| idchar idchars { result = val[0] + val[1] }
|
34
|
+
|
35
|
+
idchar: IDCHAR | idstart | MINUS | DIGIT
|
36
|
+
|
37
|
+
idstart: IDSTART | E | T | F | N | DOT
|
38
|
+
|
39
|
+
string: QUOTE QUOTE { result = '' }
|
40
|
+
| QUOTE strchars QUOTE { result = val[1] }
|
41
|
+
|
42
|
+
strchars: strchar
|
43
|
+
| strchar strchars { result = val[0] + val[1] }
|
44
|
+
|
45
|
+
strchar: STRCHAR
|
46
|
+
| idchar
|
47
|
+
| EXCLAM EXCLAM { result = '!' }
|
48
|
+
| EXCLAM QUOTE { result = "'" }
|
49
|
+
| COLON
|
50
|
+
| LPAREN
|
51
|
+
| RPAREN
|
52
|
+
| COMMA
|
53
|
+
|
54
|
+
number: int { result = val[0].to_i }
|
55
|
+
| int frac { result = "#{val[0]}#{val[1]}".to_f }
|
56
|
+
| int exp { result = "#{val[0]}#{val[1]}".to_f }
|
57
|
+
| int frac exp { result = "#{val[0]}#{val[1]}#{val[2]}".to_f }
|
58
|
+
|
59
|
+
int : DIGIT { result = val[0].to_i }
|
60
|
+
| DIGIT digits { result = "#{val[0]}#{val[1]}".to_i }
|
61
|
+
| MINUS DIGIT { result = "-#{val[1]}".to_i }
|
62
|
+
| MINUS DIGIT digits { result = "-#{val[1]}#{val[2]}".to_i }
|
63
|
+
|
64
|
+
frac: DOT digits { result = "#{val[0]}#{val[1]}" }
|
65
|
+
|
66
|
+
exp: e digits { result = "#{val[0]}#{val[1]}" }
|
67
|
+
|
68
|
+
digits: DIGIT
|
69
|
+
| DIGIT digits { result = "#{val[0]}#{val[1]}" }
|
70
|
+
|
71
|
+
e: E { result = 'e' }
|
72
|
+
| E MINUS { result = "e-" }
|
73
|
+
|
74
|
+
---- inner
|
75
|
+
|
76
|
+
attr_reader :source, :input
|
77
|
+
|
78
|
+
def initialize(source)
|
79
|
+
@source = source
|
80
|
+
@input = StringScanner.new(source)
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.parse(source)
|
84
|
+
self.new(source).do_parse
|
85
|
+
rescue Racc::ParseError => exn
|
86
|
+
raise ParserError.new("#{exn.message} in #{source}")
|
87
|
+
end
|
88
|
+
|
89
|
+
def next_token
|
90
|
+
case
|
91
|
+
when input.eos?
|
92
|
+
[false, false]
|
93
|
+
when input.scan(/'/)
|
94
|
+
[:QUOTE, input.matched]
|
95
|
+
when input.scan(/\(/)
|
96
|
+
[:LPAREN, input.matched]
|
97
|
+
when input.scan(/\)/)
|
98
|
+
[:RPAREN, input.matched]
|
99
|
+
when input.scan(/:/)
|
100
|
+
[:COLON, input.matched]
|
101
|
+
when input.scan(/\./)
|
102
|
+
[:DOT, input.matched]
|
103
|
+
when input.scan(/\,/)
|
104
|
+
[:COMMA, input.matched]
|
105
|
+
when input.scan(/!/)
|
106
|
+
[:EXCLAM, input.matched]
|
107
|
+
when input.scan(/\-/)
|
108
|
+
[:MINUS, input.matched]
|
109
|
+
when input.scan(/e/)
|
110
|
+
[:E, input.matched]
|
111
|
+
when input.scan(/t/)
|
112
|
+
[:T, input.matched]
|
113
|
+
when input.scan(/f/)
|
114
|
+
[:F, input.matched]
|
115
|
+
when input.scan(/n/)
|
116
|
+
[:N, input.matched]
|
117
|
+
# Originally, 0 is not allowed at the beginning of the number, but rison.js accepts this.
|
118
|
+
when input.scan(/[0-9]/)
|
119
|
+
[:DIGIT, input.matched]
|
120
|
+
# IDSTART and IDCHAR should originally accept only the ASCII symbols `-_./~`, but rison.js accepts other symbols.
|
121
|
+
# @see https://rison.io/
|
122
|
+
# @see https://github.com/Nanonid/rison/blob/e64af6c096fd30950ec32cfd48526ca6ee21649d/js/rison.js#L77-L84
|
123
|
+
when input.scan(/[^\-0-9 '!:\(\),\*@\$]/)
|
124
|
+
[:IDSTART, input.matched]
|
125
|
+
when input.scan(/[^ '!:\(\),\*@\$]/)
|
126
|
+
[:IDCHAR, input.matched]
|
127
|
+
when input.scan(/[^\'\!]/)
|
128
|
+
[:STRCHAR, input.matched]
|
129
|
+
end
|
130
|
+
end
|
data/rison-rb.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "rison/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "rison-rb"
|
7
|
+
spec.version = Rison::VERSION
|
8
|
+
spec.authors = ["Kazuma Watanabe"]
|
9
|
+
spec.email = ["watassbass@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{A Ruby implementation for Rison}
|
12
|
+
spec.description = %q{This is a Ruby implementation for Rison that represents compact data in URIs. This module provides a parsing and dumping API like JSON module.}
|
13
|
+
spec.homepage = "https://github.com/wata727/rison-rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/wata727/rison-rb/blob/master/CHANGELOG.md"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "racc", "~> 1.4"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rison-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kazuma Watanabe
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: racc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
description: This is a Ruby implementation for Rison that represents compact data
|
70
|
+
in URIs. This module provides a parsing and dumping API like JSON module.
|
71
|
+
email:
|
72
|
+
- watassbass@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".github/workflows/build.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- lib/rison.rb
|
89
|
+
- lib/rison/array/dumper.rb
|
90
|
+
- lib/rison/array/parser.rb
|
91
|
+
- lib/rison/array/parser.y
|
92
|
+
- lib/rison/dumper.rb
|
93
|
+
- lib/rison/object/dumper.rb
|
94
|
+
- lib/rison/object/parser.rb
|
95
|
+
- lib/rison/object/parser.y
|
96
|
+
- lib/rison/parser.rb
|
97
|
+
- lib/rison/parser.y
|
98
|
+
- lib/rison/version.rb
|
99
|
+
- rison-rb.gemspec
|
100
|
+
homepage: https://github.com/wata727/rison-rb
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata:
|
104
|
+
homepage_uri: https://github.com/wata727/rison-rb
|
105
|
+
source_code_uri: https://github.com/wata727/rison-rb
|
106
|
+
changelog_uri: https://github.com/wata727/rison-rb/blob/master/CHANGELOG.md
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubygems_version: 3.0.6
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: A Ruby implementation for Rison
|
126
|
+
test_files: []
|