aboutsummaryrefslogtreecommitdiffhomepage
path: root/samples/fun/minibruijn.bruijn
blob: 136498318c3ba941300e154edba1bd164ec3c13a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# MIT License, Copyright (c) 2024 Marvin Borner

:import std/Char C
:import std/Combinator .
:import std/List .
:import std/Meta M
:import std/Monad/Parser .
:import std/Number/Conversion O
:import std/Result R

# meta encoding uses Church numerals instead of binary!
char→number (\C.sub '0') → O.binary→unary

identifier satisfy (c ∘ C.space?)

spaces many (satisfy C.space?)

newlines some (satisfy (C.eq? '\n'))

parens between (char '(') (char ')')

number char→number <$> (satisfy C.numeric?)

term y [(foldl1 M.app) <$> (some (spaces *> singleton <* spaces))]
	singleton abs <|> idx <|> (parens 0)
		abs M.abs <$> (between (char '[') (char ']') 0)
		idx M.idx <$> number

block identifier <*> term

program block >>= newlines

main (M.eval <$> term) → [0 i i]