aboutsummaryrefslogtreecommitdiff
path: root/src/parcom.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-09 01:13:08 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-09 01:13:08 +1300
commit27a2d4281c5b270d6f3bba06ff1fd82ebfb94df6 (patch)
tree79a391d3f13d3b6508d1cc746db488958edd13ed /src/parcom.cr
parent8f8bee2893df280bd013e06c338838c758c4d8fc (diff)
Rewrite Satisfy to use blocks
Diffstat (limited to 'src/parcom.cr')
-rw-r--r--src/parcom.cr13
1 files changed, 5 insertions, 8 deletions
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