aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parcom/parser.cr9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/parcom/parser.cr b/src/parcom/parser.cr
index e7442db..2b058d4 100644
--- a/src/parcom/parser.cr
+++ b/src/parcom/parser.cr
@@ -36,9 +36,16 @@ module Parcom
Parser(T, U).new("Pure #{value}") { |tokens| Result.new(tokens, value) }
end
+ # Creates a parser that always fails with the given error message.
+ def self.flunk(message : String) : Parser(T, U)
+ Parser(T, U).new("Flunk") do |_|
+ raise ParserFail.new(message)
+ end
+ end
+
# Creates a parser that always fails.
def self.flunk : Parser(T, U)
- Parser(T, U).new("Flunk") { |_| raise ParserFail.new("Flunked parser") }
+ flunk("Flunked parser")
end
# Creates a parser that returns the first token in the input stream.