diff options
author | Eduardo Julian | 2017-08-05 14:30:53 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-08-05 14:30:53 -0400 |
commit | 6ed80bff3286ef1b7c458f86c3cc31ef7a5e137e (patch) | |
tree | d85ae66f9bd1a4a40fe81a8b2072cbcf86c5e467 /stdlib | |
parent | c94372370a129c8b8ebc94cca2a9e4aefd71d646 (diff) |
- Moved "codec" from lux/data/text/lexer to lux/control/parser.
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux/control/parser.lux | 18 | ||||
-rw-r--r-- | stdlib/source/lux/data/format/xml.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/data/text/lexer.lux | 17 | ||||
-rw-r--r-- | stdlib/source/lux/data/text/regex.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/time/date.lux | 4 | ||||
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/time/instant.lux | 6 |
7 files changed, 26 insertions, 27 deletions
diff --git a/stdlib/source/lux/control/parser.lux b/stdlib/source/lux/control/parser.lux index e2c522188..0c1b2cf32 100644 --- a/stdlib/source/lux/control/parser.lux +++ b/stdlib/source/lux/control/parser.lux @@ -2,7 +2,8 @@ [lux #- not default] (lux (control functor applicative - ["M" monad #+ do Monad]) + ["M" monad #+ do Monad] + [codec]) (data (coll [list "L/" Functor<List> Monoid<List>]) [product] ["R" result]))) @@ -246,3 +247,18 @@ [output parser _ (assert "Constraint failed." (test output))] (wrap output))) + +(def: #export (codec Codec<a,z> parser) + (All [s a z] (-> (codec;Codec a z) (Parser s a) (Parser s z))) + (function [input] + (case (parser input) + (#R;Error error) + (#R;Error error) + + (#R;Success [input' to-decode]) + (case (:: Codec<a,z> decode to-decode) + (#R;Error error) + (#R;Error error) + + (#R;Success value) + (#R;Success [input' value]))))) diff --git a/stdlib/source/lux/data/format/xml.lux b/stdlib/source/lux/data/format/xml.lux index e3a76fce2..4ff38380f 100644 --- a/stdlib/source/lux/data/format/xml.lux +++ b/stdlib/source/lux/data/format/xml.lux @@ -49,10 +49,10 @@ [hex? (p;opt (l;this "x")) code (case hex? #;None - (l;codec number;Codec<Text,Int> (l;many l;decimal)) + (p;codec number;Codec<Text,Int> (l;many l;decimal)) (#;Some _) - (l;codec number;Hex@Codec<Text,Int> (l;many l;hexadecimal)))] + (p;codec number;Hex@Codec<Text,Int> (l;many l;hexadecimal)))] (wrap (|> code int-to-nat text;from-code))) (p;before (l;this ";")) (p;after (l;this "&#")))) diff --git a/stdlib/source/lux/data/text/lexer.lux b/stdlib/source/lux/data/text/lexer.lux index 984fc4b09..ae3c4859f 100644 --- a/stdlib/source/lux/data/text/lexer.lux +++ b/stdlib/source/lux/data/text/lexer.lux @@ -3,7 +3,6 @@ (lux (control functor applicative [monad #+ do Monad] - codec ["p" parser]) (data [text "text/" Monoid<Text>] [product] @@ -239,22 +238,6 @@ (-> Nat Nat (Lexer Text) (Lexer Text)) (|> p (p;between from to) (:: p;Monad<Parser> map text;concat))) -(def: #export (codec Codec<a> lexer) - {#;doc "Lex a token by means of a codec."} - (All [a] (-> (Codec Text a) (Lexer Text) (Lexer a))) - (function [input] - (case (lexer input) - (#R;Error error) - (#R;Error error) - - (#R;Success [input' to-decode]) - (case (:: Codec<a> decode to-decode) - (#R;Error error) - (#R;Error error) - - (#R;Success value) - (#R;Success [input' value]))))) - (def: #export (enclosed [start end] lexer) (All [a] (-> [Text Text] (Lexer a) (Lexer a))) (|> lexer diff --git a/stdlib/source/lux/data/text/regex.lux b/stdlib/source/lux/data/text/regex.lux index 0b4df9faf..c42aa9ba3 100644 --- a/stdlib/source/lux/data/text/regex.lux +++ b/stdlib/source/lux/data/text/regex.lux @@ -179,7 +179,7 @@ (def: number^ (l;Lexer Nat) (|> (l;many l;decimal) - (l;codec number;Codec<Text,Int>) + (p;codec number;Codec<Text,Int>) (p/map int-to-nat))) (def: re-back-reference^ diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index bd7253a59..85c878211 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -234,7 +234,7 @@ (l;Lexer Int) (do p;Monad<Parser> [sign? (p;opt (l;this "-")) - raw-year (l;codec number;Codec<Text,Int> (l;many l;decimal)) + raw-year (p;codec number;Codec<Text,Int> (l;many l;decimal)) #let [signum (case sign? #;None 1 (#;Some _) -1)]] @@ -242,7 +242,7 @@ (def: lex-section (l;Lexer Int) - (l;codec number;Codec<Text,Int> (l;exactly +2 l;decimal))) + (p;codec number;Codec<Text,Int> (l;exactly +2 l;decimal))) (def: (leap-years year) (-> Int Int) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 2f3d019dd..d4f8bd52c 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -101,7 +101,7 @@ (def: (lex-section suffix) (-> Text (l;Lexer Int)) - (|> (l;codec number;Codec<Text,Int> (l;many l;decimal)) + (|> (p;codec number;Codec<Text,Int> (l;many l;decimal)) (p;before (l;this suffix)) (p;default 0))) diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 2901d5828..5177ffb44 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -214,7 +214,7 @@ (l;Lexer Int) (do p;Monad<Parser> [sign? (p;opt (l;this "-")) - raw-year (l;codec number;Codec<Text,Int> (l;many l;decimal)) + raw-year (p;codec number;Codec<Text,Int> (l;many l;decimal)) #let [signum (case sign? #;None 1 (#;Some _) -1)]] @@ -222,12 +222,12 @@ (def: lex-section (l;Lexer Int) - (l;codec number;Codec<Text,Int> (l;exactly +2 l;decimal))) + (p;codec number;Codec<Text,Int> (l;exactly +2 l;decimal))) (def: lex-millis (l;Lexer Int) (p;either (|> (l;at-most +3 l;decimal) - (l;codec number;Codec<Text,Int>) + (p;codec number;Codec<Text,Int>) (p;after (l;this "."))) (:: p;Monad<Parser> wrap 0))) |