lector 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lector (0.0.2)
4
+ lector (0.0.4)
5
5
  citrus
6
6
 
7
7
  GEM
@@ -33,7 +33,7 @@ grammar Lector::RubyParse
33
33
  end
34
34
 
35
35
  rule code
36
- ("#=" code:string) <Lector::Types::Code>
36
+ ("#=" string) <Lector::Types::Code>
37
37
  end
38
38
 
39
39
  rule symbol
data/lib/lector/types.rb CHANGED
@@ -14,9 +14,9 @@ module Lector
14
14
  module Code
15
15
  def val
16
16
  if $_LECTOR_READ_EVAL
17
- eval(code.to_s.slice(3..-2))
17
+ eval(to_s.slice(3..-2))
18
18
  else
19
- code.to_s.slice(3..-2)
19
+ raise RuntimeError, "Evaluation isn't allowed if :read_eval is false"
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module Lector
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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
- Lector::RubyParse::parse(string).val
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)
@@ -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 "returns the code when read-eval is off" do
98
- Lector::read_s("#='1+2'").should == '1+2'
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
- it "evals the code when read-eval is on" do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: