parser_combinator_dsl 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: f4f09f2cab4d3a7ec337902226fa25de2b6dfd194d2cc1ac4e7c00bff724eb54
4
- data.tar.gz: aaa5b7b18fca3ef2334a0bea97820aef96f732adf2b089c02ef71479832ca914
3
+ metadata.gz: 9dfb04f7c0fc4cc1cf5308cb11f7d4a48a8234e1491841d15d552e8ad2ae4235
4
+ data.tar.gz: 8e455c3c496ab8a5a979658cb1cfe0410e34140835b6f7aa6016cefa63b30cdf
5
5
  SHA512:
6
- metadata.gz: f9926cf30554094f1fd5f736e52bc1173fb8ed857af09013de7a534c6f9ffaa6f332493ddbd58ad597b5213cd84c6ce36f8e24f68340adf62aef7f3ea05ceae7
7
- data.tar.gz: 99e2a534ccbecbd89976c18f3bf85af51c04819367dbb454c4da76529af728d233ffaddd0d50abd9fb9af2901d309af0ecbcc751b32ea72bf035dc212688f372
6
+ metadata.gz: 9b0b86387edca3f6b7929cde658aca2d4175773d7e4b162da9f9a0e979d5bd610299f5099e1b5248dfb0bb56a36c4a5d7df112e6fbfab6c24530aa591bd082d3
7
+ data.tar.gz: f1a2c0ba308168f3d45cd8c1c3d8c09288f5f1cddf1fc9ed7178abf670f85c664feb497ede7456e0f2a0acc26db5b018c4d6bcdd2116f07bbaa2782eed132b17
data/lib/base_parsers.rb CHANGED
@@ -90,10 +90,12 @@ module BaseParsers
90
90
  result = parser.run(remaining)
91
91
  return ParserResult.fail(input) unless result.ok?
92
92
  remaining = result.remaining
93
+ matched += result.matched
93
94
  result.matched
94
95
  end
95
96
 
96
- callback.call(*new_args)
97
+ output = callback.call(*new_args)
98
+ ParserResult.ok(output, matched: matched, remaining: remaining)
97
99
  end
98
100
  end
99
101
 
data/lib/parser_result.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  class ParserResult
2
- attr_reader :success, :remaining, :matched
3
- def initialize(success, remaining, matched)
2
+ attr_reader :success, :remaining, :matched, :output
3
+ def initialize(success, remaining, matched, output=[])
4
4
  @success = success
5
5
  @remaining = remaining
6
6
  @matched = matched
7
+ @output = output
7
8
  end
8
9
 
9
- def self.ok(matched:, remaining:)
10
- ParserResult.new(true, remaining, matched)
10
+ def self.ok(output=nil, matched:, remaining:)
11
+ # yield matched if block_given?
12
+ ParserResult.new(true, remaining, matched, output)
11
13
  end
12
14
 
13
15
  def self.fail(remaining)
@@ -132,7 +132,7 @@ describe Grammar do
132
132
  start(:letterOrNumber)
133
133
  end
134
134
 
135
- assert_equal ["w", "8"], parser.run("w8")
135
+ assert_equal ["w", "8"], parser.run("w8").output
136
136
 
137
137
  parser = Grammar.build do
138
138
  rule(:letter) { many1 { anyLetter } }
@@ -140,7 +140,7 @@ describe Grammar do
140
140
  start(:letterOrNumber)
141
141
  end
142
142
 
143
- assert_equal ["w", "8"], parser.run("w8")
143
+ assert_equal ["w", "8"], parser.run("w8").output
144
144
  end
145
145
 
146
146
  it "uses regex" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parser_combinator_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Ramirez
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-05-21 00:00:00.000000000 Z
12
+ date: 2018-05-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: "\n\tThis library provides a DSL which you can use to easily generate
15
15
  parsers in Ruby.\n\n\tAt it's core, it's a parser combinator library, but you don't