aboutsummaryrefslogtreecommitdiff
path: root/src/parcom.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/parcom.cr')
-rw-r--r--src/parcom.cr85
1 files changed, 48 insertions, 37 deletions
diff --git a/src/parcom.cr b/src/parcom.cr
index ef1aa2a..8d1d47b 100644
--- a/src/parcom.cr
+++ b/src/parcom.cr
@@ -59,15 +59,18 @@ module Parcom
return nil
end
- def assert(f : V -> Bool)
- Assert.new(self, f)
+ def |(other : Parser(T, V)) : Alt(T, V)
+ Alt.new(self, other)
end
- def |(other : Parser(T, V)) : Parser(T, V)
- Alt.new(self, other)
+ def +(other : Parser(T, U)) : Plus(T, V, U) forall U
+ Plus.new(self, other)
+ end
+
+ def assert(f : V -> Bool)
+ Assert.new(self, f)
end
- # TODO: Find a way to annotate this method's type
def map(f : V -> U) : Map(T, V, U) forall U
Map.new(self, f)
end
@@ -162,53 +165,61 @@ module Parcom
Result.new(result.tokens, @f.call(result.value))
end
end
-end
-class Phrase
-end
+ class Phrase
+ end
-class Plus
-end
+ class Plus(T, V, U) < Parser(T, {V, U})
+ def initialize(@p1 : Parser(T, V), @p2 : Parser(T, U))
+ end
-class Recover
-end
+ def parse(tokens : TokenStream(T)) : Result(T, {V, U})
+ r1 = @p1.parse(tokens)
+ r2 = @p2.parse(r1.tokens)
+ Result.new(r2.tokens, {r1.value, r2.value})
+ end
+ end
-class Optional
-end
+ class Recover
+ end
-class Tokens
-end
+ class Optional
+ end
-class Many
-end
+ class Tokens
+ end
-class Some
-end
+ class Many
+ end
-class Exactly
-end
+ class Some
+ end
-class AtLeast
-end
+ class Exactly
+ end
-class AtMost
-end
+ class AtLeast
+ end
-class Between
-end
+ class AtMost
+ end
-class StopAt
-end
+ class Between
+ end
-class StopAfter
-end
+ class StopAt
+ end
-class StopIf
-end
+ class StopAfter
+ end
-class FirstOf
-end
+ class StopIf
+ end
-class SepBy
+ class FirstOf
+ end
+
+ class SepBy
+ end
end