diff options
author | Eduardo Julian | 2019-07-02 23:36:02 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-07-02 23:36:02 -0400 |
commit | 91c0619657bcf2ac520e7dd2912188f66bbe2157 (patch) | |
tree | f26675f263eb5f0285c1674b0777a7369248fe07 /stdlib/source/lux/control/parser/text.lux | |
parent | 4f191540f831a7bba0e262b1a6b598f99fb9b35c (diff) |
Re-name "lux/data/error" to "lux/control/try".
Diffstat (limited to 'stdlib/source/lux/control/parser/text.lux')
-rw-r--r-- | stdlib/source/lux/control/parser/text.lux | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/stdlib/source/lux/control/parser/text.lux b/stdlib/source/lux/control/parser/text.lux index 7c7c7fe4a..0e57f02f6 100644 --- a/stdlib/source/lux/control/parser/text.lux +++ b/stdlib/source/lux/control/parser/text.lux @@ -3,11 +3,11 @@ [abstract [monad (#+ Monad do)]] [control + ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["." product] ["." maybe] - ["." error (#+ Error)] ["/" text ("#@." monoid)] [number ["." nat ("#@." decimal)]] @@ -47,20 +47,20 @@ (exception: #export cannot-slice) (def: #export (run parser input) - (All [a] (-> (Parser a) Text (Error a))) + (All [a] (-> (Parser a) Text (Try a))) (case (parser [start-offset input]) - (#error.Failure msg) - (#error.Failure msg) + (#try.Failure msg) + (#try.Failure msg) - (#error.Success [[end-offset _] output]) + (#try.Success [[end-offset _] output]) (if (n/= end-offset (/.size input)) - (#error.Success output) + (#try.Success output) (exception.throw ..unconsumed-input [end-offset input])))) (def: #export offset (Parser Offset) (function (_ (^@ input [offset tape])) - (#error.Success [input offset]))) + (#try.Success [input offset]))) (def: (with-slices parser) (-> (Parser (List Slice)) (Parser Slice)) @@ -80,7 +80,7 @@ (function (_ [offset tape]) (case (/.nth offset tape) (#.Some output) - (#error.Success [[("lux i64 +" 1 offset) tape] (/.from-code output)]) + (#try.Success [[("lux i64 +" 1 offset) tape] (/.from-code output)]) _ (exception.throw ..cannot-parse [])))) @@ -89,9 +89,9 @@ {#.doc "Just returns the next character without applying any logic."} (Parser Slice) (function (_ [offset tape]) - (#error.Success [[("lux i64 +" 1 offset) tape] - {#basis offset - #distance 1}]))) + (#try.Success [[("lux i64 +" 1 offset) tape] + {#basis offset + #distance 1}]))) (template [<name> <type> <any>] [(def: #export (<name> p) @@ -99,7 +99,7 @@ (All [a] (-> (Parser a) (Parser <type>))) (function (_ input) (case (p input) - (#error.Failure msg) + (#try.Failure msg) (<any> input) _ @@ -116,12 +116,12 @@ (case (/.index-of' reference offset tape) (#.Some where) (if (n/= offset where) - (#error.Success [[("lux i64 +" (/.size reference) offset) tape] - []]) - (#error.Failure ($_ /@compose "Could not match: " (/.encode reference) " @ " (maybe.assume (/.clip' offset tape))))) + (#try.Success [[("lux i64 +" (/.size reference) offset) tape] + []]) + (#try.Failure ($_ /@compose "Could not match: " (/.encode reference) " @ " (maybe.assume (/.clip' offset tape))))) _ - (#error.Failure ($_ /@compose "Could not match: " (/.encode reference)))))) + (#try.Failure ($_ /@compose "Could not match: " (/.encode reference)))))) (def: #export (this? reference) {#.doc "Lex a text if it matches the given sample."} @@ -129,25 +129,25 @@ (function (_ (^@ input [offset tape])) (case (/.index-of' reference offset tape) (^multi (#.Some where) (n/= offset where)) - (#error.Success [[("lux i64 +" (/.size reference) offset) tape] - #1]) + (#try.Success [[("lux i64 +" (/.size reference) offset) tape] + #1]) _ - (#error.Success [input #0])))) + (#try.Success [input #0])))) (def: #export end {#.doc "Ensure the parser's input is empty."} (Parser Any) (function (_ (^@ input [offset tape])) (if (n/= offset (/.size tape)) - (#error.Success [input []]) + (#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])) - (#error.Success [input (n/= offset (/.size tape))]))) + (#try.Success [input (n/= offset (/.size tape))]))) (def: #export peek {#.doc "Lex the next character (without consuming it from the input)."} @@ -155,7 +155,7 @@ (function (_ (^@ input [offset tape])) (case (/.nth offset tape) (#.Some output) - (#error.Success [input (/.from-code output)]) + (#try.Success [input (/.from-code output)]) _ (exception.throw ..cannot-parse [])))) @@ -164,7 +164,7 @@ {#.doc "Get all of the remaining input (without consuming it)."} (Parser Text) (function (_ (^@ input [offset tape])) - (#error.Success [input (remaining offset tape)]))) + (#try.Success [input (remaining offset tape)]))) (def: #export (range bottom top) {#.doc "Only lex characters within a range."} @@ -216,10 +216,10 @@ (#.Some output) (let [output (/.from-code output)] (if (<modifier> (/.contains? output options)) - (#error.Success [[("lux i64 +" 1 offset) tape] output]) - (#error.Failure ($_ /@compose "Character (" output - ") is should " <description-modifier> - "be one of: " options)))) + (#try.Success [[("lux i64 +" 1 offset) tape] output]) + (#try.Failure ($_ /@compose "Character (" output + ") is should " <description-modifier> + "be one of: " options)))) _ (exception.throw ..cannot-parse []))))] @@ -237,12 +237,12 @@ (#.Some output) (let [output (/.from-code output)] (if (<modifier> (/.contains? output options)) - (#error.Success [[("lux i64 +" 1 offset) tape] - {#basis offset - #distance 1}]) - (#error.Failure ($_ /@compose "Character (" output - ") is should " <description-modifier> - "be one of: " options)))) + (#try.Success [[("lux i64 +" 1 offset) tape] + {#basis offset + #distance 1}]) + (#try.Failure ($_ /@compose "Character (" output + ") is should " <description-modifier> + "be one of: " options)))) _ (exception.throw ..cannot-parse []))))] @@ -258,8 +258,8 @@ (case (/.nth offset tape) (#.Some output) (if (p output) - (#error.Success [[("lux i64 +" 1 offset) tape] (/.from-code output)]) - (#error.Failure ($_ /@compose "Character does not satisfy predicate: " (/.from-code output)))) + (#try.Success [[("lux i64 +" 1 offset) tape] (/.from-code output)]) + (#try.Failure ($_ /@compose "Character does not satisfy predicate: " (/.from-code output)))) _ (exception.throw ..cannot-parse [])))) @@ -346,11 +346,11 @@ (All [a] (-> Text (Parser a) (Parser a))) (function (_ real-input) (case (run parser local-input) - (#error.Failure error) - (#error.Failure error) + (#try.Failure error) + (#try.Failure error) - (#error.Success value) - (#error.Success [real-input value])))) + (#try.Success value) + (#try.Success [real-input value])))) (def: #export (slice parser) (-> (Parser Slice) (Parser Text)) @@ -359,7 +359,7 @@ (function (_ (^@ input [offset tape])) (case (/.clip basis ("lux i64 +" basis distance) tape) (#.Some output) - (#error.Success [input output]) + (#try.Success [input output]) #.None (exception.throw ..cannot-slice []))))) |