diff --git a/Gemfile.lock b/Gemfile.lock index 87400e7..ff34371 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,41 +1,41 @@ PATH remote: . specs: - parsby (1.0.0) + parsby (1.1.1) GEM remote: https://rubygems.org/ specs: - coderay (1.1.2) - diff-lcs (1.3) + coderay (1.1.3) + diff-lcs (1.5.0) method_source (1.0.0) - pry (0.13.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) rake (10.5.0) - rspec (3.9.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-core (3.9.2) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.2) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.1) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.3) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) PLATFORMS - ruby + x86_64-linux DEPENDENCIES - bundler (~> 1.17) + bundler (~> 2.4) parsby! - pry + pry (~> 0) rake (~> 10.0) rspec (~> 3.0) BUNDLED WITH - 1.17.1 + 2.4.6 diff --git a/lib/parsby.rb b/lib/parsby.rb index ac5f1e2..5c3fcb0 100644 --- a/lib/parsby.rb +++ b/lib/parsby.rb @@ -609,6 +609,10 @@ def initialize(label = nil, &b) @parser = b end + def parser + @parser + end + # Parse a String or IO object. def parse(src) ctx = src.is_a?(Context) ? src : Context.new(src) diff --git a/lib/parsby/combinators.rb b/lib/parsby/combinators.rb index d90cb77..d1bbc0e 100644 --- a/lib/parsby/combinators.rb +++ b/lib/parsby/combinators.rb @@ -395,5 +395,18 @@ def splicer end end end + + # Takes a block which can run multiple parsers + # and use control flow to adapt itself. + define_combinator :coroutine do |&block| + Parsby.new do |target| + + parse = Proc.new do |parsby| + parsby.parser.call target + end + + block.call(parse) + end + end end end diff --git a/parsby.gemspec b/parsby.gemspec index 977d67b..86f6995 100644 --- a/parsby.gemspec +++ b/parsby.gemspec @@ -36,7 +36,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_development_dependency "bundler", "~> 1.17" + spec.add_development_dependency "bundler", "~> 2.4" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" spec.add_development_dependency "pry", "~> 0"