lector 0.0.3 → 0.0.4
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/Gemfile.lock +1 -1
- data/lib/lector/reader.citrus +1 -1
- data/lib/lector/types.rb +2 -2
- data/lib/lector/version.rb +1 -1
- data/lib/lector.rb +3 -2
- data/spec/lector/reader_spec.rb +14 -3
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/lib/lector/reader.citrus
CHANGED
data/lib/lector/types.rb
CHANGED
data/lib/lector/version.rb
CHANGED
data/lib/lector.rb
CHANGED
@@ -8,8 +8,9 @@ end
|
|
8
8
|
module Lector
|
9
9
|
module RubyParse; end
|
10
10
|
def self.read_s(string, opts = {})
|
11
|
-
$_LECTOR_READ_EVAL = opts[:read_eval]
|
12
|
-
|
11
|
+
$_LECTOR_READ_EVAL = opts[:read_eval] || false
|
12
|
+
string_without_comments = $_LECTOR_READ_EVAL ? string : string.gsub(/#[^=].*$/, '')
|
13
|
+
Lector::RubyParse::parse(string_without_comments).val
|
13
14
|
end
|
14
15
|
def self.read_file(file, opts = {})
|
15
16
|
read_s(File.read(file), opts)
|
data/spec/lector/reader_spec.rb
CHANGED
@@ -91,16 +91,27 @@ describe Lector do
|
|
91
91
|
it 'preserves other escaped characters' do
|
92
92
|
Lector::read_s('"a string with a\nnewline"').should == 'a string with a\nnewline'
|
93
93
|
end
|
94
|
+
|
95
|
+
it 'deals with comments' do
|
96
|
+
Lector::read_s("{#Here's a comment in the code.\nx: #And another!\n10}").
|
97
|
+
should == {:x => 10}
|
98
|
+
end
|
94
99
|
end
|
95
100
|
|
96
101
|
context 'read-evaling' do
|
97
|
-
it "
|
98
|
-
|
102
|
+
it "blows up when read-eval is off and there's embedded code" do
|
103
|
+
expect {
|
104
|
+
Lector::read_s("#='1+2'").should == '1+2'
|
105
|
+
}.to raise_error(RuntimeError)
|
99
106
|
end
|
100
|
-
|
107
|
+
|
108
|
+
it "embedded code works when :read_eval is on" do
|
101
109
|
Lector::read_s("#='1+2'", :read_eval => true).should == 3
|
102
110
|
end
|
103
111
|
|
112
|
+
it "copes when strings have comments" do
|
113
|
+
Lector::read_s("[:a#some comment\n,:b,:c]").should == [:a, :b, :c]
|
114
|
+
end
|
104
115
|
end
|
105
116
|
|
106
117
|
context 'reading files' do
|