edn 0.9.2 → 0.9.3
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/CHANGELOG.md +9 -0
- data/README.md +13 -0
- data/lib/edn/parser.rb +7 -31
- data/lib/edn/version.rb +1 -1
- data/lib/parslet/ignore.rb +24 -0
- data/spec/edn/parser_spec.rb +12 -0
- data/spec/edn_spec.rb +15 -5
- data/spec/spec_helper.rb +9 -4
- metadata +6 -4
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -4,6 +4,19 @@
|
|
4
4
|
|
5
5
|
**edn-ruby** is a Ruby library to read and write [edn][edn] (extensible data notation), a subset of Clojure used for transferring data between applications, much like JSON, YAML, or XML.
|
6
6
|
|
7
|
+
## Metadata
|
8
|
+
|
9
|
+
tags and metadata do not work together
|
10
|
+
|
11
|
+
metadata keys can be symbols, keywords, or strings
|
12
|
+
|
13
|
+
only collections and symbols can have metadata
|
14
|
+
|
15
|
+
^foo => ^{:tag foo}
|
16
|
+
^:foo => ^{:foo true}
|
17
|
+
These do stack.
|
18
|
+
|
19
|
+
|
7
20
|
## Installation
|
8
21
|
|
9
22
|
Add this line to your application's Gemfile:
|
data/lib/edn/parser.rb
CHANGED
@@ -1,29 +1,5 @@
|
|
1
1
|
require 'parslet'
|
2
|
-
|
3
|
-
class IgnoreParslet < Parslet::Atoms::Base
|
4
|
-
def initialize(parslet)
|
5
|
-
@parslet = parslet
|
6
|
-
end
|
7
|
-
def to_s_inner(prec)
|
8
|
-
@parslet.to_s(prec)
|
9
|
-
end
|
10
|
-
def try(source, context)
|
11
|
-
success, value = result = @parslet.try(source, context)
|
12
|
-
|
13
|
-
return succ(nil) if success
|
14
|
-
return result
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module IgnoreDSL
|
19
|
-
def ignore
|
20
|
-
IgnoreParslet.new(self)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class Parslet::Atoms::Base
|
25
|
-
include IgnoreDSL
|
26
|
-
end
|
2
|
+
require 'parslet/ignore'
|
27
3
|
|
28
4
|
module EDN
|
29
5
|
class Parser < Parslet::Parser
|
@@ -90,13 +66,13 @@ module EDN
|
|
90
66
|
# Primitives
|
91
67
|
|
92
68
|
rule(:integer) {
|
93
|
-
(
|
69
|
+
(match['\-\+'].maybe >>
|
94
70
|
(str('0') | match('[1-9]') >> digit.repeat)).as(:integer) >>
|
95
71
|
str('N').maybe.as(:precision)
|
96
72
|
}
|
97
73
|
|
98
74
|
rule(:float) {
|
99
|
-
(
|
75
|
+
(match['\-\+'].maybe >>
|
100
76
|
(str('0') | (match('[1-9]') >> digit.repeat)) >>
|
101
77
|
str('.') >> digit.repeat(1) >>
|
102
78
|
(match('[eE]') >> match('[\-+]').maybe >> digit.repeat).maybe).as(:float) >>
|
@@ -111,7 +87,7 @@ module EDN
|
|
111
87
|
|
112
88
|
rule(:character) {
|
113
89
|
str("\\") >>
|
114
|
-
(str('newline') | str('space') | str('tab') |
|
90
|
+
(str('newline') | str('space') | str('tab') | str('return') |
|
115
91
|
match['[:graph:]']).as(:character)
|
116
92
|
}
|
117
93
|
|
@@ -137,11 +113,11 @@ module EDN
|
|
137
113
|
rule(:symbol_chars) {
|
138
114
|
(symbol_first_char >>
|
139
115
|
valid_chars.repeat) |
|
140
|
-
match['
|
116
|
+
match['\-\+\.']
|
141
117
|
}
|
142
118
|
|
143
119
|
rule(:symbol_first_char) {
|
144
|
-
(match['
|
120
|
+
(match['\-\+\.'] >> match['0-9'].absent? |
|
145
121
|
match['\#\:0-9'].absent?) >> valid_chars
|
146
122
|
}
|
147
123
|
|
@@ -150,7 +126,7 @@ module EDN
|
|
150
126
|
}
|
151
127
|
|
152
128
|
rule(:sym_punct) {
|
153
|
-
match['
|
129
|
+
match['\.\*\+\!\-\?\$_%&=:#']
|
154
130
|
}
|
155
131
|
|
156
132
|
rule(:digit) {
|
data/lib/edn/version.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
class IgnoreParslet < Parslet::Atoms::Base
|
2
|
+
def initialize(parslet)
|
3
|
+
@parslet = parslet
|
4
|
+
end
|
5
|
+
def to_s_inner(prec)
|
6
|
+
@parslet.to_s(prec)
|
7
|
+
end
|
8
|
+
def try(source, context)
|
9
|
+
success, value = result = @parslet.try(source, context)
|
10
|
+
|
11
|
+
return succ(nil) if success
|
12
|
+
return result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module IgnoreDSL
|
17
|
+
def ignore
|
18
|
+
IgnoreParslet.new(self)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Parslet::Atoms::Base
|
23
|
+
include IgnoreDSL
|
24
|
+
end
|
data/spec/edn/parser_spec.rb
CHANGED
@@ -53,6 +53,12 @@ describe EDN::Parser do
|
|
53
53
|
parser.integer.should parse(int)
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
it "should consume integers prefixed with a +" do
|
58
|
+
rant(RantlyHelpers::INTEGER).each do |int|
|
59
|
+
parser.integer.should parse("+#{int.to_i.abs.to_s}")
|
60
|
+
end
|
61
|
+
end
|
56
62
|
end
|
57
63
|
|
58
64
|
context "float" do
|
@@ -67,6 +73,12 @@ describe EDN::Parser do
|
|
67
73
|
parser.float.should parse(float)
|
68
74
|
end
|
69
75
|
end
|
76
|
+
|
77
|
+
it "should consume floats prefixed with a +" do
|
78
|
+
rant(RantlyHelpers::FLOAT).each do |float|
|
79
|
+
parser.float.should parse("+#{float.to_f.abs.to_s}")
|
80
|
+
end
|
81
|
+
end
|
70
82
|
end
|
71
83
|
|
72
84
|
context "symbol" do
|
data/spec/edn_spec.rb
CHANGED
@@ -54,10 +54,15 @@ describe EDN do
|
|
54
54
|
it "reads any valid value" do
|
55
55
|
values = rant(RantlyHelpers::VALUE)
|
56
56
|
values.each do |value|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
begin
|
58
|
+
if value == "nil"
|
59
|
+
EDN.read(value).should be_nil
|
60
|
+
else
|
61
|
+
EDN.read(value).should_not be_nil
|
62
|
+
end
|
63
|
+
rescue Exception => ex
|
64
|
+
puts "Bad value: #{value}"
|
65
|
+
raise ex
|
61
66
|
end
|
62
67
|
end
|
63
68
|
end
|
@@ -68,7 +73,12 @@ describe EDN do
|
|
68
73
|
values = rant(RantlyHelpers::VALUE)
|
69
74
|
values.each do |value|
|
70
75
|
expect {
|
71
|
-
|
76
|
+
begin
|
77
|
+
EDN.read(value).to_edn
|
78
|
+
rescue Exception => ex
|
79
|
+
puts "Bad value: #{value}"
|
80
|
+
raise ex
|
81
|
+
end
|
72
82
|
}.to_not raise_error
|
73
83
|
end
|
74
84
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,9 +26,10 @@ module RantlyHelpers
|
|
26
26
|
|
27
27
|
PLAIN_SYMBOL = lambda { |_|
|
28
28
|
sized(range(1, 100)) {
|
29
|
-
s = string(/[[:alnum:]]|[
|
30
|
-
guard s =~ /^[A-Za-z
|
31
|
-
guard s !~ /^[
|
29
|
+
s = string(/[[:alnum:]]|[\.\*\+\!\-\?\$_%&=:#]/)
|
30
|
+
# guard s =~ /^[A-Za-z\.\*\+\!\-\?\$_%&=:#]/
|
31
|
+
guard s !~ /^[0-9]/
|
32
|
+
guard s !~ /^[\+\-\.][0-9]/
|
32
33
|
guard s !~ /^[\:\#]/
|
33
34
|
s
|
34
35
|
}
|
@@ -122,7 +123,11 @@ module RantlyHelpers
|
|
122
123
|
}
|
123
124
|
|
124
125
|
INST = lambda { |_|
|
125
|
-
|
126
|
+
begin
|
127
|
+
DateTime.new(range(0, 2500), range(1, 12), range(1, 28), range(0, 23), range(0, 59), range(0, 59), "#{range(-12,12)}").to_edn
|
128
|
+
rescue ArgumentError
|
129
|
+
guard false
|
130
|
+
end
|
126
131
|
}
|
127
132
|
|
128
133
|
def rant(fun, count = REPEAT)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -83,6 +83,7 @@ extensions: []
|
|
83
83
|
extra_rdoc_files: []
|
84
84
|
files:
|
85
85
|
- .gitignore
|
86
|
+
- CHANGELOG.md
|
86
87
|
- Gemfile
|
87
88
|
- LICENSE
|
88
89
|
- README.md
|
@@ -99,6 +100,7 @@ files:
|
|
99
100
|
- lib/edn/type/uuid.rb
|
100
101
|
- lib/edn/types.rb
|
101
102
|
- lib/edn/version.rb
|
103
|
+
- lib/parslet/ignore.rb
|
102
104
|
- spec/edn/parser_spec.rb
|
103
105
|
- spec/edn/transform_spec.rb
|
104
106
|
- spec/edn_spec.rb
|
@@ -117,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
119
|
version: '0'
|
118
120
|
segments:
|
119
121
|
- 0
|
120
|
-
hash: -
|
122
|
+
hash: -2167184458695188347
|
121
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
124
|
none: false
|
123
125
|
requirements:
|
@@ -126,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
128
|
version: '0'
|
127
129
|
segments:
|
128
130
|
- 0
|
129
|
-
hash: -
|
131
|
+
hash: -2167184458695188347
|
130
132
|
requirements: []
|
131
133
|
rubyforge_project:
|
132
134
|
rubygems_version: 1.8.23
|