mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
fix parser type
This commit is contained in:
parent
1cbb2a6f9a
commit
2af901f0cf
|
@ -31,7 +31,7 @@ fn typehint_parser() -> impl Parser<Token, Spanned<Typehint>, Error = Simple<Tok
|
||||||
(Typehint::Vector(Box::new(arg)), span)
|
(Typehint::Vector(Box::new(arg)), span)
|
||||||
});
|
});
|
||||||
|
|
||||||
let function = ty
|
let function = ty.clone()
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
.allow_trailing()
|
.allow_trailing()
|
||||||
.delimited_by(
|
.delimited_by(
|
||||||
|
@ -39,7 +39,7 @@ fn typehint_parser() -> impl Parser<Token, Spanned<Typehint>, Error = Simple<Tok
|
||||||
just(Token::Pipe),
|
just(Token::Pipe),
|
||||||
)
|
)
|
||||||
.then_ignore(just(Token::Arrow))
|
.then_ignore(just(Token::Arrow))
|
||||||
.then(single)
|
.then(ty)
|
||||||
.map_with_span(|(args, ret), span| {
|
.map_with_span(|(args, ret), span| {
|
||||||
(Typehint::Function(args, Box::new(ret)), span)
|
(Typehint::Function(args, Box::new(ret)), span)
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
fun iter_ (vec: vec_int) (current: int): void = do
|
fun iter_ (vec: [int]) (fn: |int| -> int) (current: int): void = do
|
||||||
if current == @len(vec) then
|
if current == @len(vec) then
|
||||||
do end
|
do end
|
||||||
else
|
else
|
||||||
do
|
do
|
||||||
-- iter logic
|
@get(vec, current)
|
||||||
-- TODO: function as argument
|
|> fn(_)
|
||||||
@get(vec, current) |> @write(_)
|
|> @write(_)
|
||||||
@write("\n")
|
@write("\n")
|
||||||
|
|
||||||
iter_(vec, current + 1)
|
iter_(vec, fn, current + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun iter (vec: vec_int): void = do
|
fun iter (vec: [int]) (fn: |int| -> int): void = iter_(vec, fn, 0)
|
||||||
iter_(vec, 0)
|
|
||||||
end
|
fun mul10 (x: int): int = x * 10
|
||||||
|
|
||||||
fun main: void = do
|
fun main: void = do
|
||||||
let foo: vec_int = [69, 420, 727, 1337, 42069, 69420]
|
let foo: [int] = [69, 420, 727, 1337, 42069, 69420]
|
||||||
iter(foo)
|
iter(foo, mul10)
|
||||||
end
|
end
|
|
@ -1,14 +0,0 @@
|
||||||
fun mul (foo: int) (bar: int) : int = foo * bar
|
|
||||||
fun map
|
|
||||||
(fn: |int, int| -> int)
|
|
||||||
(to: int)
|
|
||||||
: int
|
|
||||||
= fn(to, 10)
|
|
||||||
|
|
||||||
fun main: void = do
|
|
||||||
let foo : int = 69
|
|
||||||
let bar : int = 10
|
|
||||||
|
|
||||||
map(mul, foo)
|
|
||||||
|> @write(_)
|
|
||||||
end
|
|
Loading…
Reference in a new issue