mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
Compare commits
No commits in common. "8cfeb61549c2767c01d93a6f1c02da524ba28e72" and "1cbb2a6f9a111c74240f51dc6f7fd05520dde7f9" have entirely different histories.
8cfeb61549
...
1cbb2a6f9a
12
README.md
12
README.md
|
@ -2,16 +2,16 @@
|
||||||
Programming language that compiles to Typescript!
|
Programming language that compiles to Typescript!
|
||||||
|
|
||||||
```sml
|
```sml
|
||||||
fun main : void = do
|
fun main: void = do
|
||||||
@write("Hello, World!")
|
@write("Hello, World!");
|
||||||
end
|
end;
|
||||||
```
|
```
|
||||||
or with the pipeline operator:
|
or with the pipeline operator:
|
||||||
```sml
|
```sml
|
||||||
fun main : void = do
|
fun main: void = do
|
||||||
"Hello, World!\n"
|
"Hello, World!\n"
|
||||||
|> @write(_)
|
|> @write(_);
|
||||||
end
|
end;
|
||||||
```
|
```
|
||||||
|
|
||||||
Note: Everything in this project can be changed at anytime! (I'm still finding out what work best for lots of thing) if you have an idea, feel free to create an issues about it, or even create a PR! (I'd be very happy)
|
Note: Everything in this project can be changed at anytime! (I'm still finding out what work best for lots of thing) if you have an idea, feel free to create an issues about it, or even create a PR! (I'd be very happy)
|
||||||
|
|
92
SYNTAX.md
Normal file
92
SYNTAX.md
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
# Syntax
|
||||||
|
> This language is still in development, the syntax can be changed at anytime.
|
||||||
|
|
||||||
|
Hazure is a [free-form](https://en.wikipedia.org/wiki/Free-form_language) syntax style, so the indentation is purely for readability.
|
||||||
|
|
||||||
|
```sml
|
||||||
|
fun main: void = do
|
||||||
|
@write("Hello, World!");
|
||||||
|
end;
|
||||||
|
```
|
||||||
|
|
||||||
|
is the same as
|
||||||
|
|
||||||
|
```sml
|
||||||
|
fun main: void = do @write("Hello, World!"); end;
|
||||||
|
```
|
||||||
|
|
||||||
|
Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-oriented_programming_language) like OCaml. There are currently 10 expressions:
|
||||||
|
|
||||||
|
1) Comment
|
||||||
|
```
|
||||||
|
-- Comment!
|
||||||
|
-{ Block Comment }-
|
||||||
|
```
|
||||||
|
2) Values / Types
|
||||||
|
```sml
|
||||||
|
1
|
||||||
|
true
|
||||||
|
"string"
|
||||||
|
variable
|
||||||
|
```
|
||||||
|
3) Unary and Binary
|
||||||
|
```sml
|
||||||
|
1 + 2
|
||||||
|
!true
|
||||||
|
```
|
||||||
|
4) Call and Intrinsic. Intrinsic starts with a `@`
|
||||||
|
```sml
|
||||||
|
@write("Hello")
|
||||||
|
foo("bar")
|
||||||
|
```
|
||||||
|
5) Pipeline
|
||||||
|
```sml
|
||||||
|
"Hello, World" |> @write(_)
|
||||||
|
```
|
||||||
|
6) Variable declaration
|
||||||
|
```sml
|
||||||
|
let foo: int = 727;
|
||||||
|
let bar: string = "Hi";
|
||||||
|
let baz: boolean = true;
|
||||||
|
```
|
||||||
|
7) Function declaration
|
||||||
|
```sml
|
||||||
|
fun foo: void = @write("void returns nothing");
|
||||||
|
fun bar (x: int): int = x + 1;
|
||||||
|
fun baz (x: int) (y: int): int = x + y;
|
||||||
|
```
|
||||||
|
8) If conditions
|
||||||
|
```sml
|
||||||
|
let cond: bool = true;
|
||||||
|
if cond then
|
||||||
|
@write("True");
|
||||||
|
else
|
||||||
|
do
|
||||||
|
@write("False");
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
```
|
||||||
|
9) Case matching
|
||||||
|
```sml
|
||||||
|
match 1 + 1 with
|
||||||
|
| 2 -> @write("Yes");
|
||||||
|
| else @write("How?");
|
||||||
|
end;
|
||||||
|
```
|
||||||
|
10) Do notation. It allows you to have multiple expression because something like right hand side of the function declaration `fun a: int = ...` can only have 1 expression. Do allows you to bypass that.
|
||||||
|
```sml
|
||||||
|
do
|
||||||
|
@write("Hello, World");
|
||||||
|
foo(bar);
|
||||||
|
let baz: int = 6 + 10;
|
||||||
|
end;
|
||||||
|
```
|
||||||
|
|
||||||
|
Hazure isn't a scripting language, so, you will need a main function.
|
||||||
|
|
||||||
|
```sml
|
||||||
|
fun main: void = do
|
||||||
|
@write("Hello, World");
|
||||||
|
@write(34 + 35);
|
||||||
|
end;
|
||||||
|
```
|
|
@ -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.clone()
|
let function = ty
|
||||||
.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(ty)
|
.then(single)
|
||||||
.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: [int]) (fn: |int| -> int) (current: int): void = do
|
fun iter_ (vec: vec_int) (current: int): void = do
|
||||||
if current == @len(vec) then
|
if current == @len(vec) then
|
||||||
do end
|
do end
|
||||||
else
|
else
|
||||||
do
|
do
|
||||||
@get(vec, current)
|
-- iter logic
|
||||||
|> fn(_)
|
-- TODO: function as argument
|
||||||
|> @write(_)
|
@get(vec, current) |> @write(_)
|
||||||
@write("\n")
|
@write("\n")
|
||||||
|
|
||||||
iter_(vec, fn, current + 1)
|
iter_(vec, current + 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun iter (vec: [int]) (fn: |int| -> int): void = iter_(vec, fn, 0)
|
fun iter (vec: vec_int): void = do
|
||||||
|
iter_(vec, 0)
|
||||||
fun mul10 (x: int): int = x * 10
|
end
|
||||||
|
|
||||||
fun main: void = do
|
fun main: void = do
|
||||||
let foo: [int] = [69, 420, 727, 1337, 42069, 69420]
|
let foo: vec_int = [69, 420, 727, 1337, 42069, 69420]
|
||||||
iter(foo, mul10)
|
iter(foo)
|
||||||
end
|
end
|
14
example/tuples.hz
Normal file
14
example/tuples.hz
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
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