Skip to content

Commit

Permalink
feat: Add coroutine parser
Browse files Browse the repository at this point in the history
  • Loading branch information
GearsDatapacks committed Feb 13, 2023
1 parent 17d729a commit 307800a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 20 deletions.
38 changes: 19 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/parsby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions lib/parsby/combinators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion parsby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 307800a

Please sign in to comment.