-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump version * Update README to show the right version of llvm * Add the self returning method with `@->` * Add tests for self returning function * Add an embryo of documentation with mdbook * Documentation * Fix doc about struct * Doc * Add \0 as escaped char and generalize escaped char parsing (#125) * Add \0 as escaped char and generalize escaped char parsing * Inline parser variable in parse_char method * Readme * Readme * Escaped chars (#132) * Add \0 as escaped char and generalize escaped char parsing * Inline parser variable in parse_char method * Better unescaped handling * Fix escaped backslack and add tests * Restored string unescape * Fixed the `\0` escaped char * Doc * Introducing default trait methods (#128) * Introducing default trait methods * Allow for empty impl * Readme * Add tests * Allow for default method overriding * Add tests for default method overriding * Doc * Fix dot notation newline (#140) * Fix dot notation by restricting newline in dot notation when parsing an argument * Readme * Struct fields are no more reordered. (#138) * Struct fields are no more reordered. * Removed comment * Removed some old readme entry * Submodule parser errors (#137) * Subparser now fails when error * Transformed the module declaration error to failure * Fixed the diagnostic in submodule not showing
- Loading branch information
Showing
42 changed files
with
1,149 additions
and
163 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[book] | ||
authors = ["Champii"] | ||
language = "en" | ||
multilingual = false | ||
src = "src" | ||
title = "Rock v0.4.2 language documentation" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Summary | ||
|
||
[Introduction](./intro.md) | ||
- [Quick start](./quick_start.md) | ||
- [Language reference](./language_reference.md) | ||
- [Primitives](./primitives.md) | ||
- [Function](./function_decl.md) | ||
- [Function signature](./function_signature.md) | ||
- [Struct](./struct.md) | ||
- [Trait](./trait.md) | ||
- [Self](./self.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Function | ||
|
||
## Syntax | ||
|
||
The function declaration format is: | ||
|
||
```haskell | ||
function_name: arg1, arg2, arg3 -> return_value | ||
``` | ||
|
||
The function call format is: | ||
|
||
```haskell | ||
function_name arg1, arg2, arg3 | ||
``` | ||
|
||
But you can add parenthesis | ||
|
||
```haskell | ||
function_name(arg1, arg2, arg3) | ||
``` | ||
|
||
Every Rock package must have a `./src/main.rk` file containing a `main` function | ||
|
||
```haskell | ||
main: -> "Hello World!".print! | ||
``` | ||
|
||
You can call functions with no args with a bang `!` like the `.print!` above or with | ||
explicit parenthesis like `.print()` | ||
But the idiomatic way is to avoid parenthesis as much as possible | ||
|
||
```haskell | ||
add: x, y -> x + y | ||
main: -> add 2, 3 | ||
``` | ||
|
||
Rock does not allow for uppercase identifiers, so you should embrace the snake case. | ||
Uppercase names are reserved for custom types like [Struct](./struct.md) or [Trait](./trait.md) | ||
|
||
## Polymorphism | ||
|
||
Every function in Rock is polymorphic by default, and only infer the types based on the caller and the return value of its body. | ||
Multiple calls with different types will generate each corresponding function, just like the templates in C++ or in Rust, except the generic parameter is always implicit if no constraints have been made. | ||
|
||
For example, lets declare the most polymorphic function of all, `id`: | ||
|
||
```haskell | ||
id: x -> x | ||
``` | ||
|
||
This function takes a `x` argument and returns it. Here `x` can be of any type | ||
|
||
```haskell | ||
main: -> | ||
id 42 | ||
id 6.66 | ||
id "Hello" | ||
id my_custom_struct | ||
``` | ||
|
||
The infered signature of the function is `id: a => a`, with `a` being any type | ||
|
||
If we had changed the body of `id` to be: | ||
|
||
```haskell | ||
id: x -> x + x | ||
``` | ||
|
||
the previous main would still work if all of the types implemented the `Num` trait from the stdlib, that provide implementation of `+` for the basic types | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Function signature | ||
|
||
## Syntax | ||
|
||
```haskell | ||
trait MyTrait a | ||
my_func: a => Int64 => String | ||
``` | ||
|
||
Here, the `my_func` method takes 2 arguments of type `a` (generic) and `Int64`, and returns a `String` | ||
|
||
A signature is always formed of at least one type. | ||
The last (or only) type is the return type | ||
|
||
Functions can take functions as parameter, and must be representable in a signature: | ||
|
||
```haskell | ||
trait MyTrait a | ||
my_func: a => (a => b) => b | ||
``` | ||
|
||
Here the first argument of the method `my_func` is the `self`, the second is a function that take the generic type `a` taken from the trait definition and returns a type `b`, and the whole method returns a type `b` | ||
|
||
An implementation of this trait would be: | ||
|
||
```haskell | ||
impl MyTrait Int64 | ||
my_func: f -> f @ | ||
|
||
# A function of type (a => b) | ||
handler: x -> x.show! | ||
|
||
main: -> (2).my_func handler .print! | ||
``` | ||
|
||
This outputs: | ||
|
||
``` | ||
2 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Introduction | ||
|
||
Rock is an experimental native language. | ||
|
||
Its main goal is to mix some parts of popular functionnal languages like haskell or livescript with | ||
the rigor of Rust while staying elegant and fast with minimal runtime | ||
|
||
Rock is at an early development stage. Don't expect everything to work smoothly. (you have been warned) | ||
|
||
```haskell | ||
struct Player | ||
level: Int64 | ||
name: String | ||
|
||
impl Player | ||
new: x -> | ||
Player | ||
level: x | ||
name: "MyName" | ||
|
||
impl Show Player | ||
@show: -> @name + "(" + @level.show! + ")" | ||
|
||
use std::print::printl | ||
|
||
impl Print Player | ||
@print: -> printl @ | ||
|
||
main: -> | ||
let player = Player::new 42 | ||
player.print! | ||
``` | ||
|
||
Rock syntax is entierly based on indentation, like Livescript. | ||
Each whitespace count, and tabulations `\t` are prohibited. | ||
|
||
The number of whitespace to make one level of indentation is taken from the first indent level. | ||
If your first indentation has two whitespaces, the rest of the file must have the same number of whitespace per level (here two) | ||
|
||
We generally use two as a default, but you can use any number you want. Here is the same example with four whitespaces: | ||
|
||
```haskell | ||
struct Player | ||
level: Int64 | ||
name: String | ||
|
||
impl Player | ||
new: x -> | ||
Player | ||
level: x | ||
name: "MyName" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Language reference | ||
|
Oops, something went wrong.