aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/text/lexer.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/text/lexer.lux')
-rw-r--r--stdlib/source/lux/data/text/lexer.lux54
1 files changed, 27 insertions, 27 deletions
diff --git a/stdlib/source/lux/data/text/lexer.lux b/stdlib/source/lux/data/text/lexer.lux
index 5fcbe8e6e..49a711236 100644
--- a/stdlib/source/lux/data/text/lexer.lux
+++ b/stdlib/source/lux/data/text/lexer.lux
@@ -19,7 +19,7 @@
## [Structures]
(struct: #export _ (Functor Lexer)
(def: (map f fa)
- (lambda [input]
+ (function [input]
(case (fa input)
(#E;Error msg) (#E;Error msg)
(#E;Success [input' output]) (#E;Success [input' (f output)])))))
@@ -28,11 +28,11 @@
(def: functor Functor<Lexer>)
(def: (wrap a)
- (lambda [input]
+ (function [input]
(#E;Success [input a])))
(def: (apply ff fa)
- (lambda [input]
+ (function [input]
(case (ff input)
(#E;Success [input' f])
(case (fa input')
@@ -49,7 +49,7 @@
(def: applicative Applicative<Lexer>)
(def: (join mma)
- (lambda [input]
+ (function [input]
(case (mma input)
(#E;Error msg) (#E;Error msg)
(#E;Success [input' ma]) (ma input'))))
@@ -74,13 +74,13 @@
## Combinators
(def: #export (fail message)
(All [a] (-> Text (Lexer a)))
- (lambda [input]
+ (function [input]
(#E;Error message)))
(def: #export any
{#;doc "Just returns the next character without applying any logic."}
(Lexer Char)
- (lambda [input]
+ (function [input]
(case [(text;nth +0 input) (text;split +1 input)]
[(#;Some output) (#;Some [_ input'])]
(#E;Success [input' output])
@@ -100,7 +100,7 @@
(def: #export (alt left right)
{#;doc "Heterogeneous alternative combinator."}
(All [a b] (-> (Lexer a) (Lexer b) (Lexer (| a b))))
- (lambda [input]
+ (function [input]
(case (left input)
(#E;Error msg)
(case (right input)
@@ -116,7 +116,7 @@
(def: #export (not! p)
{#;doc "Ensure a lexer fails."}
(All [a] (-> (Lexer a) (Lexer Unit)))
- (lambda [input]
+ (function [input]
(case (p input)
(#E;Error msg)
(#E;Success [input []])
@@ -127,7 +127,7 @@
(def: #export (not p)
{#;doc "Produce a character if the lexer fails."}
(All [a] (-> (Lexer a) (Lexer Char)))
- (lambda [input]
+ (function [input]
(case (p input)
(#E;Error msg)
(any input)
@@ -138,7 +138,7 @@
(def: #export (either left right)
{#;doc "Homogeneous alternative combinator."}
(All [a] (-> (Lexer a) (Lexer a) (Lexer a)))
- (lambda [input]
+ (function [input]
(case (left input)
(#E;Error msg)
(right input)
@@ -149,7 +149,7 @@
(def: #export (assert message test)
{#;doc "Fails with the given message if the test is false."}
(-> Text Bool (Lexer Unit))
- (lambda [input]
+ (function [input]
(if test
(#E;Success [input []])
(#E;Error message))))
@@ -157,7 +157,7 @@
(def: #export (some p)
{#;doc "0-or-more combinator."}
(All [a] (-> (Lexer a) (Lexer (List a))))
- (lambda [input]
+ (function [input]
(case (p input)
(#E;Error msg)
(#E;Success [input (list)])
@@ -191,7 +191,7 @@
{#;doc "Lex at most N times."}
(All [a] (-> Nat (Lexer a) (Lexer (List a))))
(if (n.> +0 n)
- (lambda [input]
+ (function [input]
(case (p input)
(#E;Error msg)
(#E;Success [input (list)])
@@ -223,7 +223,7 @@
(def: #export (opt p)
{#;doc "Optionality combinator."}
(All [a] (-> (Lexer a) (Lexer (Maybe a))))
- (lambda [input]
+ (function [input]
(case (p input)
(#E;Error msg)
(#E;Success [input #;None])
@@ -235,7 +235,7 @@
(def: #export (text test)
{#;doc "Lex a text if it matches the given sample."}
(-> Text (Lexer Text))
- (lambda [input]
+ (function [input]
(if (text;starts-with? test input)
(case (text;split (text;size test) input)
#;None (#E;Error "")
@@ -261,7 +261,7 @@
(def: #export end
{#;doc "Ensure the lexer's input is empty."}
(Lexer Unit)
- (lambda [input]
+ (function [input]
(case input
"" (#E;Success [input []])
_ (#E;Error ($_ Text/append "The text input has not been fully consumed @ " (:: text;Codec<Text,Text> encode input)))
@@ -270,7 +270,7 @@
(def: #export peek
{#;doc "Lex the next character (without consuming it from the input)."}
(Lexer Char)
- (lambda [input]
+ (function [input]
(case (text;nth +0 input)
(#;Some output)
(#E;Success [input output])
@@ -282,7 +282,7 @@
(def: #export (char test)
{#;doc "Lex a character if it matches the given sample."}
(-> Char (Lexer Char))
- (lambda [input]
+ (function [input]
(case [(text;nth +0 input) (text;split +1 input)]
[(#;Some char') (#;Some [_ input'])]
(if (Char/= test char')
@@ -296,7 +296,7 @@
(def: #export get-input
{#;doc "Get all of the remaining input (without consuming it)."}
(Lexer Text)
- (lambda [input]
+ (function [input]
(#E;Success [input input])))
(def: #export (char-range bottom top)
@@ -343,7 +343,7 @@
(def: #export (one-of options)
{#;doc "Only lex characters that are part of a piece of text."}
(-> Text (Lexer Char))
- (lambda [input]
+ (function [input]
(case (text;split +1 input)
(#;Some [init input'])
(if (text;contains? init options)
@@ -361,7 +361,7 @@
(def: #export (none-of options)
{#;doc "Only lex characters that aren't part of a piece of text."}
(-> Text (Lexer Char))
- (lambda [input]
+ (function [input]
(case (text;split +1 input)
(#;Some [init input'])
(if (;not (text;contains? init options))
@@ -379,7 +379,7 @@
(def: #export (satisfies p)
{#;doc "Only lex characters that satisfy a predicate."}
(-> (-> Char Bool) (Lexer Char))
- (lambda [input]
+ (function [input]
(case (: (Maybe [Text Char])
(do Monad<Maybe>
[[init input'] (text;split +1 input)
@@ -443,7 +443,7 @@
(def: #export end?
{#;doc "Ask if the lexer's input is empty."}
(Lexer Bool)
- (lambda [input]
+ (function [input]
(#E;Success [input (text;empty? input)])))
(def: #export (after param subject)
@@ -462,7 +462,7 @@
(def: #export (default value lexer)
{#;doc "If the given lexer fails, this lexer will succeed with the provided value."}
(All [a] (-> a (Lexer a) (Lexer a)))
- (lambda [input]
+ (function [input]
(case (lexer input)
(#E;Error error)
(#E;Success [input value])
@@ -473,7 +473,7 @@
(def: #export (codec codec lexer)
{#;doc "Lex a token by means of a codec."}
(All [a] (-> (Codec Text a) (Lexer Text) (Lexer a)))
- (lambda [input]
+ (function [input]
(case (lexer input)
(#E;Error error)
(#E;Error error)
@@ -495,13 +495,13 @@
(def: #export (rec lexer)
(All [a] (-> (-> (Lexer a) (Lexer a))
(Lexer a)))
- (lambda [input]
+ (function [input]
(run' input (lexer (rec lexer)))))
(def: #export (local local-input lexer)
{#;doc "Run a lexer with the given input, instead of the real one."}
(All [a] (-> Text (Lexer a) (Lexer a)))
- (lambda [real-input]
+ (function [real-input]
(case (run' local-input lexer)
(#E;Error error)
(#E;Error error)