aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/parser/code.lux
diff options
context:
space:
mode:
authorEduardo Julian2019-07-02 23:36:02 -0400
committerEduardo Julian2019-07-02 23:36:02 -0400
commit91c0619657bcf2ac520e7dd2912188f66bbe2157 (patch)
treef26675f263eb5f0285c1674b0777a7369248fe07 /stdlib/source/lux/control/parser/code.lux
parent4f191540f831a7bba0e262b1a6b598f99fb9b35c (diff)
Re-name "lux/data/error" to "lux/control/try".
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/parser/code.lux73
1 files changed, 37 insertions, 36 deletions
diff --git a/stdlib/source/lux/control/parser/code.lux b/stdlib/source/lux/control/parser/code.lux
index 25009b447..33ff0abe2 100644
--- a/stdlib/source/lux/control/parser/code.lux
+++ b/stdlib/source/lux/control/parser/code.lux
@@ -2,10 +2,11 @@
[lux (#- nat int rev)
[abstract
["." monad (#+ do)]]
+ [control
+ ["." try (#+ Try)]]
[data
["." bit]
["." name]
- ["." error (#+ Error)]
[number
["." nat]
["." int]
@@ -38,18 +39,18 @@
(Parser Code)
(function (_ tokens)
(case tokens
- #.Nil (#error.Failure "There are no tokens to parse!")
- (#.Cons [t tokens']) (#error.Success [tokens' t]))))
+ #.Nil (#try.Failure "There are no tokens to parse!")
+ (#.Cons [t tokens']) (#try.Success [tokens' t]))))
(template [<query> <assertion> <type> <tag> <eq> <desc>]
- [(with-expansions [<error> (as-is (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))]
+ [(with-expansions [<error> (as-is (#try.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))]
(def: #export <query>
{#.doc (code.text ($_ text@compose "Parses the next " <desc> " input."))}
(Parser <type>)
(function (_ tokens)
(case tokens
(#.Cons [[_ (<tag> x)] tokens'])
- (#error.Success [tokens' x])
+ (#try.Success [tokens' x])
_
<error>)))
@@ -60,7 +61,7 @@
(case tokens
(#.Cons [[_ (<tag> actual)] tokens'])
(if (:: <eq> = expected actual)
- (#error.Success [tokens' []])
+ (#try.Success [tokens' []])
<error>)
_
@@ -83,12 +84,12 @@
(case tokens
(#.Cons [token tokens'])
(if (code@= ast token)
- (#error.Success [tokens' []])
- (#error.Failure ($_ text@compose "Expected a " (code.to-text ast) " but instead got " (code.to-text token)
- (remaining-inputs tokens))))
+ (#try.Success [tokens' []])
+ (#try.Failure ($_ text@compose "Expected a " (code.to-text ast) " but instead got " (code.to-text token)
+ (remaining-inputs tokens))))
_
- (#error.Failure "There are no tokens to parse!"))))
+ (#try.Failure "There are no tokens to parse!"))))
(template [<name> <tag> <desc>]
[(def: #export <name>
@@ -97,10 +98,10 @@
(function (_ tokens)
(case tokens
(#.Cons [[_ (<tag> ["" x])] tokens'])
- (#error.Success [tokens' x])
+ (#try.Success [tokens' x])
_
- (#error.Failure ($_ text@compose "Cannot parse local " <desc> (remaining-inputs tokens))))))]
+ (#try.Failure ($_ text@compose "Cannot parse local " <desc> (remaining-inputs tokens))))))]
[local-identifier #.Identifier "identifier"]
[ local-tag #.Tag "tag"]
@@ -115,11 +116,11 @@
(case tokens
(#.Cons [[_ (<tag> members)] tokens'])
(case (p members)
- (#error.Success [#.Nil x]) (#error.Success [tokens' x])
- _ (#error.Failure ($_ text@compose "Parser was expected to fully consume " <desc> (remaining-inputs tokens))))
+ (#try.Success [#.Nil x]) (#try.Success [tokens' x])
+ _ (#try.Failure ($_ text@compose "Parser was expected to fully consume " <desc> (remaining-inputs tokens))))
_
- (#error.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))]
+ (#try.Failure ($_ text@compose "Cannot parse " <desc> (remaining-inputs tokens))))))]
[ form #.Form "form"]
[tuple #.Tuple "tuple"]
@@ -133,59 +134,59 @@
(case tokens
(#.Cons [[_ (#.Record pairs)] tokens'])
(case (p (join-pairs pairs))
- (#error.Success [#.Nil x]) (#error.Success [tokens' x])
- _ (#error.Failure ($_ text@compose "Parser was expected to fully consume record" (remaining-inputs tokens))))
+ (#try.Success [#.Nil x]) (#try.Success [tokens' x])
+ _ (#try.Failure ($_ text@compose "Parser was expected to fully consume record" (remaining-inputs tokens))))
_
- (#error.Failure ($_ text@compose "Cannot parse record" (remaining-inputs tokens))))))
+ (#try.Failure ($_ text@compose "Cannot parse record" (remaining-inputs tokens))))))
(def: #export end!
{#.doc "Ensures there are no more inputs."}
(Parser Any)
(function (_ tokens)
(case tokens
- #.Nil (#error.Success [tokens []])
- _ (#error.Failure ($_ text@compose "Expected list of tokens to be empty!" (remaining-inputs tokens))))))
+ #.Nil (#try.Success [tokens []])
+ _ (#try.Failure ($_ text@compose "Expected list of tokens to be empty!" (remaining-inputs tokens))))))
(def: #export end?
{#.doc "Checks whether there are no more inputs."}
(Parser Bit)
(function (_ tokens)
(case tokens
- #.Nil (#error.Success [tokens #1])
- _ (#error.Success [tokens #0]))))
+ #.Nil (#try.Success [tokens #1])
+ _ (#try.Success [tokens #0]))))
(def: #export (lift outcome)
- (All [a] (-> (Error a) (Parser a)))
+ (All [a] (-> (Try a) (Parser a)))
(function (_ input)
(case outcome
- (#error.Failure error)
- (#error.Failure error)
+ (#try.Failure error)
+ (#try.Failure error)
- (#error.Success value)
- (#error.Success [input value])
+ (#try.Success value)
+ (#try.Success [input value])
)))
(def: #export (run syntax inputs)
- (All [a] (-> (Parser a) (List Code) (Error a)))
+ (All [a] (-> (Parser a) (List Code) (Try a)))
(case (syntax inputs)
- (#error.Failure error)
- (#error.Failure error)
+ (#try.Failure error)
+ (#try.Failure error)
- (#error.Success [unconsumed value])
+ (#try.Success [unconsumed value])
(case unconsumed
#.Nil
- (#error.Success value)
+ (#try.Success value)
_
- (#error.Failure (text@compose "Unconsumed inputs: "
- (|> (list@map code.to-text unconsumed)
- (text.join-with ", ")))))))
+ (#try.Failure (text@compose "Unconsumed inputs: "
+ (|> (list@map code.to-text unconsumed)
+ (text.join-with ", ")))))))
(def: #export (local inputs syntax)
{#.doc "Run a syntax parser with the given list of inputs, instead of the real ones."}
(All [a] (-> (List Code) (Parser a) (Parser a)))
(function (_ real)
- (do error.monad
+ (do try.monad
[value (run syntax inputs)]
(wrap [real value]))))