aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/parser/text.lux
diff options
context:
space:
mode:
authorEduardo Julian2020-06-23 03:02:15 -0400
committerEduardo Julian2020-06-23 03:02:15 -0400
commitc3eab65e3f107f7acdc0c0354770f9b8fbd92c4f (patch)
treee7c3221383b6dfc3d7f97ea5b4910193566d3806 /stdlib/source/lux/control/parser/text.lux
parenta8dacf2bd2b19e50888d3e5f293792d0b88afff7 (diff)
Bug fixes.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/parser/text.lux35
1 files changed, 11 insertions, 24 deletions
diff --git a/stdlib/source/lux/control/parser/text.lux b/stdlib/source/lux/control/parser/text.lux
index 5a7c2bb10..b74be5022 100644
--- a/stdlib/source/lux/control/parser/text.lux
+++ b/stdlib/source/lux/control/parser/text.lux
@@ -89,9 +89,14 @@
{#.doc "Just returns the next character without applying any logic."}
(Parser Slice)
(function (_ [offset tape])
- (#try.Success [[("lux i64 +" 1 offset) tape]
- {#basis offset
- #distance 1}])))
+ (case (/.nth offset tape)
+ (#.Some _)
+ (#try.Success [[("lux i64 +" 1 offset) tape]
+ {#basis offset
+ #distance 1}])
+
+ _
+ (exception.throw ..cannot-parse []))))
(template [<name> <type> <any>]
[(def: #export (<name> p)
@@ -124,19 +129,7 @@
_
<failure>))))
-(def: #export (this? reference)
- {#.doc "Lex a text if it matches the given sample."}
- (-> Text (Parser Bit))
- (function (_ (^@ input [offset tape]))
- (case (/.index-of' reference offset tape)
- (^multi (#.Some where) (n.= offset where))
- (#try.Success [[("lux i64 +" (/.size reference) offset) tape]
- #1])
-
- _
- (#try.Success [input #0]))))
-
-(def: #export end
+(def: #export end!
{#.doc "Ensure the parser's input is empty."}
(Parser Any)
(function (_ (^@ input [offset tape]))
@@ -144,12 +137,6 @@
(#try.Success [input []])
(exception.throw ..unconsumed-input input))))
-(def: #export end?
- {#.doc "Ask if the parser's input is empty."}
- (Parser Bit)
- (function (_ (^@ input [offset tape]))
- (#try.Success [input (n.= offset (/.size tape))])))
-
(def: #export peek
{#.doc "Lex the next character (without consuming it from the input)."}
(Parser Text)
@@ -182,7 +169,7 @@
[(def: #export <name>
{#.doc (code.text ($_ /@compose "Only lex " <desc> " characters."))}
(Parser Text)
- (range (char <bottom>) (char <top>)))]
+ (..range (char <bottom>) (char <top>)))]
[upper "A" "Z" "uppercase"]
[lower "a" "z" "lowercase"]
@@ -268,7 +255,7 @@
(def: #export space
{#.doc "Only lex white-space."}
(Parser Text)
- (satisfies /.space?))
+ (..satisfies /.space?))
(def: #export (and left right)
(-> (Parser Text) (Parser Text) (Parser Text))