aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2017-01-12 19:39:31 -0400
committerEduardo Julian2017-01-12 19:39:31 -0400
commit1f28cd54954e8b2b978b5fa94956c8df4cbee698 (patch)
treec0ff4aaf6e57d1544402d40f461a88527f6a1cf9 /stdlib
parent129d3a169484c08d90a31fba5d8f59d39227c5fd (diff)
- Minor refactorings and additions.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/data/format/json.lux8
-rw-r--r--stdlib/source/lux/lexer.lux199
-rw-r--r--stdlib/source/lux/macro/syntax.lux6
-rw-r--r--stdlib/source/lux/regex.lux3
-rw-r--r--stdlib/test/test/lux/lexer.lux210
-rw-r--r--stdlib/test/test/lux/regex.lux8
6 files changed, 265 insertions, 169 deletions
diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux
index f9dafee7a..d9ef60605 100644
--- a/stdlib/source/lux/data/format/json.lux
+++ b/stdlib/source/lux/data/format/json.lux
@@ -628,8 +628,8 @@
(#;Left _) (#;Right #;None)
(#;Right x) (#;Right (#;Some x))))
-(def: #export (run parser json)
- (All [a] (-> (Parser a) JSON (Error a)))
+(def: #export (run json parser)
+ (All [a] (-> JSON (Parser a) (Error a)))
(parser json))
(def: #export (ensure test parser json)
@@ -710,7 +710,7 @@
(struct: #export _ (Codec Text JSON)
(def: encode show-json)
- (def: decode (lexer;run (json~' []))))
+ (def: decode (lambda [input] (lexer;run input (json~' [])))))
## [Syntax]
(type: Shape
@@ -980,7 +980,7 @@
(lambda [(~ g!key)]
(do Monad<Error>
[(~ g!val) (;;get (~ g!key) (~ g!input))
- (~ g!val) (;;run (~ .val.) (~ g!val))]
+ (~ g!val) (;;run (~ g!val) (~ .val.))]
((~ (' wrap)) [(~ g!key) (~ g!val)])))
(~ g!key))))
)))
diff --git a/stdlib/source/lux/lexer.lux b/stdlib/source/lux/lexer.lux
index 04e9dfef1..bc5bea5f0 100644
--- a/stdlib/source/lux/lexer.lux
+++ b/stdlib/source/lux/lexer.lux
@@ -15,7 +15,7 @@
[product]
[char "Char/" Ord<Char>]
maybe
- [error #- fail]
+ ["E" error #- fail]
(struct [list "" Functor<List>]))
host))
@@ -28,29 +28,29 @@
(def: (map f fa)
(lambda [input]
(case (fa input)
- (#;Left msg) (#;Left msg)
- (#;Right [input' output]) (#;Right [input' (f output)])))))
+ (#E;Error msg) (#E;Error msg)
+ (#E;Success [input' output]) (#E;Success [input' (f output)])))))
(struct: #export _ (Applicative Lexer)
(def: functor Functor<Lexer>)
(def: (wrap a)
(lambda [input]
- (#;Right [input a])))
+ (#E;Success [input a])))
(def: (apply ff fa)
(lambda [input]
(case (ff input)
- (#;Right [input' f])
+ (#E;Success [input' f])
(case (fa input')
- (#;Right [input'' a])
- (#;Right [input'' (f a)])
+ (#E;Success [input'' a])
+ (#E;Success [input'' (f a)])
- (#;Left msg)
- (#;Left msg))
+ (#E;Error msg)
+ (#E;Error msg))
- (#;Left msg)
- (#;Left msg)))))
+ (#E;Error msg)
+ (#E;Error msg)))))
(struct: #export _ (Monad Lexer)
(def: applicative Applicative<Lexer>)
@@ -58,31 +58,31 @@
(def: (join mma)
(lambda [input]
(case (mma input)
- (#;Left msg) (#;Left msg)
- (#;Right [input' ma]) (ma input'))))
+ (#E;Error msg) (#E;Error msg)
+ (#E;Success [input' ma]) (ma input'))))
)
## [Values]
## Runner
-(def: #export (run' lexer input)
- (All [a] (-> (Lexer a) Text (Error [Text a])))
+(def: #export (run' input lexer)
+ (All [a] (-> Text (Lexer a) (Error [Text a])))
(lexer input))
-(def: #export (run lexer input)
- (All [a] (-> (Lexer a) Text (Error a)))
+(def: #export (run input lexer)
+ (All [a] (-> Text (Lexer a) (Error a)))
(case (lexer input)
- (#;Left msg)
- (#;Left msg)
+ (#E;Error msg)
+ (#E;Error msg)
- (#;Right [input' output])
- (#;Right output)
+ (#E;Success [input' output])
+ (#E;Success output)
))
## Combinators
(def: #export (fail message)
(All [a] (-> Text (Lexer a)))
(lambda [input]
- (#;Left message)))
+ (#E;Error message)))
(def: #export any
{#;doc "Just returns the next character without applying any logic."}
@@ -90,10 +90,10 @@
(lambda [input]
(case [(text;at +0 input) (text;split +1 input)]
[(#;Some output) (#;Some [_ input'])]
- (#;Right [input' output])
+ (#E;Success [input' output])
_
- (#;Left "Can't parse character from empty text."))
+ (#E;Error "Can't parse character from empty text."))
))
(def: #export (seq left right)
@@ -109,45 +109,45 @@
(All [a b] (-> (Lexer a) (Lexer b) (Lexer (| a b))))
(lambda [input]
(case (left input)
- (#;Left msg)
+ (#E;Error msg)
(case (right input)
- (#;Left msg)
- (#;Left msg)
+ (#E;Error msg)
+ (#E;Error msg)
- (#;Right [input' output])
- (#;Right [input' (+1 output)]))
+ (#E;Success [input' output])
+ (#E;Success [input' (+1 output)]))
- (#;Right [input' output])
- (#;Right [input' (+0 output)]))))
+ (#E;Success [input' output])
+ (#E;Success [input' (+0 output)]))))
(def: #export (not! p)
{#;doc "Ensure a lexer fails."}
(All [a] (-> (Lexer a) (Lexer Unit)))
(lambda [input]
(case (p input)
- (#;Left msg)
- (#;Right [input []])
+ (#E;Error msg)
+ (#E;Success [input []])
_
- (#;Left "Expected to fail; yet succeeded."))))
+ (#E;Error "Expected to fail; yet succeeded."))))
(def: #export (not p)
{#;doc "Produce a character if the lexer fails."}
(All [a] (-> (Lexer a) (Lexer Char)))
(lambda [input]
(case (p input)
- (#;Left msg)
+ (#E;Error msg)
(any input)
_
- (#;Left "Expected to fail; yet succeeded."))))
+ (#E;Error "Expected to fail; yet succeeded."))))
(def: #export (either left right)
{#;doc "Homogeneous alternative combinator."}
(All [a] (-> (Lexer a) (Lexer a) (Lexer a)))
(lambda [input]
(case (left input)
- (#;Left msg)
+ (#E;Error msg)
(right input)
output
@@ -158,22 +158,22 @@
(-> Text Bool (Lexer Unit))
(lambda [input]
(if test
- (#;Right [input []])
- (#;Left message))))
+ (#E;Success [input []])
+ (#E;Error message))))
(def: #export (some p)
{#;doc "0-or-more combinator."}
(All [a] (-> (Lexer a) (Lexer (List a))))
(lambda [input]
(case (p input)
- (#;Left msg)
- (#;Right [input (list)])
+ (#E;Error msg)
+ (#E;Success [input (list)])
- (#;Right [input' x])
- (run' (do Monad<Lexer>
+ (#E;Success [input' x])
+ (run' input'
+ (do Monad<Lexer>
[xs (some p)]
- (wrap (#;Cons x xs)))
- input'))
+ (wrap (#;Cons x xs)))))
))
(def: #export (many p)
@@ -200,14 +200,14 @@
(if (n.> +0 n)
(lambda [input]
(case (p input)
- (#;Left msg)
- (#;Right [input (list)])
+ (#E;Error msg)
+ (#E;Success [input (list)])
- (#;Right [input' x])
- (run' (do Monad<Lexer>
+ (#E;Success [input' x])
+ (run' input'
+ (do Monad<Lexer>
[xs (at-most (n.dec n) p)]
- (wrap (#;Cons x xs)))
- input')
+ (wrap (#;Cons x xs))))
))
(:: Monad<Lexer> wrap (list))))
@@ -232,11 +232,11 @@
(All [a] (-> (Lexer a) (Lexer (Maybe a))))
(lambda [input]
(case (p input)
- (#;Left msg)
- (#;Right [input #;None])
+ (#E;Error msg)
+ (#E;Success [input #;None])
- (#;Right [input value])
- (#;Right [input (#;Some value)])
+ (#E;Success [input value])
+ (#E;Success [input (#;Some value)])
)))
(def: #export (text test)
@@ -245,9 +245,9 @@
(lambda [input]
(if (text;starts-with? test input)
(case (text;split (text;size test) input)
- #;None (#;Left "")
- (#;Some [_ input']) (#;Right [input' test]))
- (#;Left (format "Invalid match: " test " @ " (:: text;Codec<Text,Text> encode input))))
+ #;None (#E;Error "")
+ (#;Some [_ input']) (#E;Success [input' test]))
+ (#E;Error (format "Invalid match: " test " @ " (:: text;Codec<Text,Text> encode input))))
))
(def: #export (sep-by sep lexer)
@@ -270,8 +270,8 @@
(Lexer Unit)
(lambda [input]
(case input
- "" (#;Right [input []])
- _ (#;Left (format "The text input has not been fully consumed @ " (:: text;Codec<Text,Text> encode input)))
+ "" (#E;Success [input []])
+ _ (#E;Error (format "The text input has not been fully consumed @ " (:: text;Codec<Text,Text> encode input)))
)))
(def: #export peek
@@ -280,10 +280,10 @@
(lambda [input]
(case (text;at +0 input)
(#;Some output)
- (#;Right [input output])
+ (#E;Success [input output])
_
- (#;Left "Can't peek character from empty text."))
+ (#E;Error "Can't peek character from empty text."))
))
(def: #export (char test)
@@ -293,19 +293,19 @@
(case [(text;at +0 input) (text;split +1 input)]
[(#;Some char') (#;Some [_ input'])]
(if (Char/= test char')
- (#;Right [input' test])
- (#;Left (format "Expected " (:: char;Codec<Text,Char> encode test) " @ " (:: text;Codec<Text,Text> encode input)
- " " (Int/encode (c2l test))" " (Int/encode (c2l [char'])))))
+ (#E;Success [input' test])
+ (#E;Error (format "Expected " (:: char;Codec<Text,Char> encode test) " @ " (:: text;Codec<Text,Text> encode input)
+ " " (Int/encode (c2l test))" " (Int/encode (c2l [char'])))))
_
- (#;Left "Can't parse character from empty text."))
+ (#E;Error "Can't parse character from empty text."))
))
(def: #export get-input
{#;doc "Get all of the remaining input (without consuming it)."}
(Lexer Text)
(lambda [input]
- (#;Right [input input])))
+ (#E;Success [input input])))
(def: #export (char-range bottom top)
{#;doc "Only lex characters within a range."}
@@ -357,14 +357,14 @@
(if (text;contains? init options)
(case (text;at +0 init)
(#;Some output)
- (#;Right [input' output])
+ (#E;Success [input' output])
_
- (#;Left ""))
- (#;Left (format "Character (" init ") is not one of: " options " @ " (:: text;Codec<Text,Text> encode input))))
+ (#E;Error ""))
+ (#E;Error (format "Character (" init ") is not one of: " options " @ " (:: text;Codec<Text,Text> encode input))))
_
- (#;Left "Can't parse character from empty text."))))
+ (#E;Error "Can't parse character from empty text."))))
(def: #export (none-of options)
{#;doc "Only lex characters that aren't part of a piece of text."}
@@ -375,14 +375,14 @@
(if (;not (text;contains? init options))
(case (text;at +0 init)
(#;Some output)
- (#;Right [input' output])
+ (#E;Success [input' output])
_
- (#;Left ""))
- (#;Left (format "Character (" init ") is one of: " options " @ " (:: text;Codec<Text,Text> encode input))))
+ (#E;Error ""))
+ (#E;Error (format "Character (" init ") is one of: " options " @ " (:: text;Codec<Text,Text> encode input))))
_
- (#;Left "Can't parse character from empty text."))))
+ (#E;Error "Can't parse character from empty text."))))
(def: #export (satisfies p)
{#;doc "Only lex characters that satisfy a predicate."}
@@ -395,11 +395,11 @@
(wrap [input' output])))
(#;Some [input' output])
(if (p output)
- (#;Right [input' output])
- (#;Left (format "Character does not satisfy predicate: " (:: text;Codec<Text,Text> encode input))))
+ (#E;Success [input' output])
+ (#E;Error (format "Character does not satisfy predicate: " (:: text;Codec<Text,Text> encode input))))
_
- (#;Left "Can't parse character from empty text."))))
+ (#E;Error "Can't parse character from empty text."))))
(def: #export space
{#;doc "Only lex white-space."}
@@ -424,7 +424,7 @@
{#;doc "Ask if the lexer's input is empty."}
(Lexer Bool)
(lambda [input]
- (#;Right [input (text;empty? input)])))
+ (#E;Success [input (text;empty? input)])))
(def: #export (_& left right)
(All [a b] (-> (Lexer a) (Lexer b) (Lexer b)))
@@ -444,30 +444,49 @@
(All [a] (-> a (Lexer a) (Lexer a)))
(lambda [input]
(case (lexer input)
- (#;Left error)
- (#;Right [input value])
+ (#E;Error error)
+ (#E;Success [input value])
- (#;Right input'+value)
- (#;Right input'+value))))
+ (#E;Success input'+value)
+ (#E;Success input'+value))))
(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]
(case (lexer input)
- (#;Left error)
- (#;Left error)
+ (#E;Error error)
+ (#E;Error error)
- (#;Right [input' to-decode])
+ (#E;Success [input' to-decode])
(case (:: codec decode to-decode)
- (#;Left error)
- (#;Left error)
+ (#E;Error error)
+ (#E;Error error)
- (#;Right value)
- (#;Right [input' value])))))
+ (#E;Success value)
+ (#E;Success [input' value])))))
(def: #export (enclosed [start end] lexer)
(All [a] (-> [Text Text] (Lexer a) (Lexer a)))
(_& (text start)
(&_ lexer
(text end))))
+
+(def: #export (rec lexer)
+ (All [a] (-> (-> (Lexer a) (Lexer a))
+ (Lexer a)))
+ (lambda [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]
+ (case (run' local-input lexer)
+ (#E;Error error)
+ (#E;Error error)
+
+ (#E;Success [unconsumed value])
+ (if (Text/= "" unconsumed)
+ (#E;Success [real-input value])
+ (#E;Error (format "Unconsumed input: " unconsumed))))))
diff --git a/stdlib/source/lux/macro/syntax.lux b/stdlib/source/lux/macro/syntax.lux
index d043a0b29..dd7a3ac06 100644
--- a/stdlib/source/lux/macro/syntax.lux
+++ b/stdlib/source/lux/macro/syntax.lux
@@ -408,6 +408,12 @@
(|> (map ast;to-text unconsumed-inputs)
(text;join-with ", "))))))))
+(def: #export (rec syntax)
+ {#;doc "Combinator for recursive syntax."}
+ (All [a] (-> (-> (Syntax a) (Syntax a)) (Syntax a)))
+ (lambda [inputs]
+ (run inputs (syntax (rec syntax)))))
+
## [Syntax]
(def: #hidden text.join-with text;join-with)
diff --git a/stdlib/source/lux/regex.lux b/stdlib/source/lux/regex.lux
index 417abc086..5684a4465 100644
--- a/stdlib/source/lux/regex.lux
+++ b/stdlib/source/lux/regex.lux
@@ -481,7 +481,8 @@
)}
(do @
[current-module compiler;current-module-name]
- (case (&;run (&;&_ (regex^ current-module) &;end) pattern)
+ (case (&;run pattern
+ (&;&_ (regex^ current-module) &;end))
(#;Left error)
(compiler;fail error)
diff --git a/stdlib/test/test/lux/lexer.lux b/stdlib/test/test/lux/lexer.lux
index 7e7408428..3c459ab8e 100644
--- a/stdlib/test/test/lux/lexer.lux
+++ b/stdlib/test/test/lux/lexer.lux
@@ -73,11 +73,13 @@
(test: "End"
($_ seq
(assert "Can detect the end of the input."
- (|> (&;run &;end "")
+ (|> (&;run ""
+ &;end)
(case> (#;Right _) true _ false)))
(assert "Won't mistake non-empty text for no more input."
- (|> (&;run &;end "YOLO")
+ (|> (&;run "YOLO"
+ &;end)
(case> (#;Left _) true _ false)))
))
@@ -88,163 +90,231 @@
(R;filter (|>. (text;starts-with? pre) not)))]
($_ seq
(assert "Can find literal text fragments."
- (and (|> (&;run (&;text pre) (format pre post))
+ (and (|> (&;run (format pre post)
+ (&;text pre))
(case> (#;Right found) (T/= pre found) _ false))
- (|> (&;run (&;text pre) post)
+ (|> (&;run post
+ (&;text pre))
(case> (#;Left _) true _ false))))
))
(test: "Char lexers"
($_ seq
(assert "Can lex characters."
- (and (|> (&;run (&;char #"Y") "YOLO")
+ (and (|> (&;run "YOLO"
+ (&;char #"Y"))
(case> (#;Right #"Y") true _ false))
- (|> (&;run (&;char #"Y") "MEME")
+ (|> (&;run "MEME"
+ (&;char #"Y"))
(case> (#;Left _) true _ false))))
(assert "Can lex characters ranges."
- (and (should-passC #"Y" (&;run (&;char-range #"X" #"Z") "YOLO"))
- (should-fail (&;run (&;char-range #"X" #"Z") "MEME"))))
+ (and (should-passC #"Y" (&;run "YOLO"
+ (&;char-range #"X" #"Z")))
+ (should-fail (&;run "MEME"
+ (&;char-range #"X" #"Z")))))
))
(test: "Custom lexers"
($_ seq
(assert "Can lex anything"
- (and (should-passC #"A" (&;run &;any "A"))
- (should-fail (&;run &;any ""))))
+ (and (should-passC #"A" (&;run "A"
+ &;any))
+ (should-fail (&;run ""
+ &;any))))
(assert "Can lex upper-case and &;lower-case letters."
- (and (should-passC #"Y" (&;run &;upper "YOLO"))
- (should-fail (&;run &;upper "meme"))
+ (and (should-passC #"Y" (&;run "YOLO"
+ &;upper))
+ (should-fail (&;run "meme"
+ &;upper))
- (should-passC #"y" (&;run &;lower "yolo"))
- (should-fail (&;run &;lower "MEME"))))
+ (should-passC #"y" (&;run "yolo"
+ &;lower))
+ (should-fail (&;run "MEME"
+ &;lower))))
(assert "Can lex numbers."
- (and (should-passC #"1" (&;run &;digit "1"))
- (should-fail (&;run &;digit " "))
+ (and (should-passC #"1" (&;run "1"
+ &;digit))
+ (should-fail (&;run " "
+ &;digit))
- (should-passC #"7" (&;run &;oct-digit "7"))
- (should-fail (&;run &;oct-digit "8"))
+ (should-passC #"7" (&;run "7"
+ &;oct-digit))
+ (should-fail (&;run "8"
+ &;oct-digit))
- (should-passC #"1" (&;run &;hex-digit "1"))
- (should-passC #"a" (&;run &;hex-digit "a"))
- (should-passC #"A" (&;run &;hex-digit "A"))
- (should-fail (&;run &;hex-digit " "))
+ (should-passC #"1" (&;run "1"
+ &;hex-digit))
+ (should-passC #"a" (&;run "a"
+ &;hex-digit))
+ (should-passC #"A" (&;run "A"
+ &;hex-digit))
+ (should-fail (&;run " "
+ &;hex-digit))
))
(assert "Can lex alphabetic characters."
- (and (should-passC #"A" (&;run &;alpha "A"))
- (should-passC #"a" (&;run &;alpha "a"))
- (should-fail (&;run &;alpha "1"))))
+ (and (should-passC #"A" (&;run "A"
+ &;alpha))
+ (should-passC #"a" (&;run "a"
+ &;alpha))
+ (should-fail (&;run "1"
+ &;alpha))))
(assert "Can lex alphanumeric characters."
- (and (should-passC #"A" (&;run &;alpha-num "A"))
- (should-passC #"a" (&;run &;alpha-num "a"))
- (should-passC #"1" (&;run &;alpha-num "1"))
- (should-fail (&;run &;alpha-num " "))))
+ (and (should-passC #"A" (&;run "A"
+ &;alpha-num))
+ (should-passC #"a" (&;run "a"
+ &;alpha-num))
+ (should-passC #"1" (&;run "1"
+ &;alpha-num))
+ (should-fail (&;run " "
+ &;alpha-num))))
(assert "Can lex white-space."
- (and (should-passC #" " (&;run &;space " "))
- (should-fail (&;run &;space "8"))))
+ (and (should-passC #" " (&;run " "
+ &;space))
+ (should-fail (&;run "8"
+ &;space))))
))
(test: "Combinators"
($_ seq
(assert "Can combine lexers sequentially."
- (and (|> (&;run (&;seq &;any &;any) "YOLO")
+ (and (|> (&;run "YOLO"
+ (&;seq &;any &;any))
(case> (#;Right [#"Y" #"O"]) true
_ false))
- (should-fail (&;run (&;seq &;any &;any) "Y"))))
+ (should-fail (&;run "Y"
+ (&;seq &;any &;any)))))
(assert "Can combine lexers alternatively."
- (and (should-passE (#;Left #"0") (&;run (&;alt &;digit &;upper) "0"))
- (should-passE (#;Right #"A") (&;run (&;alt &;digit &;upper) "A"))
- (should-fail (&;run (&;alt &;digit &;upper) "a"))))
+ (and (should-passE (#;Left #"0") (&;run "0"
+ (&;alt &;digit &;upper)))
+ (should-passE (#;Right #"A") (&;run "A"
+ (&;alt &;digit &;upper)))
+ (should-fail (&;run "a"
+ (&;alt &;digit &;upper)))))
(assert "Can create the opposite of a lexer."
- (and (should-passC #"a" (&;run (&;not (&;alt &;digit &;upper)) "a"))
- (should-fail (&;run (&;not (&;alt &;digit &;upper)) "A"))))
+ (and (should-passC #"a" (&;run "a"
+ (&;not (&;alt &;digit &;upper))))
+ (should-fail (&;run "A"
+ (&;not (&;alt &;digit &;upper))))))
(assert "Can use either lexer."
- (and (should-passC #"0" (&;run (&;either &;digit &;upper) "0"))
- (should-passC #"A" (&;run (&;either &;digit &;upper) "A"))
- (should-fail (&;run (&;either &;digit &;upper) "a"))))
+ (and (should-passC #"0" (&;run "0"
+ (&;either &;digit &;upper)))
+ (should-passC #"A" (&;run "A"
+ (&;either &;digit &;upper)))
+ (should-fail (&;run "a"
+ (&;either &;digit &;upper)))))
(assert "Can select from among a set of characters."
- (and (should-passC #"C" (&;run (&;one-of "ABC") "C"))
- (should-fail (&;run (&;one-of "ABC") "D"))))
+ (and (should-passC #"C" (&;run "C"
+ (&;one-of "ABC")))
+ (should-fail (&;run "D"
+ (&;one-of "ABC")))))
(assert "Can avoid a set of characters."
- (and (should-passC #"D" (&;run (&;none-of "ABC") "D"))
- (should-fail (&;run (&;none-of "ABC") "C"))))
+ (and (should-passC #"D" (&;run "D"
+ (&;none-of "ABC")))
+ (should-fail (&;run "C"
+ (&;none-of "ABC")))))
(assert "Can lex using arbitrary predicates."
- (and (should-passC #"D" (&;run (&;satisfies (lambda [c] true)) "D"))
- (should-fail (&;run (&;satisfies (lambda [c] false)) "C"))))
+ (and (should-passC #"D" (&;run "D"
+ (&;satisfies (lambda [c] true))))
+ (should-fail (&;run "C"
+ (&;satisfies (lambda [c] false))))))
(assert "Can apply a lexer multiple times."
- (and (should-passT "0123456789ABCDEF" (&;run (&;many' &;hex-digit) "0123456789ABCDEF yolo"))
- (should-fail (&;run (&;many' &;hex-digit) "yolo"))
+ (and (should-passT "0123456789ABCDEF" (&;run "0123456789ABCDEF yolo"
+ (&;many' &;hex-digit)))
+ (should-fail (&;run "yolo"
+ (&;many' &;hex-digit)))
- (should-passT "" (&;run (&;some' &;hex-digit) "yolo"))))
+ (should-passT "" (&;run "yolo"
+ (&;some' &;hex-digit)))))
))
(test: "Yet more combinators..."
($_ seq
(assert "Can fail at will."
- (should-fail (&;run (&;fail "Well, it really SHOULD fail...") "yolo")))
+ (should-fail (&;run "yolo"
+ (&;fail "Well, it really SHOULD fail..."))))
(assert "Can make assertions."
- (and (should-fail (&;run (&;assert "Well, it really SHOULD fail..." false) "yolo"))
- (|> (&;run (&;assert "GO, GO, GO!" true) "yolo")
+ (and (should-fail (&;run "yolo"
+ (&;assert "Well, it really SHOULD fail..." false)))
+ (|> (&;run "yolo"
+ (&;assert "GO, GO, GO!" true))
(case> (#;Right []) true
_ false))))
(assert "Can apply a lexer multiple times."
(and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;many &;hex-digit) "0123456789ABCDEF yolo"))
- (should-fail (&;run (&;many &;hex-digit) "yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;many &;hex-digit)))
+ (should-fail (&;run "yolo"
+ (&;many &;hex-digit)))
(should-passL (list)
- (&;run (&;some &;hex-digit) "yolo"))))
+ (&;run "yolo"
+ (&;some &;hex-digit)))))
(assert "Can lex exactly N elements."
(and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;exactly +16 &;hex-digit) "0123456789ABCDEF yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;exactly +16 &;hex-digit)))
(should-passL (list #"0" #"1" #"2")
- (&;run (&;exactly +3 &;hex-digit) "0123456789ABCDEF yolo"))
- (should-fail (&;run (&;exactly +17 &;hex-digit) "0123456789ABCDEF yolo"))))
+ (&;run "0123456789ABCDEF yolo"
+ (&;exactly +3 &;hex-digit)))
+ (should-fail (&;run "0123456789ABCDEF yolo"
+ (&;exactly +17 &;hex-digit)))))
(assert "Can lex at-most N elements."
(and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;at-most +16 &;hex-digit) "0123456789ABCDEF yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;at-most +16 &;hex-digit)))
(should-passL (list #"0" #"1" #"2")
- (&;run (&;at-most +3 &;hex-digit) "0123456789ABCDEF yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;at-most +3 &;hex-digit)))
(should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;at-most +17 &;hex-digit) "0123456789ABCDEF yolo"))))
+ (&;run "0123456789ABCDEF yolo"
+ (&;at-most +17 &;hex-digit)))))
(assert "Can lex tokens between lower and upper boundaries of quantity."
(and (should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;between +0 +16 &;hex-digit) "0123456789ABCDEF yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;between +0 +16 &;hex-digit)))
(should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;between +3 +16 &;hex-digit) "0123456789ABCDEF yolo"))
- (should-fail (&;run (&;between +17 +100 &;hex-digit) "0123456789ABCDEF yolo"))
+ (&;run "0123456789ABCDEF yolo"
+ (&;between +3 +16 &;hex-digit)))
+ (should-fail (&;run "0123456789ABCDEF yolo"
+ (&;between +17 +100 &;hex-digit)))
(should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"A" #"B" #"C" #"D" #"E" #"F")
- (&;run (&;between +15 +20 &;hex-digit) "0123456789ABCDEF yolo"))))
+ (&;run "0123456789ABCDEF yolo"
+ (&;between +15 +20 &;hex-digit)))))
(assert "Can optionally lex a token."
- (and (|> (&;run (&;opt &;hex-digit) "123abc")
+ (and (|> (&;run "123abc"
+ (&;opt &;hex-digit))
(case> (#;Right (#;Some #"1")) true
_ false))
- (|> (&;run (&;opt &;hex-digit) "yolo")
+ (|> (&;run "yolo"
+ (&;opt &;hex-digit))
(case> (#;Right #;None) true
_ false))))
(assert "Can take into account separators during lexing."
(should-passL (list #"0" #"1" #"2" #"3" #"4" #"5" #"6" #"7" #"8" #"9" #"a" #"b" #"c" #"d" #"e" #"f")
- (&;run (&;sep-by &;space &;hex-digit) "0 1 2 3 4 5 6 7 8 9 a b c d e f YOLO")))
+ (&;run "0 1 2 3 4 5 6 7 8 9 a b c d e f YOLO"
+ (&;sep-by &;space &;hex-digit))))
(assert "Can obtain the whole of the remaining input."
- (should-passT "yolo" (&;run &;get-input "yolo")))
+ (should-passT "yolo" (&;run "yolo"
+ &;get-input)))
))
diff --git a/stdlib/test/test/lux/regex.lux b/stdlib/test/test/lux/regex.lux
index 281e6dbad..6c6854ce0 100644
--- a/stdlib/test/test/lux/regex.lux
+++ b/stdlib/test/test/lux/regex.lux
@@ -23,7 +23,7 @@
## [Utils]
(def: (should-pass regex input)
(-> (lexer;Lexer Text) Text Bool)
- (|> (lexer;run regex input)
+ (|> (lexer;run input regex)
(case> (#;Right parsed)
(T/= parsed input)
@@ -32,7 +32,7 @@
(def: (should-passT test regex input)
(-> Text (lexer;Lexer Text) Text Bool)
- (|> (lexer;run regex input)
+ (|> (lexer;run input regex)
(case> (#;Right parsed)
(T/= test parsed)
@@ -41,11 +41,11 @@
(def: (should-fail regex input)
(All [a] (-> (lexer;Lexer a) Text Bool))
- (|> (lexer;run regex input)
+ (|> (lexer;run input regex)
(case> (#;Left _) true _ false)))
(syntax: (should-check pattern regex input)
- (wrap (list (` (|> (lexer;run (~ regex) (~ input))
+ (wrap (list (` (|> (lexer;run (~ input) (~ regex))
(case> (^ (#;Right (~ pattern)))
true