From d1bb32a2327abbda351848ee4bc46f8857420ca3 Mon Sep 17 00:00:00 2001 From: Flipez Date: Tue, 6 Dec 2022 11:12:59 +0100 Subject: [PATCH] update docs Signed-off-by: Flipez --- docs/docusaurus.config.js | 2 +- .../version-v0.21.0/builtins/HTTP.md | 23 ++ .../version-v0.21.0/builtins/IO.md | 25 ++ .../version-v0.21.0/builtins/JSON.md | 27 ++ .../version-v0.21.0/builtins/Math.md | 254 +++++++++++++++++ .../version-v0.21.0/builtins/OS.md | 37 +++ .../version-v0.21.0/builtins/Time.md | 89 ++++++ .../version-v0.21.0/builtins/_category_.yml | 1 + .../control_expressions/_category_.yml | 1 + .../control_expressions/foreach.md | 82 ++++++ .../version-v0.21.0/control_expressions/if.md | 19 ++ .../control_expressions/while.md | 25 ++ docs/versioned_docs/version-v0.21.0/index.md | 54 ++++ .../versioned_docs/version-v0.21.0/install.md | 31 +++ .../version-v0.21.0/language/_category_.yml | 1 + .../version-v0.21.0/language/modules.md | 46 ++++ .../version-v0.21.0/language/operators.md | 8 + .../version-v0.21.0/literals/_category_.yml | 1 + .../version-v0.21.0/literals/array.md | 210 +++++++++++++++ .../version-v0.21.0/literals/boolean.md | 84 ++++++ .../version-v0.21.0/literals/error.md | 108 ++++++++ .../version-v0.21.0/literals/file.md | 127 +++++++++ .../version-v0.21.0/literals/float.md | 92 +++++++ .../version-v0.21.0/literals/hash.md | 131 +++++++++ .../version-v0.21.0/literals/http.md | 107 ++++++++ .../version-v0.21.0/literals/integer.md | 111 ++++++++ .../version-v0.21.0/literals/nil.md | 94 +++++++ .../version-v0.21.0/literals/string.md | 255 ++++++++++++++++++ .../specification/_category_.yml | 1 + .../version-v0.21.0/specification/builtins.md | 22 ++ .../version-v0.21.0/specification/closures.md | 20 ++ .../version-v0.21.0/specification/comments.md | 18 ++ .../specification/functions.md | 40 +++ .../specification/local_variables.md | 27 ++ .../version-v0.21.0-sidebars.json | 8 + docs/versions.json | 1 + 36 files changed, 2181 insertions(+), 1 deletion(-) create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/HTTP.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/IO.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/JSON.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/Math.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/OS.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/Time.md create mode 100644 docs/versioned_docs/version-v0.21.0/builtins/_category_.yml create mode 100644 docs/versioned_docs/version-v0.21.0/control_expressions/_category_.yml create mode 100644 docs/versioned_docs/version-v0.21.0/control_expressions/foreach.md create mode 100644 docs/versioned_docs/version-v0.21.0/control_expressions/if.md create mode 100644 docs/versioned_docs/version-v0.21.0/control_expressions/while.md create mode 100644 docs/versioned_docs/version-v0.21.0/index.md create mode 100644 docs/versioned_docs/version-v0.21.0/install.md create mode 100644 docs/versioned_docs/version-v0.21.0/language/_category_.yml create mode 100644 docs/versioned_docs/version-v0.21.0/language/modules.md create mode 100644 docs/versioned_docs/version-v0.21.0/language/operators.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/_category_.yml create mode 100644 docs/versioned_docs/version-v0.21.0/literals/array.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/boolean.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/error.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/file.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/float.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/hash.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/http.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/integer.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/nil.md create mode 100644 docs/versioned_docs/version-v0.21.0/literals/string.md create mode 100644 docs/versioned_docs/version-v0.21.0/specification/_category_.yml create mode 100644 docs/versioned_docs/version-v0.21.0/specification/builtins.md create mode 100644 docs/versioned_docs/version-v0.21.0/specification/closures.md create mode 100644 docs/versioned_docs/version-v0.21.0/specification/comments.md create mode 100644 docs/versioned_docs/version-v0.21.0/specification/functions.md create mode 100644 docs/versioned_docs/version-v0.21.0/specification/local_variables.md create mode 100644 docs/versioned_sidebars/version-v0.21.0-sidebars.json diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.js index c60c2b1..2267cd8 100644 --- a/docs/docusaurus.config.js +++ b/docs/docusaurus.config.js @@ -32,7 +32,7 @@ const config = { sidebarPath: require.resolve('./sidebars.js'), editUrl: 'https://github.com/flipez/rocket-lang/tree/main/docs/', - lastVersion: 'v0.20.1', + lastVersion: 'v0.21.0', }, theme: { customCss: require.resolve('./src/css/custom.css'), diff --git a/docs/versioned_docs/version-v0.21.0/builtins/HTTP.md b/docs/versioned_docs/version-v0.21.0/builtins/HTTP.md new file mode 100644 index 0000000..f50737d --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/HTTP.md @@ -0,0 +1,23 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# HTTP + + + + +## Module Function + +### new() +> Returns `HTTP` + +Creates a new instance of HTTP + + + + + + +## Properties +| Name | Value | +| ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/IO.md b/docs/versioned_docs/version-v0.21.0/builtins/IO.md new file mode 100644 index 0000000..98669ab --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/IO.md @@ -0,0 +1,25 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# IO + + + + +## Module Function + +### open(STRING, STRING, STRING) +> Returns `FILE` + +Opens a file pointer to the file at the path, mode and permission can be set optionally. + + + + + + +## Properties +| Name | Value | +| ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/JSON.md b/docs/versioned_docs/version-v0.21.0/builtins/JSON.md new file mode 100644 index 0000000..285f04e --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/JSON.md @@ -0,0 +1,27 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# JSON + + + + +## Module Function + +### parse(STRING) +> Returns `HASH` + +Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. + + + + + + +## Properties +| Name | Value | +| ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/Math.md b/docs/versioned_docs/version-v0.21.0/builtins/Math.md new file mode 100644 index 0000000..fdbaac1 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/Math.md @@ -0,0 +1,254 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Math + + + + +## Module Function + +### abs(FLOAT) +> Returns `FLOAT` + + + + + + + +### acos(FLOAT) +> Returns `FLOAT` + +Returns the arccosine, in radians, of the argument + + + + + +### asin(FLOAT) +> Returns `FLOAT` + +Returns the arcsine, in radians, of the argument + + + + + +### atan(FLOAT) +> Returns `FLOAT` + +Returns the arctangent, in radians, of the argument + + + + + +### ceil(FLOAT) +> Returns `FLOAT` + +Returns the least integer value greater or equal to the argument + + + + + +### copysign(FLOAT, FLOAT) +> Returns `FLOAT` + +Returns a value with the magnitude of first argument and sign of second argument + + + + + +### cos(FLOAT) +> Returns `FLOAT` + +Returns the cosine of the radion argument + + + + + +### exp(FLOAT) +> Returns `FLOAT` + +Returns e**argument, the base-e exponential of argument + + + + + +### floor(FLOAT) +> Returns `FLOAT` + +Returns the greatest integer value less than or equal to argument + + + + + +### log(FLOAT) +> Returns `FLOAT` + +Returns the natural logarithm of argument + + + + + +### log10(FLOAT) +> Returns `FLOAT` + +Returns the decimal logarithm of argument + + + + + +### log2(FLOAT) +> Returns `FLOAT` + +Returns the binary logarithm of argument + + + + + +### max(FLOAT, FLOAT) +> Returns `FLOAT` + +Returns the larger of the two numbers + + + + + +### min(FLOAT, FLOAT) +> Returns `FLOAT` + +Returns the smaller of the two numbers + + + + + +### pow(FLOAT, FLOAT) +> Returns `FLOAT` + +Returns argument1**argument2, the base-argument1 exponential of argument2 + + + + + +### rand() +> Returns `FLOAT` + +Returns a pseudo-random number in the half-open interval [0.0, 1.0]. + + + + + +### remainder(FLOAT, FLOAT) +> Returns `FLOAT` + +Returns the IEEE 754 floating-point remainder of argument1/argument2 + + + + + +### round(FLOAT) +> Returns `FLOAT` + +Returns the nearest integer, rounding half away from zero + + + + + +### sin(FLOAT) +> Returns `FLOAT` + +Returns the sine of the radion argument + + + + + +### sqrt(FLOAT) +> Returns `FLOAT` + +Returns the square root of argument + + + + + +### tan(FLOAT) +> Returns `FLOAT` + +Returns the tangent of the radion argument + + + + + + +## Properties +| Name | Value | +| ---- | ----- | +| E | 2.718281828459045 | +| Ln10 | 2.302585092994046 | +| Ln2 | 0.6931471805599453 | +| Log10E | 0.4342944819032518 | +| Log2E | 1.4426950408889634 | +| Phi | 1.618033988749895 | +| Pi | 3.141592653589793 | +| Sqrt2 | 1.4142135623730951 | +| SqrtE | 1.6487212707001282 | +| SqrtPhi | 1.272019649514069 | +| SqrtPi | 1.772453850905516 | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/OS.md b/docs/versioned_docs/version-v0.21.0/builtins/OS.md new file mode 100644 index 0000000..762026e --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/OS.md @@ -0,0 +1,37 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# OS + + + + +## Module Function + +### exit(INTEGER) +> Returns `` + +Terminates the program with the given exit code. + + + + + +### raise(INTEGER, STRING) +> Returns `` + +Terminates the program with the given exit code and prints the error message. + + + + + + +## Properties +| Name | Value | +| ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/Time.md b/docs/versioned_docs/version-v0.21.0/builtins/Time.md new file mode 100644 index 0000000..e4f3ac2 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/Time.md @@ -0,0 +1,89 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Time + + + + +## Module Function + +### format(INTEGER, STRING) +> Returns `STRING` + +Formats the given unix timestamp with the given layout + +[Go date and time formats](https://gosamples.dev/date-time-format-cheatsheet/) are natively supported. +You can also use some but not all [formats present in many other languages](https://apidock.com/ruby/Time/strftime) which are not fully supported. +Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdlib/time.go) to see which formatters are supported. + + + + + + +### parse(STRING, STRING) +> Returns `STRING` + +Parses a given string with the given format to a unix timestamp. + +[Go date and time formats](https://gosamples.dev/date-time-format-cheatsheet/) are natively supported. +You can also use some but not all [formats present in many other languages](https://apidock.com/ruby/Time/strftime) which are not fully supported. +Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdlib/time.go) to see which formatters are supported. + + + + + + +### sleep(INTEGER) +> Returns `NIL` + +Stops the RocketLang routine for at least the stated duration in seconds + + + + + + + +### unix() +> Returns `INTEGER` + +Returns the current time as unix timestamp + + + + + + +## Properties +| Name | Value | +| ---- | ----- | +| ANSIC | Mon Jan _2 15:04:05 2006 | +| Kitchen | 3:04PM | +| Layout | 01/02 03:04:05PM '06 -0700 | +| RFC1123 | Mon, 02 Jan 2006 15:04:05 MST | +| RFC1123Z | Mon, 02 Jan 2006 15:04:05 -0700 | +| RFC3339 | 2006-01-02T15:04:05Z07:00 | +| RFC3339Nano | 2006-01-02T15:04:05.999999999Z07:00 | +| RFC822 | 02 Jan 06 15:04 MST | +| RFC822Z | 02 Jan 06 15:04 -0700 | +| RFC850 | Monday, 02-Jan-06 15:04:05 MST | +| RubyDate | Mon Jan 02 15:04:05 -0700 2006 | +| Stamp | Jan _2 15:04:05 | +| StampMicro | Jan _2 15:04:05.000000 | +| StampMilli | Jan _2 15:04:05.000 | +| StampNano | Jan _2 15:04:05.000000000 | +| UnixDate | Mon Jan _2 15:04:05 MST 2006 | + diff --git a/docs/versioned_docs/version-v0.21.0/builtins/_category_.yml b/docs/versioned_docs/version-v0.21.0/builtins/_category_.yml new file mode 100644 index 0000000..c2400cc --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/builtins/_category_.yml @@ -0,0 +1 @@ +label: Builtins \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/control_expressions/_category_.yml b/docs/versioned_docs/version-v0.21.0/control_expressions/_category_.yml new file mode 100644 index 0000000..6983d21 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/control_expressions/_category_.yml @@ -0,0 +1 @@ +label: Control Expressions \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/control_expressions/foreach.md b/docs/versioned_docs/version-v0.21.0/control_expressions/foreach.md new file mode 100644 index 0000000..3c01a89 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/control_expressions/foreach.md @@ -0,0 +1,82 @@ +--- +title: "Foreach" +menu: + docs: + parent: "controls" +--- +# Foreach +For loops allow to iterate over different sets of data and perform actions based on them. + +```js +// read a file with numbers in it (file content will always be represented by strings) +// .lines() splits the lines of the file into an array +input = open("examples/aoc/2021/day-1/input").lines() + +// define temporary array +a = [] + +foreach i, number in input + // read each line into temporary array and cast it into an integer + a.yoink(number.strip().plz_i()) +end + +// assign temporary array to input array +input = a +``` + + +Count form zero to a given number (excluding): + +```js +🚀 > foreach i in 5 + puts(i) +end + +0 +1 +2 +3 +4 +=> 5 +``` + +Iterate over a string: + +```js +🚀 > foreach i in "test" + puts(i) +end + +"t" +"e" +"s" +"t" +=> "test" +``` + +It is possible to use `next` or `break` inside a loop. + +```js +foreach i in 5 + if (i == 2) + next + end + puts(i) +end + +foreach i in 5 + if (i == 2) + break + end + puts(i) +end + +// Returns +0 +1 +3 +4 +0 +1 +nil +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/control_expressions/if.md b/docs/versioned_docs/version-v0.21.0/control_expressions/if.md new file mode 100644 index 0000000..02ecd12 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/control_expressions/if.md @@ -0,0 +1,19 @@ +--- +title: "If" +menu: + docs: + parent: "controls" +--- +# If +With `if` and `else` keywords the flow of a program can be controlled. + +```js +🚀 > if (a.type() == "STRING") + puts("is a string") +else + puts("is not a string") +end + +// which prints +is a string +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/control_expressions/while.md b/docs/versioned_docs/version-v0.21.0/control_expressions/while.md new file mode 100644 index 0000000..4f79aad --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/control_expressions/while.md @@ -0,0 +1,25 @@ +--- +title: "While" +menu: + docs: + parent: "controls" +--- +# While +While loops will run as long as the condition is truthy. + +Print numbers from 0 to 3: + +```js +🚀 > a = 0 +🚀 > while (a != 4) + puts(a) + a = a + 1 +end + +// which prints +0 +1 +2 +3 +=> nil +``` diff --git a/docs/versioned_docs/version-v0.21.0/index.md b/docs/versioned_docs/version-v0.21.0/index.md new file mode 100644 index 0000000..9e7c20e --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/index.md @@ -0,0 +1,54 @@ +--- +sidebar_position: 0 +--- +# Getting Started + +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 + +[![GitHub release](https://img.shields.io/github/release/flipez/rocket-lang.svg)](https://github.com/flipez/rocket-lang/releases/) + +# Quick Start +```js +input = open("examples/aoc/2021/day-1/input").lines() + + +a = [] +foreach i, number in input + a.yoink(number.strip().plz_i()) +end +input = a + +increase = 0 +foreach i, number in input + if (number > input[i-1]) + increase = increase + 1 + end +end +puts(increase + 1) + +increase = 0 +foreach i, number in input + sum = number + input[i+1] + input[i+2] + sum_two = input[i+1] + input[i+2] + input[i+3] + + if (sum_two > sum) + increase = increase + 1 + end +end +puts(increase + 1) +``` + +# Help +You can launch RocketLang with `-h` or `--help` to get an overview about the cli capabilities. + +```zsh +$ rocket-lang -h +Usage: rocket-lang [flags] [program file] [arguments] + +Available flags: + -e, --exec string Runs the given code. + -v, --version Prints the version and build date. +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/install.md b/docs/versioned_docs/version-v0.21.0/install.md new file mode 100644 index 0000000..9bef291 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/install.md @@ -0,0 +1,31 @@ +--- +sidebar_position: 1 +--- +# Install Guide + +[![GitHub release](https://img.shields.io/github/release/flipez/rocket-lang.svg)](https://github.com/flipez/rocket-lang/releases/) + +## Installation +### macOS +``` +brew install flipez/homebrew-tap/rocket-lang +``` + +### APT +``` +echo "deb [trusted=yes] https://apt.rocket-lang.org/ /" > \ +/etc/apt/sources.list.d/fury.list +``` + +### RPM +``` +[fury] +name=RocketLang Repo +baseurl=https://rpm.rocket-lang.org +enabled=1 +gpgcheck=0 +``` +### Manual +Download from [releases](https://github.com/Flipez/rocket-lang/releases). + +There is also a [Visual Studio Code Extension](https://marketplace.visualstudio.com/items?itemName=Flipez.rocket-lang-support) available. Just search for `rocket-lang` in the extension menu. \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/language/_category_.yml b/docs/versioned_docs/version-v0.21.0/language/_category_.yml new file mode 100644 index 0000000..dc65ac3 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/language/_category_.yml @@ -0,0 +1 @@ +label: Language \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/language/modules.md b/docs/versioned_docs/version-v0.21.0/language/modules.md new file mode 100644 index 0000000..32a159c --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/language/modules.md @@ -0,0 +1,46 @@ +# Modules +> 👉 Modules were introduced in `0.11` + +Modules are seperate RocketLang files can be imported using the `import` statement. +Functions and variables starting with a uppercase name are then available in the imported module. + +For example take this module: + +```js +// fixtures/module.rl +a = 1 +A = 5 + +Sum = def (a, b) + return a + b +end +``` + +You can import it with: + +```js +import("fixtures/module") +``` + +This results in a variable `module` implicitly being assigned. +You can use it like so: + +```js +🚀 > import("fixtures/module") +=> nil +🚀 > module.a +=> nil +🚀 > module.A +=> 5 +🚀 > module.Sum(module.A, 2) +=> 7 +``` + +You can also define a name for the variable in which the module will be available: + +```js +🚀 > import("fixtures/module", "anotherModule") +=> nil +🚀 > anotherModule.A +=> 5 +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/language/operators.md b/docs/versioned_docs/version-v0.21.0/language/operators.md new file mode 100644 index 0000000..9e43aa1 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/language/operators.md @@ -0,0 +1,8 @@ +# Operators + +| Operator | Description | +| -------- | ----------- | +| `==`, `!=` | Equals, Not Equal | +| `<`, `>`, `<=`, `>=` | Comparsion | +| `and`, `&&` | Logical And | +| `or`, `‖` | Logical Or | \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/literals/_category_.yml b/docs/versioned_docs/version-v0.21.0/literals/_category_.yml new file mode 100644 index 0000000..f189bbf --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/_category_.yml @@ -0,0 +1 @@ +label: Literals \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/literals/array.md b/docs/versioned_docs/version-v0.21.0/literals/array.md new file mode 100644 index 0000000..6ff040f --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/array.md @@ -0,0 +1,210 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Array + + + + +```js +a = [1, 2, 3, 4, 5] +puts(a[2]) +puts(a[-2]) +puts(a[:2]) +puts(a[:-2]) +puts(a[2:]) +puts(a[-2:]) +puts(a[1:-2]) + +// should output +[1, 2] +[1, 2, 3] +[3, 4, 5] +[4, 5] +[2, 3] +[1, 2, 8, 9, 5] + +``` + +## Literal Specific Methods + +### first() +> Returns `STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE` + +Returns the first element of the array. Shorthand for `array[0]` + + + + + +### include?(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) +> Returns `BOOLEAN` + +Returns true or false wether the array contains the given element + + + + + +### index(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) +> Returns `INTEGER` + +Returns the index of the given element in the array if found. Otherwise return `-1`. + + + + + +### last() +> Returns `STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE` + +Returns the last element of the array. + + + + + +### reverse() +> Returns `ARRAY` + +Reverses the elements of the array + + + + + +### size() +> Returns `INTEGER` + +Returns the amount of elements in the array. + + + + + +### slices(INTEGER) +> Returns `ARRAY` + +Returns the elements of the array in slices with the size of the given integer + + + + + +### sort() +> Returns `ARRAY` + +Sorts the array if it contains only one type of STRING, INTEGER or FLOAT + + + + + +### uniq() +> Returns `ARRAY|ERROR` + +Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable. + + + + + +### yeet() +> Returns `STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE` + +Removes the last element of the array and returns it. + + + + + +### yoink(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE) +> Returns `NIL` + +Adds the given object as last element to the array. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/boolean.md b/docs/versioned_docs/version-v0.21.0/literals/boolean.md new file mode 100644 index 0000000..2be124a --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/boolean.md @@ -0,0 +1,84 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Boolean + +A Boolean can represent two values: `true` and `false` and can be used in control flows. + + +```js +true // Is the representation for truthyness +false // is it for a falsy value + +a = true; +b = false; + +is_true = a == a; +is_false = a == b; + +is_true = a != b; + +``` + +## Literal Specific Methods + +### plz_s() +> Returns `STRING` + +Converts a boolean into a String representation and returns `"true"` or `"false"` based on the value. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/error.md b/docs/versioned_docs/version-v0.21.0/literals/error.md new file mode 100644 index 0000000..abce018 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/error.md @@ -0,0 +1,108 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Error + +An Error is created by RocketLang if unallowed or invalid code is run. +An error does often replace the original return value of a function or identifier. +The documentation of those functions does indicate ERROR as a potential return value. + +A program can rescue from errors within a block or alter it's behavior within other blocks like 'if' or 'def'. + +It is possible for the user to create errors using 'raise(STRING)' which will return an ERROR object with STRING as the message. + + + +```js +def test() + puts(nope) +rescue e + puts("Got error: '" + e.msg() + "'") +end + +test() + +=> "Got error in if: 'identifier not found: error'" + +if (true) + nope() +rescue your_name + puts("Got error in if: '" + your_name.msg() + "'") +end + +=> "Got error in if: 'identifier not found: nope'" + +begin + puts(nope) +rescue e + puts("rescue") +end + +=> "rescue" + +``` + +## Literal Specific Methods + +### msg() +> Returns `STRING` + +Returns the error message + +:::caution +Please note that performing `.msg()` on a ERROR object does result in a STRING object which then will no longer be treated as an error! +::: + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/file.md b/docs/versioned_docs/version-v0.21.0/literals/file.md new file mode 100644 index 0000000..d6250e0 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/file.md @@ -0,0 +1,127 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# File + + + + +```js +input = open("examples/aoc/2021/day-1/input").lines() + +``` + +## Literal Specific Methods + +### close() +> Returns `BOOLEAN` + +Closes the file pointer. Returns always `true`. + + + + + +### content() +> Returns `STRING|ERROR` + +Reads content of the file and returns it. Resets the position to 0 after read. + + + + + +### lines() +> Returns `ARRAY|ERROR` + +If successfull, returns all lines of the file as array elements, otherwise `nil`. Resets the position to 0 after read. + + + + + +### position() +> Returns `INTEGER` + +Returns the position of the current file handle. -1 if the file is closed. + + + + + +### read(INTEGER) +> Returns `STRING|ERROR` + +Reads the given amount of bytes from the file. Sets the position to the bytes that where actually read. At the end of file EOF error is returned. + + + + + +### seek(INTEGER, INTEGER) +> Returns `INTEGER|ERROR` + +Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence. 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. + + + + + +### write(STRING) +> Returns `INTEGER|ERROR` + +Writes the given string to the file. Returns number of written bytes on success. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/float.md b/docs/versioned_docs/version-v0.21.0/literals/float.md new file mode 100644 index 0000000..c0e67d0 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/float.md @@ -0,0 +1,92 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Float + + + + +## Literal Specific Methods + +### plz_f() +> Returns `FLOAT` + +Returns self + + + + + +### plz_i() +> Returns `INTEGER` + +Converts the float into an integer. + + + + + +### plz_s() +> Returns `STRING` + +Returns a string representation of the float. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/hash.md b/docs/versioned_docs/version-v0.21.0/literals/hash.md new file mode 100644 index 0000000..42258e6 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/hash.md @@ -0,0 +1,131 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Hash + + + + +```js +people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}]; + +// reassign of values +h = {"a": 1, 2: true} +puts(h["a"]) +puts(h[2]) +h["a"] = 3 +h["b"] = "moo" +puts(h["a"]) +puts(h["b"]) +puts(h[2])h = {"a": 1, 2: true} +puts(h["a"]) +puts(h[2]) +h["a"] = 3 +h["b"] = "moo" + +// should output +1 +true +3 +"moo" +true + +``` + +## Literal Specific Methods + +### get(INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL, INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL) +> Returns `INTEGER|STRING|BOOLEAN|ARRAY|HASH|FLOAT|ERROR|NIL` + +Returns the value of the given key or the default + + + + + +### include?(BOOLEAN|STRING|INTEGER|FLOAT|ARRAY|HASH) +> Returns `BOOLEAN` + +Returns true or false wether the hash contains the given object as key + + + + + +### keys() +> Returns `ARRAY` + +Returns the keys of the hash. + + + + + +### values() +> Returns `ARRAY` + +Returns the values of the hash. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/http.md b/docs/versioned_docs/version-v0.21.0/literals/http.md new file mode 100644 index 0000000..17d0b2c --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/http.md @@ -0,0 +1,107 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# HTTP + + + + +```js +def test() + puts(request["body"]) + return("test") +end + +HTTP.handle("/", test) + +HTTP.listen(3000) + +// Example request hash: +// {"protocol": "HTTP/1.1", "protocolMajor": 1, "protocolMinor": 1, "body": "servus", "method": "POST", "host": "localhost:3000", "contentLength": 6} + +``` + +## Literal Specific Methods + +### handle(STRING, FUNCTION) +> Returns `NIL|ERROR` + +Adds a handle to the global HTTP server. Needs to be done before starting one via .listen(). +Inside the function a variable called "request" will be populated which is a hash with information about the request. + +Also a variable called "response" will be created which will be returned automatically as a response to the client. +The response can be adjusted to the needs. It is a HASH supports the following content: + +- "status" needs to be an INTEGER (eg. 200, 400, 500). Default is 200. +- "body" needs to be a STRING. Default "" +- "headers" needs to be a HASH(STRING:STRING) eg. headers["Content-Type"] = "text/plain". Default is {"Content-Type": "text/plain"} + + + + + + + + +### listen(INTEGER) +> Returns `NIL|ERROR` + +Starts a blocking webserver on the given port. + + + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/integer.md b/docs/versioned_docs/version-v0.21.0/literals/integer.md new file mode 100644 index 0000000..de30750 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/integer.md @@ -0,0 +1,111 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Integer + +An integer can be positiv or negative and is always internally represented by a 64-Bit Integer. + +To cast a negative integer a digit can be prefixed with a - eg. -456. + + + +```js +a = 1; + +b = a + 2; + +is_true = 1 == 1; +is_false = 1 == 2; + +``` + +## Literal Specific Methods + +### plz_f() +> Returns `FLOAT` + +Converts the integer into a float. + + + + + +### plz_i() +> Returns `INTEGER` + +Returns self + + + + + +### plz_s(INTEGER) +> Returns `STRING` + +Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/nil.md b/docs/versioned_docs/version-v0.21.0/literals/nil.md new file mode 100644 index 0000000..9562939 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/nil.md @@ -0,0 +1,94 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# Nil + +Nil is the representation of "nothing". +It will be returned if something returns nothing (eg. puts or an empty break/next) and can also be generated with 'nil'. + + + +## Literal Specific Methods + +### plz_f() +> Returns `FLOAT` + +Returns zero float. + + + + + +### plz_i() +> Returns `INTEGER` + +Returns zero integer. + + + + + +### plz_s() +> Returns `STRING` + +Returns empty string. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/literals/string.md b/docs/versioned_docs/version-v0.21.0/literals/string.md new file mode 100644 index 0000000..5236835 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/literals/string.md @@ -0,0 +1,255 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + +# String + + + + +```js +a = "test_string"; + +b = "test" + "_string"; + +is_true = "test" == "test"; +is_false = "test" == "string"; + +s = "abcdef" +puts(s[2]) +puts(s[-2]) +puts(s[:2]) +puts(s[:-2]) +puts(s[2:]) +puts(s[-2:]) +puts(s[1:-2]) + +s[2] = "C" +s[-2] = "E" +puts(s) + +// should output +"c" +"e" +"ab" +"abcd" +"cdef" +"ef" +"bcd" +"abCdEf" + +// you can also use single quotes +'test "string" with doublequotes' + +// and you can scape a double quote in a double quote string +"te\"st" == 'te"st' + +``` + +## Literal Specific Methods + +### ascii() +> Returns `INTEGER|ARRAY` + +Returns the ascii representation of a char or string + + + + + +### count(STRING) +> Returns `INTEGER` + +Counts how often a given substring occurs in the string. + + + + + +### downcase() +> Returns `STRING` + +Returns the string with all uppercase letters replaced with lowercase counterparts. + + + + + +### downcase!() +> Returns `NIL` + +Replaces all upcase characters with lowercase counterparts. + + + + + +### find(STRING) +> Returns `INTEGER` + +Returns the character index of a given string if found. Otherwise returns `-1` + + + + + +### format(STRING|INTEGER|FLOAT|BOOLEAN|ARRAY|HASH) +> Returns `STRING` + +Formats according to a format specifier and returns the resulting string + + + + + +### lines() +> Returns `ARRAY` + +Splits the string at newline escape sequence and return all chunks in an array. Shorthand for `string.split("\n")`. + + + + + +### plz_i(INTEGER) +> Returns `INTEGER` + +Interprets the string as an integer with an optional given base. The default base is `10` and switched to `8` if the string starts with `0x`. + + + + + +### replace(STRING, STRING) +> Returns `STRING` + +Replaces the first string with the second string in the given string. + + + + + +### reverse() +> Returns `STRING` + +Returns a copy of the string with all characters reversed. + + + + + +### reverse!() +> Returns `NIL` + +Replaces all the characters in a string in reverse order. + + + + + +### size() +> Returns `INTEGER` + +Returns the amount of characters in the string. + + + + + +### split(STRING) +> Returns `ARRAY` + +Splits the string on a given seperator and returns all the chunks in an array. Default seperator is `" "` + + + + + +### strip() +> Returns `STRING` + +Returns a copy of the string with all leading and trailing whitespaces removed. + + + + + +### strip!() +> Returns `NIL` + +Removes all leading and trailing whitespaces in the string. + + + + + +### upcase() +> Returns `STRING` + +Returns the string with all lowercase letters replaced with uppercase counterparts. + + + + + +### upcase!() +> Returns `NIL` + +Replaces all lowercase characters with upcase counterparts. + + + + + + +## Generic Literal Methods + +### methods() +> Returns `ARRAY` + +Returns an array of all supported methods names. + + + + + +### to_json() +> Returns `STRING|ERROR` + +Returns the object as json notation. + + + + + +### type() +> Returns `STRING` + +Returns the type of the object. + + + + + +### wat() +> Returns `STRING` + +Returns the supported methods with usage information. + + + + + diff --git a/docs/versioned_docs/version-v0.21.0/specification/_category_.yml b/docs/versioned_docs/version-v0.21.0/specification/_category_.yml new file mode 100644 index 0000000..fc2b95a --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/_category_.yml @@ -0,0 +1 @@ +label: Specification \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/specification/builtins.md b/docs/versioned_docs/version-v0.21.0/specification/builtins.md new file mode 100644 index 0000000..fa92f79 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/builtins.md @@ -0,0 +1,22 @@ +--- +title: "Builtin Functions" +menu: + docs: + parent: "specification" +toc: true +--- +# Builtin Functions +## puts(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) + +Prints the string representation of the given object to STDOUT. + +```js +🚀 > puts("test") +"test" + +🚀 > puts([1,2,3]) +[1, 2, 3] + +🚀 > puts(["test",true,3]) +["test", true, 3] +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/specification/closures.md b/docs/versioned_docs/version-v0.21.0/specification/closures.md new file mode 100644 index 0000000..7c8ab72 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/closures.md @@ -0,0 +1,20 @@ +--- +title: "Closures" +menu: + docs: + parent: "specification" +toc: true +--- +# Closures +```js +newGreeter = def (greeting) + return def (name) + puts(greeting + " " + name) + end +end + +hello = newGreeter("Hello"); + +hello("dear, future Reader!"); + +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/specification/comments.md b/docs/versioned_docs/version-v0.21.0/specification/comments.md new file mode 100644 index 0000000..b6a536c --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/comments.md @@ -0,0 +1,18 @@ +--- +title: "Comments" +menu: + docs: + parent: "specification" +toc: true +--- +# Comments +Comments start with `//` characters. +All following content up to the end of the line is part of the comment. + +```js +// This is a comment +def (a) + // This is also a comment + a + a // And this +end +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/specification/functions.md b/docs/versioned_docs/version-v0.21.0/specification/functions.md new file mode 100644 index 0000000..23fb9ca --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/functions.md @@ -0,0 +1,40 @@ +--- +title: "Functions" +menu: + docs: + parent: "specification" +toc: true +--- +# Functions +Implicit and explicit return statements are supported. + +```js +fibonacci = def (x) + if (x == 0) + 0 + else + if (x == 1) + return 1; + else + fibonacci(x - 1) + fibonacci(x - 2); + end + end +end +``` + +> New in `0.11`: + +Functions can now also be created as named functions: + +```js +🚀 > def test() + puts("test") +end + +=> def () + puts(test) +end + +🚀 > test() +"test" +``` \ No newline at end of file diff --git a/docs/versioned_docs/version-v0.21.0/specification/local_variables.md b/docs/versioned_docs/version-v0.21.0/specification/local_variables.md new file mode 100644 index 0000000..83e90a6 --- /dev/null +++ b/docs/versioned_docs/version-v0.21.0/specification/local_variables.md @@ -0,0 +1,27 @@ +--- +title: "Local Variables" +menu: + docs: + parent: "specification" +toc: true +--- +# Local Variables +Variables represent the object as a memorable name. + +```js +a = "test" +``` +## Examples + +```js +some_integer = 1; +name = "RocketLang"; +array = [1, 2, 3, 4, 5]; +some_boolean = true; +``` + +Also expressions can be used +```js +another_int = (10 / 2) * 5 + 30; +an_array = [1 + 1, 2 * 2, 3]; +``` \ No newline at end of file diff --git a/docs/versioned_sidebars/version-v0.21.0-sidebars.json b/docs/versioned_sidebars/version-v0.21.0-sidebars.json new file mode 100644 index 0000000..caea0c0 --- /dev/null +++ b/docs/versioned_sidebars/version-v0.21.0-sidebars.json @@ -0,0 +1,8 @@ +{ + "tutorialSidebar": [ + { + "type": "autogenerated", + "dirName": "." + } + ] +} diff --git a/docs/versions.json b/docs/versions.json index 7c7f49e..958b745 100644 --- a/docs/versions.json +++ b/docs/versions.json @@ -1,4 +1,5 @@ [ + "v0.21.0", "v0.20.1", "v0.20.0", "v0.19.1",