aboutsummaryrefslogtreecommitdiffhomepage
path: root/std/Monad/Parser.bruijn
diff options
context:
space:
mode:
authorMarvin Borner2024-10-26 20:36:13 +0200
committerMarvin Borner2024-10-26 20:49:11 +0200
commitf0114240cecd453c2be7bb760455f0eb5b7a02a0 (patch)
tree25701a05e4bf6df011baca7a3ac9c2ce653c3882 /std/Monad/Parser.bruijn
parent072707de34348a1c01eeeb90006c5ca828d2a992 (diff)
Initial minibruijn
Diffstat (limited to 'std/Monad/Parser.bruijn')
-rw-r--r--std/Monad/Parser.bruijn9
1 files changed, 7 insertions, 2 deletions
diff --git a/std/Monad/Parser.bruijn b/std/Monad/Parser.bruijn
index e11b662..c6b53a3 100644
--- a/std/Monad/Parser.bruijn
+++ b/std/Monad/Parser.bruijn
@@ -1,15 +1,18 @@
# MIT License, Copyright (c) 2024 Marvin Borner
+# see samples/fun/minibruijn for example usage
:import std/List .
:import std/Combinator .
:import std/Char C
:import std/Result R
+# TODO: don't just use strings for errors
+
error-unexpected ["unexpected symbol " ++ 0] ⧗ Error
error-end-of-input "end of input" ⧗ Error
-compose [[1 ++ " or " ++ 0]] ⧗ Error → Error → Error
+compose [[C.?eq? 1 0 0 (1 ++ " or " ++ 0)]] ⧗ Error → Error → Error
satisfy [[0 [[[go]]] end]] ⧗ (a → Boolean) → (Parser a)
go 4 2 (R.ok (2 : 1)) (R.err (error-unexpected {}2))
@@ -62,7 +65,9 @@ alt [[[2 0 R.ok err]]] ⧗ (Parser a) → (Parser a) → (Parser a)
# most relevant functions are defined - we can now derive from Generic/Monad! #
# =========================================================================== #
-:input std/Monad/Generic
+:input std/Generic/Monad
:test (k <$ (string "ab") "abc") (R.ok (k : "c"))
:test ((char '{') *> (string "wow") <* (char '}') "{wow}{owo}") (R.ok ("wow" : "{owo}"))
+
+between [[[2 *> 0 <* 1]]] ⧗ (Parser a) → (Parser a) → (Parser a)