aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/parcom_spec.cr4
-rw-r--r--src/parcom.cr13
2 files changed, 6 insertions, 11 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index bdf8b5b..5be59b9 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -190,8 +190,7 @@ describe Assert do
end
describe Satisfy do
- test_f = ->(x : Char) { x == 't' }
- p = Satisfy.new(test_f)
+ p = Satisfy(Char).new { |x| x == 't' }
describe "#parse" do
it "fails if the input is empty" do
@@ -210,7 +209,6 @@ describe Satisfy do
result = p.parse(tokens)
result.value.should eq(expected_char)
- test_f.call(result.value).should be_true
end
end
end
diff --git a/src/parcom.cr b/src/parcom.cr
index de88a31..14d2e44 100644
--- a/src/parcom.cr
+++ b/src/parcom.cr
@@ -140,22 +140,19 @@ module Parcom
end
end
- # TODO: allow/change to support block invocation
- class Satisfy(T) < Parser(T, T)
- def initialize(@f : T -> Bool)
- end
-
- def parse(tokens : TokenStream(T)) : Result(T, T)
- AnyToken(T).new.assert(@f).parse(tokens)
+ class Satisfy(T) < Assert(T, T)
+ def initialize(&block : T -> Bool)
+ super(AnyToken(T).new, &block)
end
end
class Token(T) < Parser(T, T)
def initialize(@expected : T)
+ @p = Satisfy(T).new { |x| x == @expected }
end
def parse(tokens : TokenStream(T)) : Result(T, T)
- Satisfy(T).new(->(x : T) { x == @expected }).parse(tokens)
+ @p.parse(tokens)
end
end