aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control/parser/synthesis.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/control/parser/synthesis.lux')
-rw-r--r--stdlib/source/lux/control/parser/synthesis.lux40
1 files changed, 28 insertions, 12 deletions
diff --git a/stdlib/source/lux/control/parser/synthesis.lux b/stdlib/source/lux/control/parser/synthesis.lux
index f08159848..c36c61601 100644
--- a/stdlib/source/lux/control/parser/synthesis.lux
+++ b/stdlib/source/lux/control/parser/synthesis.lux
@@ -6,7 +6,13 @@
["." exception (#+ exception:)]]
[data
["." error (#+ Error)]
- [text
+ ["." bit]
+ ["." name]
+ [number
+ ["." i64]
+ ["." frac]
+ ["." nat]]
+ ["." text
format]]
[tool
[compiler
@@ -56,8 +62,8 @@
(#.Cons [head tail])
(#error.Success [tail head]))))
-(template [<name> <tag> <type>]
- [(def: #export <name>
+(template [<query> <assertion> <tag> <type> <eq>]
+ [(def: #export <query>
(Parser <type>)
(.function (_ input)
(case input
@@ -65,17 +71,27 @@
(#error.Success [input' x])
_
+ (exception.throw ..cannot-parse input))))
+
+ (def: #export (<assertion> expected)
+ (-> <type> (Parser Any))
+ (.function (_ input)
+ (case input
+ (^ (list& (<tag> actual) input'))
+ (if (:: <eq> = expected actual)
+ (#error.Success [input' []])
+ (exception.throw ..cannot-parse input))
+
+ _
(exception.throw ..cannot-parse input))))]
- [bit /.bit Bit]
- [i64 /.i64 (I64 Any)]
- [f64 /.f64 Frac]
- [text /.text Text]
- [variant /.variant (Variant Synthesis)]
- [local /.variable/local Nat]
- [foreign /.variable/foreign Nat]
- [constant /.constant Name]
- [abstraction /.function/abstraction Abstraction]
+ [bit bit! /.bit Bit bit.equivalence]
+ [i64 i64! /.i64 (I64 Any) i64.equivalence]
+ [f64 f64! /.f64 Frac frac.equivalence]
+ [text text! /.text Text text.equivalence]
+ [local local! /.variable/local Nat nat.equivalence]
+ [foreign foreign! /.variable/foreign Nat nat.equivalence]
+ [constant constant! /.constant Name name.equivalence]
)
(def: #export (tuple parser)