Skip to content

Commit

Permalink
Merge pull request #15 from Flipez/next
Browse files Browse the repository at this point in the history
Release RocketLang 0.10.0
  • Loading branch information
Flipez authored Dec 27, 2021
2 parents 6a78b29 + b52b662 commit af450b9
Show file tree
Hide file tree
Showing 81 changed files with 5,201 additions and 2,531 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
go-version: 1.17
- name: Test
run: go test ./...
run: go test -coverpkg=./... ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
go-version: 1.17
- name: Test
run: go test `go list ./... | grep -v examples` -coverprofile=coverage.txt -covermode=atomic
run: ./coverage.sh
- name: Codecov
uses: codecov/codecov-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ nfpms:
license: MIT
formats:
- deb
file_name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}"
file_name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}_{{ .Tag }}"

# .goreleaser.yml
brews:
Expand Down
101 changes: 9 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
[![Test Status](https://github.com/Flipez/rocket-lang/actions/workflows/test.yml/badge.svg)](https://github.com/Flipez/rocket-lang/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/Flipez/rocket-lang/branch/master/graph/badge.svg)](https://codecov.io/gh/Flipez/rocket-lang)

> Checkout the documentation at https://rocket-lang.org
RocketLang as of version 0.9.5 is the _full_ (as in the book was worked through) version of [MonkeyLang](https://monkeylang.org/) and is then being extended with various useful and not so useful features.

Besides the MonkeyLang roots RocketLang is also heavily influenced by my personal favourite language features which are mainly from Ruby. Therefore a unusual mix of usage patterns can occure. With newly implemented feature RocketLang will drift more and more into a Ruby-like language adaptation.

**Please note:** This language is developed as a side-project to learn the inner mechanics of a interpreter language. Therefore use at your own risk and do not expect production grade stability.

If you have issues, found bugs are ideas for improvements feel free to open an issues.

## Installation

Install RocketLang using
Expand All @@ -20,95 +28,4 @@ or download from [releases](https://github.com/Flipez/rocket-lang/releases).
* `rocket-lang` without any arguments will start an interactive shell
* `rocket-lang FILE` will run the code in that file (no file extension check yet)
* Use _Javascript_ Highlighting in your editor for some convenience
* Checkout Code [Samples](examples/) for what is currently possible (and what not)

## Examples
### Variables
```js
let some_integer = 1;
let name = "RocketLang";
let array = [1, 2, 3, 4, 5];
let some_boolean = true;
```

Also expressions can be used
```js
let another_int = (10 / 2) * 5 + 30;
let an_array = [1 + 1, 2 * 2, 3];
```

### Functions
Implicit and explicit return statements are supported.
```js
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
```
### Closures
```js
let newGreeter = fn(greeting) {
return fn(name) { puts(greeting + " " + name); }
};

let hello = newGreeter("Hello");

hello("dear, future Reader!");

```

### Builtin Functions
|Function|Argument(s)|Return Value(s)|Description|
|--|--|--|--|
|`len()`|`array`|`int`|Returns the size of the provided `array`.|
|`first()`|`array`|`any`, `null`|Returns the first object from `array` or `null` if `array` is empty|
|`last()`|`array`|`any`, `null`|Returns the last object from `array` or `null` if `array` is empty|
|`push()`|`array`;`any`|`array`|Returns new `array` advanced by one with given object as last element of given `array`|
|`pop()`|`array`|`array`|Returns the the given `array` as element one without the last object, returns the last object as second element|
|`puts()`|`string`|`null`|Prints the given `string` to stdout|
|`exit()`|`int`|-|Terminates program with exit code `int`|
|`raise()`|`int`; `string`|-|Prints `string` and terminates programm with exit code `int`|

### Data Types
#### Strings
```js
let a = "test_string;
let b = "test" + "_string";
let is_true = "test" == "test";
let is_false = "test" == "string";
```
#### Integer
```js
let a = 1;
let b = a + 2;
let is_true = 1 == 1;
let is_false = 1 == 2;
```
#### Boolean
```js
let a = true;
let b = false;
let is_true = a == a;
let is_false = a == b;
let is_true = a != b;
```
#### Hashes
```js
let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}];
```
* Checkout Code [Samples](examples/) for what is currently possible (and what not)
58 changes: 58 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,61 @@ func (ce *CallExpression) String() string {

return out.String()
}

type ObjectCallExpression struct {
Token token.Token
Object Expression
Call Expression
}

func (oce *ObjectCallExpression) expressionNode() {}

func (oce *ObjectCallExpression) TokenLiteral() string {
return oce.Token.Literal
}

func (oce *ObjectCallExpression) String() string {
var out bytes.Buffer
out.WriteString(oce.Object.String())
out.WriteString(".")
out.WriteString(oce.Call.String())

return out.String()
}

type ForeachStatement struct {
Token token.Token
Index string
Ident string
Value Expression
Body *BlockStatement
}

func (fes *ForeachStatement) expressionNode() {}
func (fes *ForeachStatement) TokenLiteral() string { return fes.Token.Literal }
func (fes *ForeachStatement) String() string {
var out bytes.Buffer
out.WriteString("foreach ")
out.WriteString(fes.Ident)
out.WriteString(" ")
out.WriteString(fes.Value.String())
out.WriteString(fes.Body.String())
return out.String()
}

type AssignStatement struct {
Token token.Token
Name *Identifier
Value Expression
}

func (as *AssignStatement) expressionNode() {}
func (as *AssignStatement) statementNode() {}
func (as *AssignStatement) TokenLiteral() string { return as.Token.Literal }
func (as *AssignStatement) String() string {
var out bytes.Buffer
out.WriteString(as.Name.String())
out.WriteString(" = ")
out.WriteString(as.Value.String())
return out.String()
}
3 changes: 3 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage:
status:
patch: off
11 changes: 11 additions & 0 deletions coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
echo "" > coverage.txt

for d in $(go list ./... | grep -v vendor); do
go test -coverprofile=profile.out -covermode=atomic -coverpkg=./... $d
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
rm profile.out
fi
done
2 changes: 1 addition & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# hugo server --minify --themesDir ... --baseURL=http://0.0.0.0:1313/theme/hugo-book/

baseURL: https://rocket-lang.vercel.app/
baseURL: /
title: 🚀🇱🅰🆖
theme: hugo-book

Expand Down
55 changes: 38 additions & 17 deletions docs/content/_index.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
---
title: Introduction
title: Home
type: docs
---

# Welcome to the Home of 🚀🇱🅰🆖

{{< columns >}}
## About

Information about RocketLang
RocketLang as of version 0.9.5 is the full (as in the book was worked through) version of [MonkeyLang](https://monkeylang.org/) and
is then being extended with various useful and not so useful features.

<--->

## Latest Version

Information about latest versions.
{{< /columns >}}

[![GitHub release](https://img.shields.io/github/release/flipez/rocket-lang.svg)](https://github.com/flipez/rocket-lang/releases/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/flipez/rocket-lang.svg)](https://github.com/flipez/rocket-lang)
[![Percentage of issues still open](http://isitmaintained.com/badge/open/flipez/rocket-lang.svg)](https://github.com/flipez/rocket-lang)

{{< /columns >}}
## Quick Start

Lorem **markdownum** emicat gestu. Cannis sol pressit ducta. **Est** Idaei,
tremens ausim se tutaeque, illi ulnis hausit, sed, lumina cutem. Quae avis
sequens!

var panel = ram_design;
if (backup + system) {
file.readPoint = network_native;
sidebar_engine_device(cell_tftp_raster,
dual_login_paper.adf_vci.application_reader_design(
graphicsNvramCdma, lpi_footer_snmp, integer_model));
}
Get started with 🚀🇱🅰🆖 quickly with these examples:

```js
let input = open("examples/aoc/2021/day-1/input").lines()


let a = []
foreach i, number in input {
a.yoink(number.strip().plz_i())
}
input = a

let increase = 0
foreach i, number in input {
if (number > input[i-1]) {
increase = increase + 1
}
}
puts(increase + 1)

increase = 0
foreach i, number in input {
let sum = number + input[i+1] + input[i+2]
let sum_two = input[i+1] + input[i+2] + input[i+3]

if (sum_two > sum) {
increase = increase + 1
}
}
puts(increase + 1)
```
71 changes: 0 additions & 71 deletions docs/content/docs/example/_index.md

This file was deleted.

Loading

0 comments on commit af450b9

Please sign in to comment.