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 +4 -4
- data/lib/base_parsers.rb +3 -1
- data/lib/parser_result.rb +6 -4
- data/test/test_base_parsers.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9dfb04f7c0fc4cc1cf5308cb11f7d4a48a8234e1491841d15d552e8ad2ae4235
|
|
4
|
+
data.tar.gz: 8e455c3c496ab8a5a979658cb1cfe0410e34140835b6f7aa6016cefa63b30cdf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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)
|
data/test/test_base_parsers.rb
CHANGED
|
@@ -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.
|
|
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-
|
|
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
|