toml-rb 0.1.3 → 0.1.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/README.md CHANGED
@@ -3,8 +3,12 @@ toml-rb
3
3
 
4
4
  Formerly known as __toml_parser-ruby__.
5
5
 
6
- A [TOML](https://github.com/mojombo/toml) parser using [Citrus](http://mjijackson.com/citrus/example.html) library.
6
+ A [TOML](https://github.com/mojombo/toml) parser using [Citrus](http://mjijackson.com/citrus) library.
7
7
 
8
+ [![Gem Version](https://badge.fury.io/rb/toml-rb.png)](http://badge.fury.io/rb/toml-rb)
9
+ [![Build Status](https://travis-ci.org/emancu/toml-rb.png)](https://travis-ci.org/emancu/toml-rb)
10
+ [![Code Climate](https://codeclimate.com/github/emancu/toml-rb.png)](https://codeclimate.com/github/emancu/toml-rb)
11
+ [![Dependency Status](https://gemnasium.com/emancu/toml-rb.png)](https://gemnasium.com/emancu/toml-rb)
8
12
 
9
13
  Installation
10
14
  ------------
data/lib/toml.rb CHANGED
@@ -25,7 +25,8 @@ module TOML
25
25
  #
26
26
  #
27
27
  # Returns a Ruby hash representation of the content according to TOML spec.
28
- # Raises ValueOverwriteError if a key is overwritten
28
+ # Raises ValueOverwriteError if a key is overwritten.
29
+ # Raises ParseError if the content has invalid TOML.
29
30
  def self.parse(content, options = {})
30
31
  Parser.new(content, options).hash
31
32
  end
@@ -47,7 +48,8 @@ module TOML
47
48
  #
48
49
  #
49
50
  # Returns a Ruby hash representation of the content.
50
- # Raises ValueOverwriteError if a key is overwritten
51
+ # Raises ValueOverwriteError if a key is overwritten.
52
+ # Raises ParseError if the content has invalid TOML.
51
53
  # Raises Errno::ENOENT if the file cannot be found.
52
54
  # Raises Errno::EACCES if the file cannot be accessed.
53
55
  def self.load_file(path, options = {})
@@ -12,6 +12,6 @@ grammar Helper
12
12
  end
13
13
 
14
14
  rule line_break
15
- ("\n" | "\r\n") { nil }
15
+ (space? "\n" | space? "\r\n") { nil }
16
16
  end
17
17
  end
data/lib/toml/parser.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  module TOML
2
+ class ParseError < StandardError; end
3
+
2
4
  class Parser
3
5
  attr_reader :hash
4
6
 
@@ -7,8 +9,12 @@ module TOML
7
9
  @current = @hash
8
10
  @symbolize_keys = options[:symbolize_keys]
9
11
 
10
- parsed = Document.parse(content)
11
- parsed.matches.map(&:value).compact.each { |m| m.accept_visitor(self) }
12
+ begin
13
+ parsed = Document.parse(content)
14
+ parsed.matches.map(&:value).compact.each { |m| m.accept_visitor(self) }
15
+ rescue Citrus::ParseError => e
16
+ raise ParseError.new(e.message)
17
+ end
12
18
  end
13
19
 
14
20
  # Read about the Visitor pattern
@@ -0,0 +1,60 @@
1
+ require_relative 'helper'
2
+
3
+ class ErrorsTest < Test::Unit::TestCase
4
+
5
+ def test_text_after_keygroup
6
+ str = "[error] if you didn't catch this, your parser is broken"
7
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
8
+ end
9
+
10
+ def test_text_after_string
11
+ str = 'string = "Anything other than tabs, spaces and newline after a '
12
+ str += 'keygroup or key value pair has ended should produce an error '
13
+ str += 'unless it is a comment" like this'
14
+
15
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
16
+ end
17
+
18
+ def test_multiline_array_bad_string
19
+ str =<<-EOS
20
+ array = [
21
+ "This might most likely happen in multiline arrays",
22
+ Like here,
23
+ "or here,
24
+ and here"
25
+ ] End of array comment, forgot the #
26
+ EOS
27
+
28
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
29
+ end
30
+
31
+ def test_multiline_array_string_not_ended
32
+ str =<<-EOS
33
+ array = [
34
+ "This might most likely happen in multiline arrays",
35
+ "or here,
36
+ and here"
37
+ ] End of array comment, forgot the #
38
+ EOS
39
+
40
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
41
+ end
42
+
43
+ def test_text_after_multiline_array
44
+ str =<<-EOS
45
+ array = [
46
+ "This might most likely happen in multiline arrays",
47
+ "or here",
48
+ "and here"
49
+ ] End of array comment, forgot the #
50
+ EOS
51
+
52
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
53
+ end
54
+
55
+ def test_text_after_number
56
+ str = "number = 3.14 pi <--again forgot the #"
57
+ assert_raises(TOML::ParseError){ TOML.parse(str) }
58
+ end
59
+
60
+ end
@@ -3,19 +3,31 @@
3
3
  # This part you'll really hate
4
4
 
5
5
  [the]
6
- test_string = "You'll hate me after this - #" # " Annoying, isn't it?
6
+ test_string = "You'll hate me after this - #" # " Annoying, isn't it?
7
7
 
8
8
  [the.hard]
9
- array = [ "] ", " # "] # ] There you go, parse this!
10
- array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
9
+ test_array = [ "] ", " # "] # ] There you go, parse this!
10
+ test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
11
11
  # You didn't think it'd as easy as chucking out the last #, did you?
12
- another_string = " Same thing, but with a string #"
13
- harder_string = "And when \"'s are in the string, along with # \"" # "and comments are there too"
12
+ another_test_string = " Same thing, but with a string #"
13
+ harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too"
14
14
  # Things will get harder
15
-
15
+
16
16
  [the.hard.bit#]
17
17
  what? = "You don't think some user won't do that?"
18
18
  multi_line_array = [
19
19
  "]",
20
20
  # ] Oh yes I did
21
21
  ]
22
+
23
+ # Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
24
+
25
+ #[error] if you didn't catch this, your parser is broken
26
+ #string = "Anything other than tabs, spaces and newline after a keygroup or key value pair has ended should produce an error unless it is a comment" like this
27
+ #array = [
28
+ # "This might most likely happen in multiline arrays",
29
+ # Like here,
30
+ # "or here,
31
+ # and here"
32
+ # ] End of array comment, forgot the #
33
+ #number = 3.14 pi <--again forgot the #
data/test/toml_test.rb CHANGED
@@ -50,10 +50,10 @@ class TomlTest < Test::Unit::TestCase
50
50
  'the' => {
51
51
  'test_string' => "You'll hate me after this - #",
52
52
  'hard' => {
53
- 'array' => ['] ', ' # '],
54
- 'array2' => ['Test #11 ]proved that', 'Experiment #9 was a success'],
55
- 'another_string' => ' Same thing, but with a string #',
56
- 'harder_string' => "And when \"'s are in the string, along with # \"",
53
+ 'test_array' => ['] ', ' # '],
54
+ 'test_array2' => ['Test #11 ]proved that', 'Experiment #9 was a success'],
55
+ 'another_test_string' => ' Same thing, but with a string #',
56
+ 'harder_test_string' => " And when \"'s are in the string, along with # \"",
57
57
  'bit#' => {
58
58
  'what?' => "You don't think some user won't do that?",
59
59
  'multi_line_array' => [']']
data/toml-rb.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'toml-rb'
3
- s.version = '0.1.3'
3
+ s.version = '0.1.4'
4
4
  s.date = Time.now.strftime('%Y-%m-%d')
5
5
  s.summary = "TOML parser in ruby, for ruby."
6
- s.description = "A TOML parser using Citrus parsing library. Formerly known as 'toml_parser-ruby'. "
6
+ s.description = "A TOML parser using Citrus parsing library. "
7
7
  s.authors = ["Emiliano Mancuso", "Lucas Tolchinsky"]
8
8
  s.email = ['emiliano.mancuso@gmail.com', 'lucas.tolchinsky@gmail.com']
9
9
  s.homepage = 'http://github.com/eMancu/toml-rb'
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toml-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Emiliano Mancuso
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
13
+ date: 2013-10-15 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: citrus
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ! '>='
19
21
  - !ruby/object:Gem::Version
@@ -21,11 +23,12 @@ dependencies:
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ! '>='
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0'
28
- description: ! 'A TOML parser using Citrus parsing library. Formerly known as ''toml_parser-ruby''. '
31
+ description: ! 'A TOML parser using Citrus parsing library. '
29
32
  email:
30
33
  - emiliano.mancuso@gmail.com
31
34
  - lucas.tolchinsky@gmail.com
@@ -46,8 +49,8 @@ files:
46
49
  - lib/toml/grammars/helper.citrus
47
50
  - lib/toml/grammars/primitive.citrus
48
51
  - toml-rb.gemspec
49
- - toml_parser-ruby.gemspec
50
52
  - test/dumper_test.rb
53
+ - test/errors_test.rb
51
54
  - test/example.toml
52
55
  - test/grammar_test.rb
53
56
  - test/hard_example.toml
@@ -57,25 +60,26 @@ files:
57
60
  homepage: http://github.com/eMancu/toml-rb
58
61
  licenses:
59
62
  - MIT
60
- metadata: {}
61
63
  post_install_message:
62
64
  rdoc_options: []
63
65
  require_paths:
64
66
  - lib
65
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
66
69
  requirements:
67
70
  - - ! '>='
68
71
  - !ruby/object:Gem::Version
69
72
  version: '0'
70
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
71
75
  requirements:
72
76
  - - ! '>='
73
77
  - !ruby/object:Gem::Version
74
78
  version: '0'
75
79
  requirements: []
76
80
  rubyforge_project:
77
- rubygems_version: 2.0.3
81
+ rubygems_version: 1.8.25
78
82
  signing_key:
79
- specification_version: 4
83
+ specification_version: 3
80
84
  summary: TOML parser in ruby, for ruby.
81
85
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTg0ZGY1MTk0NzM3MjAxZThkZjRhNWU2MGMxODM2OTBhMTkwZTJiYQ==
5
- data.tar.gz: !binary |-
6
- YTgwMDkwYzQ5ZDExNTJlYjJjMWZkZjFjOTU4MzY5N2I5MWI3MWQ2Zg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YjYyYTczYjRhZGFlMzg2MjU0NjdjZDZkOWE2ZDQ2YmUxNjVlNTUxMDMxNTY5
10
- ZGIxZDgyZjU3YmQ4MjYwMjgwZjVhN2NjMGNjZTBlNGQ3OWU3M2U5MzdiMzM3
11
- NTJhNjI0ZjQxZWQ1YjQ5NTMzZjY3NGYxYWNmNWU3NzlmYjQxZGE=
12
- data.tar.gz: !binary |-
13
- NjY3ODY1MDA4Y2M5ZWE1ZWZhNGE2ZGQ3ZjkxMjBmODVkM2EzNDRiNjc2ZTE4
14
- Mjk4ZGYzZmZhNjhjMjE0MDMxODk3NTg1MDM5MTkyYzgyMGQ0Y2MyZGE0M2Ji
15
- MzEyNzYwZjQzZTU5NTE1YTc4NDNhMTkxYTg4ZWRhNGY3ZmNkMmY=
@@ -1,28 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = 'toml_parser-ruby'
3
- s.version = '0.1.0'
4
- s.date = Time.now.strftime('%Y-%m-%d')
5
- s.summary = "TOML parser in ruby, for ruby."
6
- s.description = "DEPRECATED by 'toml-rb' gem.\n A TOML parser using Citrus parsing library"
7
- s.authors = ["Emiliano Mancuso"]
8
- s.email = 'emiliano.mancuso@gmail.com'
9
- s.homepage = 'http://github.com/eMancu/toml_parser-ruby'
10
- s.license = "MIT"
11
-
12
- s.files = Dir[
13
- "README.md",
14
- "Rakefile",
15
- "lib/**/*.rb",
16
- "*.gemspec",
17
- "test/*.*"
18
- ]
19
-
20
- s.add_dependency "citrus"
21
-
22
-
23
- s.post_install_message = <<-MESSAGE
24
- ! The 'toml_parser-ruby' gem has been deprecated and has been replaced by 'toml-rb'.
25
- ! See: https://rubygems.org/gems/toml-rb
26
- ! And: https://github.com/eMancu/toml-rb
27
- MESSAGE
28
- end