diff options
Diffstat (limited to 'src/parcom.cr')
| -rw-r--r-- | src/parcom.cr | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/parcom.cr b/src/parcom.cr index f0295a3..034c8e1 100644 --- a/src/parcom.cr +++ b/src/parcom.cr @@ -432,15 +432,6 @@ module Parcom end end - class StopAt - end - - class StopAfter - end - - class StopIf - end - class FirstOf(T, V) < Parser(T, V) @p : Parser(T, V) @@ -468,7 +459,20 @@ module Parcom end end - class SepBy + class SepBy(T, V, U) < Parser(T, Array(V)) + @p : Map(T, {V, Array(V)}, Array(V)) + + def initialize(elem : Parser(T, V), sep : Parser(T, U)) + @p = (elem + Many(T, U).new(sep >> elem)).map do |tup| + [tup[0]] + tup[1] + end + end + + def parse(tokens : TokenStream(T)) : Result(T, Array(V)) + @p.parse(tokens) + rescue ex : ParserException + raise ParserException.new("SepBy: #{ex.message}") + end end end |
