literal_parser 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 28871bb27419b6dfc757d953bd2f6f5ed2415e0c
4
+ data.tar.gz: 3a056f983667edb3df7f96854b901c522f1ef7d8
5
+ SHA512:
6
+ metadata.gz: 794cca369d91f721ca86ba72686d1d92060576ccc151b1947ef74614529b3b6557c87f5aa0ebaf07cea1acb6e7671a2ae929f5f32516469b62d5e8cb40b30558
7
+ data.tar.gz: 15b76587ba6c95a9bd68dfd14218648edc4f96747488142c4ae80ac262aad8dfd7780f47e727ec19924baf26c3a23084c2025e8900fb24f4d4962bab84ded455
@@ -116,7 +116,9 @@ class LiteralParser
116
116
 
117
117
  RRegexp = %r{/((?:[^\\/]+|\\.)*)/([imxnNeEsSuU]*)} # Match a regular expression
118
118
 
119
- RSymbol = /:\w+|:#{RSString}|:#{RDString}/ # Match a symbol
119
+ RSymbol = /:[A-Za-z_]\w*|:#{RSString}|:#{RDString}/ # Match a symbol
120
+
121
+ RHashKeySymbol = /([A-Za-z_]\w*):/ # Match a symbol used as key in a Hash
120
122
 
121
123
  RDate = /(\d{4})-(\d{2})-(\d{2})/ # Match a date
122
124
 
@@ -257,13 +259,23 @@ class LiteralParser
257
259
  if @scanner.scan(RHashEnd)
258
260
  value
259
261
  else
260
- key = scan_value
261
- raise SyntaxError, "Expected =>" unless @scanner.scan(RHashArrow)
262
+ if @scanner.scan(RHashKeySymbol)
263
+ key = @scanner[1].to_sym
264
+ @scanner.scan(RHashVoid)
265
+ else
266
+ key = scan_value
267
+ raise SyntaxError, "Expected =>" unless @scanner.scan(RHashArrow)
268
+ end
262
269
  val = scan_value
263
270
  value[key] = val
264
271
  while @scanner.scan(RHashSeparator)
265
- key = scan_value
266
- raise SyntaxError, "Expected =>" unless @scanner.scan(RHashArrow)
272
+ if @scanner.scan(RHashKeySymbol)
273
+ key = @scanner[1].to_sym
274
+ @scanner.scan(RHashVoid)
275
+ else
276
+ key = scan_value
277
+ raise SyntaxError, "Expected =>" unless @scanner.scan(RHashArrow)
278
+ end
267
279
  val = scan_value
268
280
  value[key] = val
269
281
  end
@@ -9,5 +9,5 @@ end
9
9
  class LiteralParser
10
10
 
11
11
  # The version of the LiteralParser library
12
- Version = Gem::Version.new("1.0.0")
12
+ Version = Gem::Version.new("1.0.1")
13
13
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "literal_parser"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
  s.authors = "Stefan Rusterholz"
7
7
  s.email = "stefan.rusterholz@gmail.com"
8
8
  s.homepage = "https://github.com/apeiros/literal_parser"
9
+ s.license = 'BSD 2-Clause'
9
10
 
10
11
  s.description = <<-DESCRIPTION.gsub(/^ /, '').chomp
11
12
  Parse Strings containing ruby literals and return a proper ruby object.
@@ -57,9 +57,9 @@ suite "LiteralParser" do
57
57
  assert_equal expected_array, LiteralParser.parse(array_string)
58
58
  end
59
59
  test "Parse Hash" do
60
- array_string = '{nil => false, true => 123, 12.5 => 2012-05-20, :sym => "str"}'
61
- expected_array = {nil => false, true => 123, 12.5 => Date.civil(2012,5,20), :sym => "str"}
62
- assert_equal expected_array, LiteralParser.parse(array_string)
60
+ hash_string = '{nil => false, true => 123, 12.5 => 2012-05-20, :sym => "str", sym2: 123}'
61
+ expected_hash = {nil => false, true => 123, 12.5 => Date.civil(2012,5,20), :sym => "str", :sym2 => 123}
62
+ assert_equal expected_hash, LiteralParser.parse(hash_string)
63
63
  end
64
64
  test "Parse Constants" do
65
65
  assert_equal Time, LiteralParser.parse('Time')
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: literal_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stefan Rusterholz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Parse Strings containing ruby literals and return a proper ruby object.
15
14
  email: stefan.rusterholz@gmail.com
@@ -26,26 +25,26 @@ files:
26
25
  - Rakefile
27
26
  - README.markdown
28
27
  homepage: https://github.com/apeiros/literal_parser
29
- licenses: []
28
+ licenses:
29
+ - BSD 2-Clause
30
+ metadata: {}
30
31
  post_install_message:
31
32
  rdoc_options: []
32
33
  require_paths:
33
34
  - lib
34
35
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
36
  requirements:
37
- - - ! '>='
37
+ - - '>='
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
41
  requirements:
43
- - - ! '>'
42
+ - - '>'
44
43
  - !ruby/object:Gem::Version
45
44
  version: 1.3.1
46
45
  requirements: []
47
46
  rubyforge_project:
48
- rubygems_version: 1.8.24
47
+ rubygems_version: 2.1.5
49
48
  signing_key:
50
49
  specification_version: 3
51
50
  summary: Parse Strings containing ruby literals and return a proper ruby object.