parby 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86b9b440a1902cfc0bf63e95b212df61f2cd6844
4
- data.tar.gz: 1a619e1eb0903d69a64d7db910d544ca82826370
3
+ metadata.gz: 724c425cfa249df29a06d28f8a5ea4a3aa36c9c5
4
+ data.tar.gz: 0140f3ab0caf4706139626f32ecff51ad3ae77dc
5
5
  SHA512:
6
- metadata.gz: 4dde60b0aa97baa80b0536bc73cbd77c11fb2d195a5d3042c51bc3895192102a184c15c60ff8e9849c54287d6625f3324e2cebd9c336cf1fee36efcac8617d88
7
- data.tar.gz: 12347688dc2b62840c14d25bfe3759df98bd3d80da46fd58f43ba84ede40adfff3dec6ccc64fd97c1213eb16876c19d367fe0cd7517a4fa40c8b249c870cf289
6
+ metadata.gz: 509d2272d48d88b1aeff0049f7debd151c51fda7e4d158925d0c33d2b48d663de7653df4f1da01472fee8c491d94a89e3a5c7f77ac1bab5f45fd25175600f5ed
7
+ data.tar.gz: c90483f894f10257a21a229eeda45a49d986ef57d00c313d6d057c1da2df329ca2d7749facd203b431956de1615ca8523e2a673ede8fa8d1f32b6cbb33e118b2
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea/
2
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ Metrics/LineLength:
2
+ # Change the default 80 chars limit value
3
+ Max: 120
4
+
5
+ Style/OneLineConditional:
6
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.3)
5
+ rspec (3.8.0)
6
+ rspec-core (~> 3.8.0)
7
+ rspec-expectations (~> 3.8.0)
8
+ rspec-mocks (~> 3.8.0)
9
+ rspec-core (3.8.0)
10
+ rspec-support (~> 3.8.0)
11
+ rspec-expectations (3.8.2)
12
+ diff-lcs (>= 1.2.0, < 2.0)
13
+ rspec-support (~> 3.8.0)
14
+ rspec-mocks (3.8.0)
15
+ diff-lcs (>= 1.2.0, < 2.0)
16
+ rspec-support (~> 3.8.0)
17
+ rspec-support (3.8.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ rspec (~> 3.0)
24
+
25
+ BUNDLED WITH
26
+ 2.0.1
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2019 Rodrigo Martin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Parby
2
+
3
+ Happy little parser combinators
@@ -1,13 +1,13 @@
1
- require 'parser'
1
+ require_relative 'parser'
2
2
 
3
3
  module Parby
4
4
  # Always yields the value passed to it, no matter the input
5
- def of(value)
5
+ def self.of(value)
6
6
  Parser.new { |input, index| Success.new(index, value, input) }
7
7
  end
8
8
 
9
9
  # Yields the first character that matches predicate, it fails with the given message, otherwise a generic one
10
- def test(predicate, description = nil)
10
+ def self.test(predicate, description = nil)
11
11
  Parser.new do |input, index|
12
12
  found = nil
13
13
  input.split('').each do |character|
@@ -26,7 +26,7 @@ module Parby
26
26
  end
27
27
 
28
28
  # Yields the input, if it matches the regex passed to it
29
- def regexp(regex)
29
+ def self.regexp(regex)
30
30
  # We have to match from the beginning
31
31
  real_regex = /^#{regex}/
32
32
 
@@ -42,17 +42,21 @@ module Parby
42
42
  end
43
43
  end
44
44
 
45
+ def self.regex(regex)
46
+ return self.regexp(regex)
47
+ end
48
+
45
49
  # Searches in the input for one of the given characters (characters can be either a string or an array), and yields it
46
- def one_of(characters)
50
+ def self.one_of(characters)
47
51
  expected = if characters.is_a?(Array) then characters else characters.split('') end
48
52
  test(Proc.new { |c| expected.include?(c) }, expected)
49
53
  end
50
54
 
51
- def none_of(characters)
55
+ def self.none_of(characters)
52
56
  test(Proc.new { |c| !characters.include?(c) }, ["None of #{characters}"])
53
57
  end
54
58
 
55
- def string(str)
59
+ def self.string(str)
56
60
  Parser.new do |input, index|
57
61
  furthest = -1
58
62
 
@@ -78,7 +82,7 @@ module Parby
78
82
  end
79
83
  end
80
84
 
81
- def all
85
+ def self.all
82
86
  Parser.new do |input, index|
83
87
  Success.new(index, input, nil)
84
88
  end
@@ -64,7 +64,7 @@ module Parby
64
64
  end
65
65
 
66
66
  def consuming
67
- self >> all
67
+ self >> Parby.all
68
68
  end
69
69
  end
70
70
  end
File without changes
@@ -0,0 +1,3 @@
1
+ module Parby
2
+ VERSION = "0.2.0"
3
+ end
data/lib/parby.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'parby/parser'
2
+ require 'parby/combinators'
3
+ require 'parby/result'
data/parby.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'parby/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'parby'
7
+ s.version = Parby::VERSION
8
+ s.date = '2019-02-17'
9
+ s.summary = 'Happy little parser combinators'
10
+ s.authors = ['Rodrigo Martin']
11
+ s.email = 'rodrigoleonardomartin@gmail.com'
12
+ s.files = `git ls-files`.split("\n")
13
+ s.metadata = { "source_code_uri" => "https://github.com/rodr0m4/parby" }
14
+ s.license = 'MIT'
15
+
16
+ s.add_development_dependency 'rspec', '~> 3.0'
17
+ end
data/spec/parser_spec.rb CHANGED
@@ -1,8 +1,6 @@
1
- require 'spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Parser do
4
- include Parby
5
-
6
4
  describe '#initialize' do
7
5
  context 'not passing a block' do
8
6
  it 'raises' do
@@ -77,7 +75,7 @@ describe Parser do
77
75
 
78
76
  describe '#map' do
79
77
  context 'Given a parser mapped with a mapping block' do
80
- first_parser = Parser.regexp(/42/)
78
+ first_parser = Parby.regexp(/42/)
81
79
  parser = first_parser.map(&:to_i)
82
80
 
83
81
  it 'when the parser yields, it will apply the block to the resulting value' do
@@ -93,7 +91,7 @@ describe Parser do
93
91
 
94
92
  describe '#consuming' do
95
93
  context 'Given a non-consuming parser' do
96
- parser = regexp(/42/)
94
+ parser = Parby.regexp(/42/)
97
95
  input = '42'
98
96
  non_consuming_result = parser.parse input
99
97
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,4 @@
1
- require './lib/combinators.rb'
2
- require './lib/parser.rb'
3
- require './lib/result.rb'
1
+ require 'parby'
4
2
 
5
3
  include RSpec
6
4
  include Parby
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Martin
@@ -30,9 +30,19 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - lib/combinators.rb
34
- - lib/parser.rb
35
- - lib/result.rb
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.md
40
+ - lib/parby.rb
41
+ - lib/parby/combinators.rb
42
+ - lib/parby/parser.rb
43
+ - lib/parby/result.rb
44
+ - lib/parby/version.rb
45
+ - parby.gemspec
36
46
  - spec/combinators_spec.rb
37
47
  - spec/parser_spec.rb
38
48
  - spec/result_spec.rb