lector 0.0.4 → 0.0.5
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/.document +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +24 -27
- data/LICENSE.txt +24 -0
- data/README.md +5 -3
- data/lector.gemspec +3 -2
- data/lib/lector/digits.citrus +23 -0
- data/lib/lector/reader.citrus +14 -9
- data/lib/lector/types.rb +1 -0
- data/lib/lector/version.rb +1 -1
- data/lib/lector.rb +2 -0
- data/spec/lector/reader_spec.rb +151 -95
- metadata +8 -3
data/.document
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,46 +1,42 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
lector (0.0.
|
|
4
|
+
lector (0.0.5)
|
|
5
5
|
citrus
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: http://rubygems.org/
|
|
9
9
|
specs:
|
|
10
10
|
citrus (2.4.1)
|
|
11
|
-
coderay (0.
|
|
11
|
+
coderay (1.0.6)
|
|
12
12
|
diff-lcs (1.1.3)
|
|
13
13
|
ffi (1.0.11)
|
|
14
|
-
guard (1.0.
|
|
14
|
+
guard (1.0.2)
|
|
15
15
|
ffi (>= 0.5.0)
|
|
16
16
|
thor (~> 0.14.6)
|
|
17
|
-
guard-rspec (0.
|
|
18
|
-
guard (>= 0.
|
|
19
|
-
method_source (0.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ruby_parser (>= 2.3.1)
|
|
26
|
-
slop (~> 2.1.0)
|
|
17
|
+
guard-rspec (0.7.0)
|
|
18
|
+
guard (>= 0.10.0)
|
|
19
|
+
method_source (0.7.1)
|
|
20
|
+
multi_json (1.3.4)
|
|
21
|
+
pry (0.9.9.4)
|
|
22
|
+
coderay (~> 1.0.5)
|
|
23
|
+
method_source (~> 0.7.1)
|
|
24
|
+
slop (>= 2.4.4, < 3)
|
|
27
25
|
rake (0.9.2.2)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
rspec-
|
|
31
|
-
rspec-
|
|
32
|
-
|
|
33
|
-
rspec-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
simplecov (0.5.4)
|
|
40
|
-
multi_json (~> 1.0.3)
|
|
26
|
+
rns (0.0.1)
|
|
27
|
+
rspec (2.10.0)
|
|
28
|
+
rspec-core (~> 2.10.0)
|
|
29
|
+
rspec-expectations (~> 2.10.0)
|
|
30
|
+
rspec-mocks (~> 2.10.0)
|
|
31
|
+
rspec-core (2.10.0)
|
|
32
|
+
rspec-expectations (2.10.0)
|
|
33
|
+
diff-lcs (~> 1.1.3)
|
|
34
|
+
rspec-mocks (2.10.0)
|
|
35
|
+
simplecov (0.6.2)
|
|
36
|
+
multi_json (~> 1.3)
|
|
41
37
|
simplecov-html (~> 0.5.3)
|
|
42
38
|
simplecov-html (0.5.3)
|
|
43
|
-
slop (2.
|
|
39
|
+
slop (2.4.4)
|
|
44
40
|
thor (0.14.6)
|
|
45
41
|
|
|
46
42
|
PLATFORMS
|
|
@@ -52,5 +48,6 @@ DEPENDENCIES
|
|
|
52
48
|
lector!
|
|
53
49
|
pry
|
|
54
50
|
rake
|
|
51
|
+
rns
|
|
55
52
|
rspec
|
|
56
53
|
simplecov
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
lector is distributed under the following terms:
|
|
2
|
+
|
|
3
|
+
Copyright (c) Alan Dipert <alan@dipert.org>. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions
|
|
7
|
+
are met:
|
|
8
|
+
1. Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
15
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
22
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
23
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
24
|
+
SUCH DAMAGE.
|
data/README.md
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
`lector` reads Ruby data
|
|
1
|
+
`lector` reads Ruby data from strings or files without necessarily evaluating either.
|
|
2
|
+
|
|
3
|
+
Oh yeah, and the build status? We have one of those: [](http://travis-ci.org/alandipert/lector)
|
|
2
4
|
|
|
3
5
|
# Usage
|
|
4
6
|
|
|
@@ -14,9 +16,9 @@
|
|
|
14
16
|
```
|
|
15
17
|
# read-eval is off by default:
|
|
16
18
|
> Lector::read_s("{three: #='1+2'}")
|
|
17
|
-
|
|
19
|
+
RuntimeError: Evaluation isn't allowed if :read_eval is false
|
|
18
20
|
|
|
19
|
-
# but you
|
|
21
|
+
# but when you turn it on...
|
|
20
22
|
> Lector::read_s("{three: #='1+2'}", :read_eval => true)
|
|
21
23
|
=> {:three=>3}
|
|
22
24
|
```
|
data/lector.gemspec
CHANGED
|
@@ -5,10 +5,11 @@ require "lector/version"
|
|
|
5
5
|
Gem::Specification.new do |s|
|
|
6
6
|
s.name = "lector"
|
|
7
7
|
s.version = Lector::VERSION
|
|
8
|
-
s.authors = ["Alan Dipert", "Michael Fogus", "Alex Redington"]
|
|
9
|
-
s.email = ["alan@dipert.org"]
|
|
8
|
+
s.authors = ["Alan Dipert", "Jon Distad", "Michael Fogus", "Alex Redington"]
|
|
9
|
+
s.email = ["alan@dipert.org", "jon.distad@gmail.com"]
|
|
10
10
|
s.homepage = "http://github.com/alandipert/lector"
|
|
11
11
|
s.summary = %q{A Ruby data reader.}
|
|
12
|
+
s.license = "BSD-new"
|
|
12
13
|
s.description = %q{lector parses Ruby data into Ruby data structures.}
|
|
13
14
|
|
|
14
15
|
s.rubyforge_project = "lector"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
grammar Lector::Digits
|
|
2
|
+
|
|
3
|
+
rule digit
|
|
4
|
+
[0-9] ('_' & [0-9])?
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
rule nonzero
|
|
8
|
+
[1-9] ('_' & [0-9])?
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
rule hexdigit
|
|
12
|
+
[0-9a-fA-F] ('_' & [0-9a-fA-F])?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
rule octaldigit
|
|
16
|
+
[0-7] ('_' & [0-7])?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
rule octalzero
|
|
20
|
+
'0' ('_' & [0-7])?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
data/lib/lector/reader.citrus
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
grammar Lector::RubyParse
|
|
2
2
|
|
|
3
|
+
include Lector::Digits
|
|
4
|
+
|
|
3
5
|
rule ruby_data
|
|
4
6
|
(space* form space*) <Lector::Types::Data>
|
|
5
7
|
end
|
|
@@ -53,26 +55,29 @@ grammar Lector::RubyParse
|
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
rule number
|
|
56
|
-
hex_integer | float | integer
|
|
58
|
+
hex_integer | float | octal_integer | integer
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
rule integer
|
|
62
|
+
([+-]? ('0' | nonzero digit*)) <Lector::Types::Integer>
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
rule hex_integer
|
|
60
|
-
|
|
66
|
+
([+-]? `0x` hexdigit+) <Lector::Types::HexInteger>
|
|
61
67
|
end
|
|
62
68
|
|
|
63
|
-
rule
|
|
64
|
-
(
|
|
65
|
-
| (number:/[-+]?[0-9][eE][-+]?[0-9]+/)) <Lector::Types::Float>
|
|
69
|
+
rule octal_integer
|
|
70
|
+
([+-]? octalzero octaldigit+) <Lector::Types::OctalInteger>
|
|
66
71
|
end
|
|
67
72
|
|
|
68
|
-
rule
|
|
69
|
-
|
|
73
|
+
rule float
|
|
74
|
+
(integer '.' digit+ (`e` integer)?
|
|
75
|
+
| integer `e` integer) <Lector::Types::Float>
|
|
70
76
|
end
|
|
71
77
|
|
|
72
78
|
rule array
|
|
73
|
-
#TODO: Spurious commas should be parse errors.
|
|
74
79
|
('['
|
|
75
|
-
((space* form space* ',')* (space* form space*))
|
|
80
|
+
((space* form space* ',')* (space* form space*)?)
|
|
76
81
|
']') <Lector::Types::Array>
|
|
77
82
|
end
|
|
78
83
|
|
data/lib/lector/types.rb
CHANGED
|
@@ -5,6 +5,7 @@ module Lector
|
|
|
5
5
|
module Nil; def val; nil; end; end
|
|
6
6
|
module Integer; def val; to_i; end; end
|
|
7
7
|
module HexInteger; def val; to_i 16; end; end
|
|
8
|
+
module OctalInteger; def val; to_i 8; end; end
|
|
8
9
|
module Float; def val; to_f; end; end
|
|
9
10
|
module SimpleSymbol; def val; slice(1..-1).to_sym; end; end
|
|
10
11
|
module StringSymbol; def val; slice(2..-2).to_sym; end; end
|
data/lib/lector/version.rb
CHANGED
data/lib/lector.rb
CHANGED
|
@@ -2,11 +2,13 @@ require 'citrus'
|
|
|
2
2
|
require 'lector/types'
|
|
3
3
|
|
|
4
4
|
module Lector
|
|
5
|
+
Citrus.load('lib/lector/digits', :force => true)
|
|
5
6
|
Citrus.load('lib/lector/reader', :force => true)
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
module Lector
|
|
9
10
|
module RubyParse; end
|
|
11
|
+
module Digits; end
|
|
10
12
|
def self.read_s(string, opts = {})
|
|
11
13
|
$_LECTOR_READ_EVAL = opts[:read_eval] || false
|
|
12
14
|
string_without_comments = $_LECTOR_READ_EVAL ? string : string.gsub(/#[^=].*$/, '')
|
data/spec/lector/reader_spec.rb
CHANGED
|
@@ -1,126 +1,182 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[.. spec_helper.rb])
|
|
2
2
|
require 'pry'
|
|
3
3
|
require 'tempfile'
|
|
4
|
+
require 'rns'
|
|
5
|
+
|
|
6
|
+
Rns::using(Lector => [:read_s, :read_file]) do
|
|
7
|
+
describe Lector do
|
|
8
|
+
context 'reading strings' do
|
|
9
|
+
it 'parses integers' do
|
|
10
|
+
read_s("+42").should == 42
|
|
11
|
+
read_s("-42").should == -42
|
|
12
|
+
read_s("42").should == 42
|
|
13
|
+
read_s("-42").should == -42
|
|
14
|
+
read_s("-0").should == 0
|
|
15
|
+
read_s("+0").should == 0
|
|
16
|
+
end
|
|
4
17
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Lector::read_s("-42").should == -42
|
|
12
|
-
Lector::read_s("-0").should == 0
|
|
13
|
-
Lector::read_s("+0").should == 0
|
|
14
|
-
end
|
|
18
|
+
it "parses hex integers" do
|
|
19
|
+
read_s("0x0").should == 0
|
|
20
|
+
read_s("0xF").should == 15
|
|
21
|
+
read_s("+0xF").should == 15
|
|
22
|
+
read_s("-0xF").should == -15
|
|
23
|
+
end
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
it "parses ocatals" do
|
|
26
|
+
read_s("00").should == 0
|
|
27
|
+
read_s("010").should == 8
|
|
28
|
+
read_s("-010").should == -8
|
|
29
|
+
read_s("+010").should == 8
|
|
30
|
+
end
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
it "parses floating point numbers" do
|
|
33
|
+
read_s("1.1").should == 1.1
|
|
34
|
+
read_s("-1.1").should == -1.1
|
|
35
|
+
read_s("-1.21e10").should == -12_100_000_000.0
|
|
36
|
+
read_s("+1.21e10").should == 12_100_000_000.0
|
|
37
|
+
read_s("1e4").should == 10_000
|
|
38
|
+
expect { read_s("1.") }.to raise_error(Citrus::ParseError)
|
|
39
|
+
expect { read_s("1.e5") }.to raise_error(Citrus::ParseError)
|
|
40
|
+
end
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
context "parsing individual underscores in the middle of numbers" do
|
|
43
|
+
it "in integers" do
|
|
44
|
+
read_s("1_0").should == 10
|
|
45
|
+
read_s("1_03_4").should == 1034
|
|
46
|
+
expect { read_s("1_03_4_") }.to raise_error(Citrus::ParseError)
|
|
47
|
+
expect { read_s("1__03_4") }.to raise_error(Citrus::ParseError)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "in octals" do
|
|
51
|
+
read_s("0_1_0").should == 010
|
|
52
|
+
read_s("0_1_03_4").should == 01034
|
|
53
|
+
expect { read_s("0_1_03_4_") }.to raise_error(Citrus::ParseError)
|
|
54
|
+
expect { read_s("0_1__03_4") }.to raise_error(Citrus::ParseError)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "in hex" do
|
|
58
|
+
read_s("0x3_f_0").should == 0x3F0
|
|
59
|
+
read_s("0x1_0D_4").should == 0x10D4
|
|
60
|
+
expect { read_s("0x1_03_4_") }.to raise_error(Citrus::ParseError)
|
|
61
|
+
expect { read_s("0x_1_03_4") }.to raise_error(Citrus::ParseError)
|
|
62
|
+
expect { read_s("0x1__03_4") }.to raise_error(Citrus::ParseError)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "in floats" do
|
|
66
|
+
read_s("1_0.2_3").should == 10.23
|
|
67
|
+
read_s("1_0.2_3e4_5").should == 10.23e45
|
|
68
|
+
expect { read_s("1__0.2") }.to raise_error(Citrus::ParseError)
|
|
69
|
+
expect { read_s("_1_0.2") }.to raise_error(Citrus::ParseError)
|
|
70
|
+
expect { read_s("1._2") }.to raise_error(Citrus::ParseError)
|
|
71
|
+
expect { read_s("1.1__2") }.to raise_error(Citrus::ParseError)
|
|
72
|
+
expect { read_s("1.2_") }.to raise_error(Citrus::ParseError)
|
|
73
|
+
expect { read_s("1.2e1__3") }.to raise_error(Citrus::ParseError)
|
|
74
|
+
expect { read_s("1.2e_3") }.to raise_error(Citrus::ParseError)
|
|
75
|
+
expect { read_s("1.2e3_") }.to raise_error(Citrus::ParseError)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
34
78
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
79
|
+
it "parses true and false" do
|
|
80
|
+
read_s("true").should == true
|
|
81
|
+
read_s("false").should == false
|
|
82
|
+
end
|
|
38
83
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Lector::read_s(':"blah blah"').should == :"blah blah"
|
|
43
|
-
Lector::read_s(":'foo foo'").should == :"foo foo"
|
|
44
|
-
end
|
|
84
|
+
it "parses nil" do
|
|
85
|
+
read_s("nil").should == nil
|
|
86
|
+
end
|
|
45
87
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
88
|
+
it 'parses symbols' do
|
|
89
|
+
read_s(":sym").should == :sym
|
|
90
|
+
read_s(':"blah"').should == :blah
|
|
91
|
+
read_s(':"blah blah"').should == :"blah blah"
|
|
92
|
+
read_s(":'foo foo'").should == :"foo foo"
|
|
93
|
+
end
|
|
49
94
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
it 'parses arrays of single elements' do
|
|
96
|
+
read_s('[42]').should == [42]
|
|
97
|
+
end
|
|
53
98
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
99
|
+
it 'ignores whitespace' do
|
|
100
|
+
read_s("[ 42 ]").should == [42]
|
|
101
|
+
end
|
|
57
102
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Lector::read_s("{:a => 7, :b => 6}").should == {:a => 7, :b => 6}
|
|
62
|
-
Lector::read_s("{:a => 7, b: 6}").should == {:a => 7, :b => 6}
|
|
63
|
-
end
|
|
103
|
+
it 'parses arrays of multiple elements' do
|
|
104
|
+
read_s("[42, -1]").should == [42, -1]
|
|
105
|
+
end
|
|
64
106
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
107
|
+
it 'fails to parse arrays with spurious commas' do
|
|
108
|
+
expect { read_s('[1,,2]') }.to raise_error(Citrus::ParseError)
|
|
109
|
+
end
|
|
68
110
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end
|
|
111
|
+
it 'allows trailing commas in arrays' do
|
|
112
|
+
read_s('[1,2,]').should == [1,2]
|
|
113
|
+
end
|
|
73
114
|
|
|
74
|
-
|
|
75
|
-
|
|
115
|
+
it 'parses hashes' do
|
|
116
|
+
read_s("{a: 7, b: 6}").should == {:a => 7, :b => 6}
|
|
117
|
+
read_s("{b: 6}").should == {:b => 6}
|
|
118
|
+
read_s("{:a => 7, :b => 6}").should == {:a => 7, :b => 6}
|
|
119
|
+
read_s("{:a => 7, b: 6}").should == {:a => 7, :b => 6}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'parses nested collections' do
|
|
123
|
+
read_s("[[1,2], 3, 4]").should == [[1, 2], 3, 4]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'has no problem with hashes of arrays' do
|
|
127
|
+
read_s("{a: [1, 2], b: [3, 4]}").should == {:a => [1, 2], :b => [3, 4]}
|
|
128
|
+
read_s("{:a => [1, 2], :b => [3, 4]}").should == {:a => [1, 2], :b => [3, 4]}
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'copes when data is surrounded by whitespace' do
|
|
132
|
+
read_s("
|
|
76
133
|
{a: 7, b: 6} ").should == {:a => 7, :b => 6}
|
|
77
|
-
|
|
134
|
+
end
|
|
78
135
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
136
|
+
it 'reads double-quoted strings' do
|
|
137
|
+
read_s('"a string by any other name is just as tangly"').should == 'a string by any other name is just as tangly'
|
|
138
|
+
end
|
|
82
139
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
140
|
+
it 'reads single-quoted strings' do
|
|
141
|
+
read_s("'i only have single quotes'").should == 'i only have single quotes'
|
|
142
|
+
end
|
|
86
143
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
144
|
+
it 'reads strings with escaped quotes' do
|
|
145
|
+
read_s('"a string with an \"escaped quote\""').should == 'a string with an "escaped quote"'
|
|
146
|
+
end
|
|
90
147
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
148
|
+
it 'preserves other escaped characters' do
|
|
149
|
+
read_s('"a string with a\nnewline"').should == 'a string with a\nnewline'
|
|
150
|
+
end
|
|
94
151
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
152
|
+
it 'deals with comments' do
|
|
153
|
+
read_s("{#Here's a comment in the code.\nx: #And another!\n10}").
|
|
154
|
+
should == {:x => 10}
|
|
155
|
+
end
|
|
98
156
|
end
|
|
99
|
-
end
|
|
100
157
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}.to raise_error(RuntimeError)
|
|
106
|
-
end
|
|
158
|
+
context 'read-evaling' do
|
|
159
|
+
it "blows up when read-eval is off and there's embedded code" do
|
|
160
|
+
expect { read_s("#='1+2'") }.to raise_error(RuntimeError)
|
|
161
|
+
end
|
|
107
162
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
163
|
+
it "embedded code works when :read_eval is on" do
|
|
164
|
+
read_s("#='1+2'", :read_eval => true).should == 3
|
|
165
|
+
end
|
|
111
166
|
|
|
112
|
-
|
|
113
|
-
|
|
167
|
+
it "copes when strings have comments" do
|
|
168
|
+
read_s("[:a#some comment\n,:b,:c]").should == [:a, :b, :c]
|
|
169
|
+
end
|
|
114
170
|
end
|
|
115
|
-
end
|
|
116
171
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
172
|
+
context 'reading files' do
|
|
173
|
+
it 'should be able to round-trip data to file' do
|
|
174
|
+
hsh = {:a => [1, 2], nil => false, :b => [3, 4], blah: [1.2, {:x => 20}]}
|
|
175
|
+
Tempfile.new('lector').tap do |f|
|
|
176
|
+
f.write(hsh.to_s)
|
|
177
|
+
f.rewind
|
|
178
|
+
read_file(f).should == hsh
|
|
179
|
+
end
|
|
124
180
|
end
|
|
125
181
|
end
|
|
126
182
|
end
|
metadata
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lector
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Alan Dipert
|
|
9
|
+
- Jon Distad
|
|
9
10
|
- Michael Fogus
|
|
10
11
|
- Alex Redington
|
|
11
12
|
autorequire:
|
|
12
13
|
bindir: bin
|
|
13
14
|
cert_chain: []
|
|
14
|
-
date: 2012-05-
|
|
15
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
|
15
16
|
dependencies:
|
|
16
17
|
- !ruby/object:Gem::Dependency
|
|
17
18
|
name: pry
|
|
@@ -112,6 +113,7 @@ dependencies:
|
|
|
112
113
|
description: lector parses Ruby data into Ruby data structures.
|
|
113
114
|
email:
|
|
114
115
|
- alan@dipert.org
|
|
116
|
+
- jon.distad@gmail.com
|
|
115
117
|
executables: []
|
|
116
118
|
extensions: []
|
|
117
119
|
extra_rdoc_files: []
|
|
@@ -123,17 +125,20 @@ files:
|
|
|
123
125
|
- Gemfile
|
|
124
126
|
- Gemfile.lock
|
|
125
127
|
- Guardfile
|
|
128
|
+
- LICENSE.txt
|
|
126
129
|
- README.md
|
|
127
130
|
- Rakefile
|
|
128
131
|
- lector.gemspec
|
|
129
132
|
- lib/lector.rb
|
|
133
|
+
- lib/lector/digits.citrus
|
|
130
134
|
- lib/lector/reader.citrus
|
|
131
135
|
- lib/lector/types.rb
|
|
132
136
|
- lib/lector/version.rb
|
|
133
137
|
- spec/lector/reader_spec.rb
|
|
134
138
|
- spec/spec_helper.rb
|
|
135
139
|
homepage: http://github.com/alandipert/lector
|
|
136
|
-
licenses:
|
|
140
|
+
licenses:
|
|
141
|
+
- BSD-new
|
|
137
142
|
post_install_message:
|
|
138
143
|
rdoc_options: []
|
|
139
144
|
require_paths:
|