From 8aeefbe4ae9c059003a192f7a2d479beab7d02f7 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Thu, 3 Nov 2022 18:11:33 +0100 Subject: [PATCH 1/6] move example from into separate files --- docs/builtins/http.yml | 3 + docs/builtins/io.yml | 6 ++ docs/builtins/json.yml | 8 ++ docs/builtins/math.yml | 103 +++++++++++++++++++++++++ docs/builtins/os.yml | 12 +++ docs/builtins/time.yml | 33 ++++++++ docs/literals/array.yml | 73 ++++++++++++++++++ docs/literals/boolean.yml | 19 +++++ docs/literals/error.yml | 38 ++++++++++ docs/literals/file.yml | 18 +++++ docs/literals/float.yml | 17 +++++ docs/literals/hash.yml | 35 +++++++++ docs/literals/http.yml | 31 ++++++++ docs/literals/integer.yml | 34 +++++++++ docs/literals/nil.yml | 20 +++++ docs/literals/object.yml | 24 ++++++ docs/literals/string.yml | 153 ++++++++++++++++++++++++++++++++++++++ object/array.go | 35 --------- object/boolean.go | 3 - object/builtin.go | 9 +-- object/error.go | 8 -- object/file.go | 7 -- object/float.go | 11 --- object/hash.go | 6 -- object/http.go | 12 --- object/integer.go | 21 ------ object/nil.go | 3 - object/object.go | 15 ---- object/string.go | 92 ----------------------- stdlib/http.go | 1 - stdlib/io.go | 3 - stdlib/json.go | 5 -- stdlib/math.go | 60 --------------- stdlib/os.go | 7 -- stdlib/std.go | 16 ++-- stdlib/time.go | 22 ------ 36 files changed, 639 insertions(+), 324 deletions(-) create mode 100644 docs/builtins/http.yml create mode 100644 docs/builtins/io.yml create mode 100644 docs/builtins/json.yml create mode 100644 docs/builtins/math.yml create mode 100644 docs/builtins/os.yml create mode 100644 docs/builtins/time.yml create mode 100644 docs/literals/array.yml create mode 100644 docs/literals/boolean.yml create mode 100644 docs/literals/error.yml create mode 100644 docs/literals/file.yml create mode 100644 docs/literals/float.yml create mode 100644 docs/literals/hash.yml create mode 100644 docs/literals/http.yml create mode 100644 docs/literals/integer.yml create mode 100644 docs/literals/nil.yml create mode 100644 docs/literals/object.yml create mode 100644 docs/literals/string.yml diff --git a/docs/builtins/http.yml b/docs/builtins/http.yml new file mode 100644 index 0000000..9bb00e8 --- /dev/null +++ b/docs/builtins/http.yml @@ -0,0 +1,3 @@ +functions: + new: + description: "Creates a new instance of HTTP" diff --git a/docs/builtins/io.yml b/docs/builtins/io.yml new file mode 100644 index 0000000..3162a11 --- /dev/null +++ b/docs/builtins/io.yml @@ -0,0 +1,6 @@ +functions: + open: + description: "Opens a file pointer to the file at the path, mode and permission can be set optionally." + example: | + ๐Ÿš€ ยป IO.open("main.go", "r", "0644") + ยป diff --git a/docs/builtins/json.yml b/docs/builtins/json.yml new file mode 100644 index 0000000..4ea9150 --- /dev/null +++ b/docs/builtins/json.yml @@ -0,0 +1,8 @@ +functions: + parse: + description: "Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT." + example: | + ๐Ÿš€ ยป JSON.parse('{"test": 123}') + ยป {"test": 123.0} + ๐Ÿš€ ยป JSON.parse('["test", 123]') + ยป ["test", 123.0] diff --git a/docs/builtins/math.yml b/docs/builtins/math.yml new file mode 100644 index 0000000..72a1805 --- /dev/null +++ b/docs/builtins/math.yml @@ -0,0 +1,103 @@ +functions: + abs: + description: "" + acos: + description: "Returns the arccosine, in radians, of the argument" + example: | + ๐Ÿš€ > Math.acos(1.0) + => 0.0 + asin: + description: "Returns the arcsine, in radians, of the argument" + example: | + ๐Ÿš€ > Math.asin(0.0) + => 0.0 + atan: + description: "Returns the arctangent, in radians, of the argument" + example: | + ๐Ÿš€ > Math.atan(0.0) + => 0.0 + ceil: + description: "Returns the least integer value greater or equal to the argument" + example: | + ๐Ÿš€ > Math.ceil(1.49) + => 2.0 + copysign: + description: "Returns a value with the magnitude of first argument and sign of second argument" + example: | + ๐Ÿš€ > Math.copysign(3.2, -1.0) + => -3.2 + cos: + description: "Returns the cosine of the radion argument" + example: | + ๐Ÿš€ > Math.cos(Pi/2) + => 0.0 + exp: + description: "Returns e**argument, the base-e exponential of argument" + example: | + ๐Ÿš€ > Math.exp(1.0) + => 2.72 + floor: + description: "Returns the greatest integer value less than or equal to argument" + example: | + ๐Ÿš€ > Math.floor(1.51) + => 1.0 + log: + description: "Returns the natural logarithm of argument" + example: | + ๐Ÿš€ > Math.log(2.7183) + => 1.0 + log10: + description: "Returns the decimal logarithm of argument" + example: | + ๐Ÿš€ > Math.log(100.0) + => 2.0 + log2: + description: "Returns the binary logarithm of argument" + example: | + ๐Ÿš€ > Math.log2(256.0) + => 8.0 + max: + description: "Returns the larger of the two numbers" + example: | + ๐Ÿš€ > Math.max(5.0, 10.0) + => 10.0 + min: + description: "Returns the smaller of the two numbers" + example: | + ๐Ÿš€ > Math.min(5.0, 10.0) + => 5.0 + pow: + description: "Returns argument1**argument2, the base-argument1 exponential of argument2" + example: | + ๐Ÿš€ > Math.pow(2.0, 3.0) + => 8.0 + rand: + description: "Returns a pseudo-random number in the half-open interval [0.0, 1.0]." + example: | + ๐Ÿš€ > Math.rand() + => 0.6046602879796196 + remainder: + description: "Returns the IEEE 754 floating-point remainder of argument1/argument2" + example: | + ๐Ÿš€ > Math.remainder(100.0, 30.0) + => 10.0 + round: + description: "Returns the nearest integer, rounding half away from zero" + example: | + ๐Ÿš€ > Math.round(73.3) + => 73.0 + sin: + description: "Returns the sine of the radion argument" + example: | + ๐Ÿš€ > Math.sin(Pi) + => 0.0 + sqrt: + description: "Returns the square root of argument" + example: | + ๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) + => 5.0 + tan: + description: "Returns the tangent of the radion argument" + example: | + ๐Ÿš€ > Math.tan(0.0) + => 0.0 diff --git a/docs/builtins/os.yml b/docs/builtins/os.yml new file mode 100644 index 0000000..1a22693 --- /dev/null +++ b/docs/builtins/os.yml @@ -0,0 +1,12 @@ +functions: + exit: + description: "Terminates the program with the given exit code." + example: | + ๐Ÿš€ > OS.exit(1) + exit status 1 + raise: + description: "Terminates the program with the given exit code and prints the error message." + example: | + ๐Ÿš€ > OS.raise(1, "broken") + ๐Ÿ”ฅ RocketLang raised an error: "broken" + exit status 1 diff --git a/docs/builtins/time.yml b/docs/builtins/time.yml new file mode 100644 index 0000000..8db33d1 --- /dev/null +++ b/docs/builtins/time.yml @@ -0,0 +1,33 @@ +functions: + format: + description: | + 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. + example: | + ๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") + ยป "Mon Oct 31 00:08:10 2022" + ๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") + ยป "Mon Oct 31 00:28:43 2022" + parse: + description: | + 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. + example: | + ๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") + ยป 1647993600 + ๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") + ยป 1647993600 + sleep: + description: "Stops the RocketLang routine for at least the stated duration in seconds" + example: | + ๐Ÿš€ > Time.sleep(2) + unix: + description: "Returns the current time as unix timestamp" + example: | + ๐Ÿš€ > Time.Unix() diff --git a/docs/literals/array.yml b/docs/literals/array.yml new file mode 100644 index 0000000..8e337d7 --- /dev/null +++ b/docs/literals/array.yml @@ -0,0 +1,73 @@ +title: "Array" +description: +example: | + 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] +methods: + reverse: + description: "Reverses the elements of the array" + example: | + ๐Ÿš€ ยป ["a", "b", 1, 2].reverse() + ยป [2, 1, "b", "a"] + size: + description: "Returns the amount of elements in the array." + example: | + ๐Ÿš€ ยป ["a", "b", 1, 2].size() + ยป 4 + sort: + description: "Sorts the array if it contains only one type of STRING, INTEGER or FLOAT" + example: | + ๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() + ยป [2.0, 3.1, 3.4] + uniq: + description: "Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable." + example: | + ๐Ÿš€ ยป ["a", 1, 1, 2].uniq() + ยป [1, 2, "a"] + index: + description: "Returns the index of the given element in the array if found. Otherwise return `-1`." + example: | + ๐Ÿš€ ยป ["a", "b", 1, 2].index(1) + ยป 2 + first: + description: "Returns the first element of the array. Shorthand for `array[0]`" + example: | + ๐Ÿš€ ยป ["a", "b", 1, 2].first() + ยป "a" + last: + description: "Returns the last element of the array." + example: | + ๐Ÿš€ ยป ["a", "b", 1, 2].last() + ยป 2 + yeet: + description: "Removes the last element of the array and returns it." + example: | + ๐Ÿš€ ยป a = [1,2,3] + ยป [1, 2, 3] + ๐Ÿš€ ยป a.yeet() + ยป 3 + ๐Ÿš€ ยป a + ยป [1, 2] + yoink: + description: "Adds the given object as last element to the array." + example: | + ๐Ÿš€ ยป a = [1,2,3] + ยป [1, 2, 3] + ๐Ÿš€ ยป a.yoink("a") + ยป nil + ๐Ÿš€ ยป a + ยป [1, 2, 3, "a"] diff --git a/docs/literals/boolean.yml b/docs/literals/boolean.yml new file mode 100644 index 0000000..ba80cb7 --- /dev/null +++ b/docs/literals/boolean.yml @@ -0,0 +1,19 @@ +title: "Boolean" +description: "A Boolean can represent two values: `true` and `false` and can be used in control flows." +example: | + 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; +methods: + plz_s: + description: "Converts a boolean into a String representation and returns `\"true\"` or `\"false\"` based on the value." + example: | + ๐Ÿš€ ยป true.plz_s() + ยป "true" diff --git a/docs/literals/error.yml b/docs/literals/error.yml new file mode 100644 index 0000000..a2245dc --- /dev/null +++ b/docs/literals/error.yml @@ -0,0 +1,38 @@ +title: "Error" +description: | + 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. +example: | + 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" +methods: + msg: + description: "Returns the error message\n\n:::caution\nPlease note that performing `.msg()` on a ERROR object does result in a STRING object which then will no longer be treated as an error!\n:::" diff --git a/docs/literals/file.yml b/docs/literals/file.yml new file mode 100644 index 0000000..c3ebbe7 --- /dev/null +++ b/docs/literals/file.yml @@ -0,0 +1,18 @@ +title: "File" +example: | + input = open("examples/aoc/2021/day-1/input").lines() +methods: + close: + description: "Closes the file pointer. Returns always `true`." + lines: + description: "If successfull, returns all lines of the file as array elements, otherwise `nil`. Resets the position to 0 after read." + content: + description: "Reads content of the file and returns it. Resets the position to 0 after read." + position: + description: "Returns the position of the current file handle. -1 if the file is closed." + read: + description: "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: + description: "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: + description: "Writes the given string to the file. Returns number of written bytes on success." diff --git a/docs/literals/float.yml b/docs/literals/float.yml new file mode 100644 index 0000000..f510294 --- /dev/null +++ b/docs/literals/float.yml @@ -0,0 +1,17 @@ +title: "Float" +methods: + plz_f: + description: "Returns self" + example: | + ๐Ÿš€ ยป 123.456.plz_f() + ยป 123.456 + plz_s: + description: "Returns a string representation of the float." + example: | + ๐Ÿš€ ยป 123.456.plz_s() + ยป "123.456" + plz_i: + description: "Converts the float into an integer." + example: | + ๐Ÿš€ ยป 123.456.plz_i() + ยป 123 diff --git a/docs/literals/hash.yml b/docs/literals/hash.yml new file mode 100644 index 0000000..4dd4ac8 --- /dev/null +++ b/docs/literals/hash.yml @@ -0,0 +1,35 @@ +title: "Hash" +example: | + 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 +methods: + keys: + description: "Returns the keys of the hash." + example: | + ๐Ÿš€ ยป {"a": "1", "b": "2"}.keys() + ยป ["a", "b"] + values: + description: "Returns the values of the hash." + example: | + ๐Ÿš€ ยป {"a": "1", "b": "2"}.values() + ยป ["1", "2"] diff --git a/docs/literals/http.yml b/docs/literals/http.yml new file mode 100644 index 0000000..d3b0abe --- /dev/null +++ b/docs/literals/http.yml @@ -0,0 +1,31 @@ +title: "HTTP" +example: | + 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} +methods: + listen: + description: "Starts a blocking webserver on the given port." + example: | + ๐Ÿš€ ยป HTTP.listen(3000) + handle: + description: | + 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"} + example: | + ๐Ÿš€ ยป HTTP.handle("/", callback_func) diff --git a/docs/literals/integer.yml b/docs/literals/integer.yml new file mode 100644 index 0000000..32aa57c --- /dev/null +++ b/docs/literals/integer.yml @@ -0,0 +1,34 @@ +title: "Integer" +description: | + 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. +example: | + a = 1; + + b = a + 2; + + is_true = 1 == 1; + is_false = 1 == 2; +methods: + plz_s: + description: "Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems" + example: | + ๐Ÿš€ ยป 1234.plz_s() + ยป "1234" + ๐Ÿš€ ยป 1234.plz_s(2) + ยป "10011010010" + ๐Ÿš€ ยป 1234.plz_s(8) + ยป "2322" + ๐Ÿš€ ยป 1234.plz_s(10) + ยป "1234" + plz_i: + description: "Returns self" + example: | + ๐Ÿš€ ยป 1234.plz_i() + ยป 1234 + plz_f: + description: "Converts the integer into a float." + example: | + ๐Ÿš€ ยป 1234.plz_f() + ยป 1234.0 diff --git a/docs/literals/nil.yml b/docs/literals/nil.yml new file mode 100644 index 0000000..dad9d0b --- /dev/null +++ b/docs/literals/nil.yml @@ -0,0 +1,20 @@ +title: "Nil" +description: | + 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'. +methods: + plz_s: + description: "Returns empty string." + example: | + ๐Ÿš€ ยป nil.plz_s() + ยป "" + plz_i: + description: "Returns zero integer." + example: | + ๐Ÿš€ ยป nil.plz_i() + ยป 0 + plz_f: + description: "Returns zero float." + example: | + ๐Ÿš€ ยป nil.plz_f() + ยป 0.0 diff --git a/docs/literals/object.yml b/docs/literals/object.yml new file mode 100644 index 0000000..6a4b0d8 --- /dev/null +++ b/docs/literals/object.yml @@ -0,0 +1,24 @@ +methods: + to_json: + description: "Returns the object as json notation." + example: | + ๐Ÿš€ ยป a = {"test": 1234} + ยป {"test": 1234} + ๐Ÿš€ ยป a.to_json() + ยป "{\"test\":1234}" + methods: + description: "Returns an array of all supported methods names." + example: | + ๐Ÿš€ ยป "test".methods() + ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + wat: + description: "Returns the supported methods with usage information." + example: | + ๐Ÿš€ ยป true.wat() + ยป "BOOLEAN supports the following methods: + plz_s()" + type: + description: "Returns the type of the object." + example: | + ๐Ÿš€ ยป "test".type() + ยป "STRING" diff --git a/docs/literals/string.yml b/docs/literals/string.yml new file mode 100644 index 0000000..ad2a660 --- /dev/null +++ b/docs/literals/string.yml @@ -0,0 +1,153 @@ +title: "String" +description: +example: | + 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' +methods: + count: + description: "Counts how often a given substring occurs in the string." + example: | + ๐Ÿš€ ยป "test".count("t") + ยป 2 + ๐Ÿš€ ยป "test".count("f") + ยป 0 + find: + description: "Returns the character index of a given string if found. Otherwise returns `-1`" + example: | + ๐Ÿš€ ยป "test".find("e") + ยป 1 + ๐Ÿš€ ยป "test".find("f") + ยป -1 + format: + description: "Formats according to a format specifier and returns the resulting string" + example: | + ๐Ÿš€ ยป "test%9d".format(1) + ยป "test 1" + ๐Ÿš€ ยป "test%1.2f".format(1.5) + ยป "test1.50" + ๐Ÿš€ ยป "test%s".format("test") + ยป "testtest" + size: + description: "Returns the amount of characters in the string." + example: | + ๐Ÿš€ ยป "test".size() + ยป 4 + plz_i: + description: "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`." + example: | + ๐Ÿš€ ยป "1234".plz_i() + ยป 1234 + ๐Ÿš€ ยป "1234".plz_i(8) + ยป 668 + ๐Ÿš€ ยป "0x1234".plz_i(8) + ยป 668 + ๐Ÿš€ ยป "0x1234".plz_i() + ยป 668 + ๐Ÿš€ ยป "0x1234".plz_i(10) + ยป 0 + replace: + description: "Replaces the first string with the second string in the given string." + example: | + ๐Ÿš€ ยป "test".replace("t", "f") + ยป "fesf" + reverse: + description: "Returns a copy of the string with all characters reversed." + example: | + ๐Ÿš€ ยป "stressed".reverse() + ยป "desserts" + reverse!: + description: "Replaces all the characters in a string in reverse order." + example: | + ๐Ÿš€ ยป a = "stressed" + ยป "stressed" + ๐Ÿš€ ยป a.reverse!() + ยป nil + ๐Ÿš€ ยป a + ยป "desserts" + split: + description: "Splits the string on a given seperator and returns all the chunks in an array. Default seperator is `\" \"`" + example: | + ๐Ÿš€ ยป "a,b,c,d".split(",") + ยป ["a", "b", "c", "d"] + ๐Ÿš€ ยป "test and another test".split() + ยป ["test", "and", "another", "test"] + lines: + description: "Splits the string at newline escape sequence and return all chunks in an array. Shorthand for `string.split(\"\\n\")`." + example: | + ๐Ÿš€ ยป "test\ntest2".lines() + ยป ["test\ntest2"] + strip: + description: "Returns a copy of the string with all leading and trailing whitespaces removed." + example: | + ๐Ÿš€ ยป " test ".strip() + ยป "test" + strip!: + description: "Removes all leading and trailing whitespaces in the string." + example: | + ๐Ÿš€ ยป a = " test " + ยป " test " + ๐Ÿš€ ยป a.strip!() + ยป nil + ๐Ÿš€ ยป a + ยป "test" + downcase: + description: "Returns the string with all uppercase letters replaced with lowercase counterparts." + example: | + ๐Ÿš€ ยป "TeST".downcase() + ยป "test" + downcase!: + description: "Replaces all upcase characters with lowercase counterparts." + example: | + ๐Ÿš€ ยป a = "TeST" + ยป "TeST" + ๐Ÿš€ ยป a.downcase!() + ยป nil + ๐Ÿš€ ยป a + ยป "test" + upcase: + description: "Returns the string with all lowercase letters replaced with uppercase counterparts." + example: | + ๐Ÿš€ ยป "test".upcase() + ยป "TEST" + upcase!: + description: "Replaces all lowercase characters with upcase counterparts." + example: | + ๐Ÿš€ ยป a = "test" + ยป "test" + ๐Ÿš€ ยป a.upcase!() + ยป nil + ๐Ÿš€ ยป a + ยป "TEST" diff --git a/object/array.go b/object/array.go index 3e60350..dd93a84 100644 --- a/object/array.go +++ b/object/array.go @@ -60,9 +60,6 @@ func init() { objectMethods[ARRAY_OBJ] = map[string]ObjectMethod{ "reverse": ObjectMethod{ Layout: MethodLayout{ - Description: "Reverses the elements of the array", - Example: `๐Ÿš€ > ["a", "b", 1, 2].reverse() -=> [2, 1, "b", "a"]`, ReturnPattern: Args( Arg(ARRAY_OBJ), ), @@ -78,9 +75,6 @@ func init() { }, "size": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the amount of elements in the array.", - Example: `๐Ÿš€ > ["a", "b", 1, 2].size() -=> 4`, ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -95,9 +89,6 @@ func init() { // https://github.com/golang/go/issues/48522 // is fixed Layout: MethodLayout{ - Description: "Sorts the array if it contains only one type of STRING, INTEGER or FLOAT", - Example: `๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() -ยป [2.0, 3.1, 3.4]`, ReturnPattern: Args(Arg(ARRAY_OBJ)), }, method: func(o Object, _ []Object, _ Environment) Object { @@ -169,9 +160,6 @@ func init() { }, "uniq": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable.", - Example: `๐Ÿš€ > ["a", 1, 1, 2].uniq() -=> [1, 2, "a"]`, ReturnPattern: Args( Arg(ARRAY_OBJ, ERROR_OBJ), ), @@ -201,9 +189,6 @@ func init() { }, "index": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the index of the given element in the array if found. Otherwise return `-1`.", - Example: `๐Ÿš€ > ["a", "b", 1, 2].index(1) -=> 2`, ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -227,9 +212,6 @@ func init() { }, "first": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the first element of the array. Shorthand for `array[0]`", - Example: `๐Ÿš€ > ["a", "b", 1, 2].first() -=> "a"`, ReturnPattern: Args( Arg(STRING_OBJ, ARRAY_OBJ, HASH_OBJ, BOOLEAN_OBJ, INTEGER_OBJ, NIL_OBJ, FUNCTION_OBJ, FILE_OBJ), ), @@ -244,9 +226,6 @@ func init() { }, "last": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the last element of the array.", - Example: `๐Ÿš€ > ["a", "b", 1, 2].last() -=> 2`, ReturnPattern: Args( Arg(STRING_OBJ, ARRAY_OBJ, HASH_OBJ, BOOLEAN_OBJ, INTEGER_OBJ, NIL_OBJ, FUNCTION_OBJ, FILE_OBJ), ), @@ -261,13 +240,6 @@ func init() { }, "yeet": ObjectMethod{ Layout: MethodLayout{ - Description: "Removes the last element of the array and returns it.", - Example: `๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yeet() -=> 3 -๐Ÿš€ > a -=> [1, 2]`, ReturnPattern: Args( Arg(STRING_OBJ, ARRAY_OBJ, HASH_OBJ, BOOLEAN_OBJ, INTEGER_OBJ, NIL_OBJ, FUNCTION_OBJ, FILE_OBJ), ), @@ -288,13 +260,6 @@ func init() { }, "yoink": ObjectMethod{ Layout: MethodLayout{ - Description: "Adds the given object as last element to the array.", - Example: `๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yoink("a") -=> nil -๐Ÿš€ > a -=> [1, 2, 3, "a"]`, ReturnPattern: Args( Arg(NIL_OBJ), ), diff --git a/object/boolean.go b/object/boolean.go index e8d6437..788bb82 100644 --- a/object/boolean.go +++ b/object/boolean.go @@ -33,9 +33,6 @@ func init() { objectMethods[BOOLEAN_OBJ] = map[string]ObjectMethod{ "plz_s": ObjectMethod{ Layout: MethodLayout{ - Description: "Converts a boolean into a String representation and returns `\"true\"` or `\"false\"` based on the value.", - Example: `๐Ÿš€ > true.plz_s() -=> "true"`, ReturnPattern: Args( Arg(STRING_OBJ), ), diff --git a/object/builtin.go b/object/builtin.go index c3ff617..acbb4ff 100644 --- a/object/builtin.go +++ b/object/builtin.go @@ -8,12 +8,11 @@ type BuiltinModule struct { Properties map[string]*BuiltinProperty } -func NewBuiltinModule(name string, description string, funcs map[string]*BuiltinFunction, props map[string]*BuiltinProperty) *BuiltinModule { +func NewBuiltinModule(name string, funcs map[string]*BuiltinFunction, props map[string]*BuiltinProperty) *BuiltinModule { return &BuiltinModule{ - Name: name, - Description: description, - Functions: funcs, - Properties: props, + Name: name, + Functions: funcs, + Properties: props, } } diff --git a/object/error.go b/object/error.go index 8e06cbd..9d4f1e1 100644 --- a/object/error.go +++ b/object/error.go @@ -24,14 +24,6 @@ func init() { objectMethods[ERROR_OBJ] = map[string]ObjectMethod{ "msg": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the error message\n\n:::caution\nPlease note that performing `.msg()` on a ERROR object does result in a STRING object which then will no longer be treated as an error!\n:::", - Example: `ยป def test() -puts(nope) -rescue e -puts((rescued error: + e.msg())) -end -๐Ÿš€ ยป test() -"rescued error:identifier not found: nope"`, ReturnPattern: Args( Arg(STRING_OBJ), ), diff --git a/object/file.go b/object/file.go index 5c7bda7..545c993 100644 --- a/object/file.go +++ b/object/file.go @@ -75,7 +75,6 @@ func init() { objectMethods[FILE_OBJ] = map[string]ObjectMethod{ "close": ObjectMethod{ Layout: MethodLayout{ - Description: "Closes the file pointer. Returns always `true`.", ReturnPattern: Args( Arg(BOOLEAN_OBJ), ), @@ -89,7 +88,6 @@ func init() { }, "lines": ObjectMethod{ Layout: MethodLayout{ - Description: "If successfull, returns all lines of the file as array elements, otherwise `nil`. Resets the position to 0 after read.", ReturnPattern: Args( Arg(ARRAY_OBJ, ERROR_OBJ), ), @@ -110,7 +108,6 @@ func init() { }, "content": ObjectMethod{ Layout: MethodLayout{ - Description: "Reads content of the file and returns it. Resets the position to 0 after read.", ReturnPattern: Args( Arg(STRING_OBJ, ERROR_OBJ), ), @@ -119,7 +116,6 @@ func init() { }, "position": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the position of the current file handle. -1 if the file is closed.", ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -131,7 +127,6 @@ func init() { }, "read": ObjectMethod{ Layout: MethodLayout{ - Description: "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.", ArgPattern: Args( Arg(INTEGER_OBJ), ), @@ -159,7 +154,6 @@ func init() { }, "seek": ObjectMethod{ Layout: MethodLayout{ - Description: "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.", ArgPattern: Args( Arg(INTEGER_OBJ), Arg(INTEGER_OBJ), @@ -189,7 +183,6 @@ func init() { }, "write": ObjectMethod{ Layout: MethodLayout{ - Description: "Writes the given string to the file. Returns number of written bytes on success.", ReturnPattern: Args( Arg(INTEGER_OBJ, ERROR_OBJ), ), diff --git a/object/float.go b/object/float.go index 2dc90c7..eebeab9 100644 --- a/object/float.go +++ b/object/float.go @@ -28,7 +28,6 @@ func init() { objectMethods[FLOAT_OBJ] = map[string]ObjectMethod{ "plz_f": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns self", ReturnPattern: Args( Arg(FLOAT_OBJ), ), @@ -39,11 +38,6 @@ func init() { }, "plz_s": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns a string representation of the float.", - Example: `๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_s() -=> "123.456"`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -55,11 +49,6 @@ func init() { }, "plz_i": ObjectMethod{ Layout: MethodLayout{ - Description: "Converts the float into an integer.", - Example: `๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_i() -=> "123"`, ReturnPattern: Args( Arg(INTEGER_OBJ), ), diff --git a/object/hash.go b/object/hash.go index 9989880..4a38269 100644 --- a/object/hash.go +++ b/object/hash.go @@ -84,9 +84,6 @@ func init() { objectMethods[HASH_OBJ] = map[string]ObjectMethod{ "keys": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the keys of the hash.", - Example: `๐Ÿš€ > {"a": "1", "b": "2"}.keys() -=> ["a", "b"]`, ReturnPattern: Args( Arg(ARRAY_OBJ), ), @@ -107,9 +104,6 @@ func init() { }, "values": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the values of the hash.", - Example: `๐Ÿš€ > {"a": "1", "b": "2"}.values() -=> ["2", "1"]`, ReturnPattern: Args( Arg(ARRAY_OBJ), ), diff --git a/object/http.go b/object/http.go index c6fd9d5..2381e49 100644 --- a/object/http.go +++ b/object/http.go @@ -34,8 +34,6 @@ func init() { objectMethods[HTTP_OBJ] = map[string]ObjectMethod{ "listen": ObjectMethod{ Layout: MethodLayout{ - Description: "Starts a blocking webserver on the given port.", - Example: `๐Ÿš€ > HTTP.listen(3000)`, ArgPattern: Args( Arg(INTEGER_OBJ), ), @@ -94,16 +92,6 @@ func init() { }, "handle": ObjectMethod{ Layout: MethodLayout{ - Description: `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"}`, - Example: `๐Ÿš€ > HTTP.handle("/", callback_func)`, ArgPattern: Args( Arg(STRING_OBJ), Arg(FUNCTION_OBJ), diff --git a/object/integer.go b/object/integer.go index 0ec44a8..253cf16 100644 --- a/object/integer.go +++ b/object/integer.go @@ -24,18 +24,6 @@ func init() { objectMethods[INTEGER_OBJ] = map[string]ObjectMethod{ "plz_s": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems", - Example: `๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_s() -=> "456" - -๐Ÿš€ > 1234.plz_s(2) -=> "10011010010" -๐Ÿš€ > 1234.plz_s(8) -=> "2322" -๐Ÿš€ > 1234.plz_s(10) -=> "1234"`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -56,7 +44,6 @@ func init() { }, "plz_i": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns self", ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -67,14 +54,6 @@ func init() { }, "plz_f": ObjectMethod{ Layout: MethodLayout{ - Description: "Converts the integer into a float.", - Example: `๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_f() -=> 456.0 - -๐Ÿš€ > 1234.plz_f() -=> 1234.0`, ReturnPattern: Args( Arg(FLOAT_OBJ), ), diff --git a/object/nil.go b/object/nil.go index 2278fcd..1367047 100644 --- a/object/nil.go +++ b/object/nil.go @@ -13,7 +13,6 @@ func init() { objectMethods[NIL_OBJ] = map[string]ObjectMethod{ "plz_s": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns empty string.", ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -24,7 +23,6 @@ func init() { }, "plz_i": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns zero integer.", ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -35,7 +33,6 @@ func init() { }, "plz_f": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns zero float.", ReturnPattern: Args( Arg(FLOAT_OBJ), ), diff --git a/object/object.go b/object/object.go index 82df34b..2aaf707 100644 --- a/object/object.go +++ b/object/object.go @@ -201,11 +201,6 @@ func init() { objectMethods["*"] = map[string]ObjectMethod{ "to_json": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the object as json notation.", - Example: `๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}"`, ReturnPattern: Args( Arg(STRING_OBJ, ERROR_OBJ), ), @@ -224,9 +219,6 @@ func init() { }, "methods": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns an array of all supported methods names.", - Example: `๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase]`, ReturnPattern: Args( Arg(ARRAY_OBJ), ), @@ -244,10 +236,6 @@ func init() { }, "wat": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the supported methods with usage information.", - Example: `๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s()`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -265,9 +253,6 @@ func init() { }, "type": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the type of the object.", - Example: `๐Ÿš€ > "test".type() -=> "STRING"`, ReturnPattern: Args( Arg(STRING_OBJ), ), diff --git a/object/string.go b/object/string.go index 6eb2376..31a8fae 100644 --- a/object/string.go +++ b/object/string.go @@ -21,13 +21,6 @@ func init() { objectMethods[STRING_OBJ] = map[string]ObjectMethod{ "count": ObjectMethod{ Layout: MethodLayout{ - Description: "Counts how often a given substring occurs in the string.", - Example: `๐Ÿš€ > "test".count("t") -=> 2 -๐Ÿš€ > "test".count("f") -=> 0 -๐Ÿš€ > "test1".count("1") -=> 1`, ArgPattern: Args( Arg(STRING_OBJ), ), @@ -43,11 +36,6 @@ func init() { }, "find": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the character index of a given string if found. Otherwise returns `-1`", - Example: `๐Ÿš€ > "test".find("e") -=> 1 -๐Ÿš€ > "test".find("f") -=> -1`, ArgPattern: Args( Arg(STRING_OBJ), ), @@ -63,13 +51,6 @@ func init() { }, "format": ObjectMethod{ Layout: MethodLayout{ - Description: "Formats according to a format specifier and returns the resulting string", - Example: `๐Ÿš€ ยป "test%9d".format(1) -ยป "test 1" -๐Ÿš€ ยป "test%1.2f".format(1.5) -ยป "test1.50" -๐Ÿš€ ยป "test%s".format("test") -ยป "testtest"`, ArgPattern: Args( OverloadArg(STRING_OBJ, INTEGER_OBJ, FLOAT_OBJ, BOOLEAN_OBJ, ARRAY_OBJ, HASH_OBJ), ), @@ -88,9 +69,6 @@ func init() { }, "size": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the amount of characters in the string.", - Example: `๐Ÿš€ > "test".size() -=> 4`, ReturnPattern: Args( Arg(INTEGER_OBJ), ), @@ -102,21 +80,6 @@ func init() { }, "plz_i": ObjectMethod{ Layout: MethodLayout{ - Description: "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`.", - Example: `๐Ÿš€ > "1234".plz_i() -=> 1234 - -๐Ÿš€ > "1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i() -=> 668 - -๐Ÿš€ > "0x1234".plz_i(10) -=> 0`, ArgPattern: Args( OptArg(INTEGER_OBJ), ), @@ -143,9 +106,6 @@ func init() { }, "replace": ObjectMethod{ Layout: MethodLayout{ - Description: "Replaces the first string with the second string in the given string.", - Example: `๐Ÿš€ > "test".replace("t", "f") -=> "fesf"`, ArgPattern: Args( Arg(STRING_OBJ), Arg(STRING_OBJ), @@ -163,9 +123,6 @@ func init() { }, "reverse": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns a copy of the string with all characters reversed.", - Example: `๐Ÿš€ > "stressed".reverse() -=> "desserts"`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -183,13 +140,6 @@ func init() { }, "reverse!": ObjectMethod{ Layout: MethodLayout{ - Description: "Replaces all the characters in a string in reverse order.", - Example: `๐Ÿš€ > a = "stressed" -=> "stressed" -๐Ÿš€ > a.reverse!() -=> nil -๐Ÿš€ > a -=> "desserts"`, ReturnPattern: Args( Arg(NIL_OBJ), ), @@ -208,12 +158,6 @@ func init() { }, "split": ObjectMethod{ Layout: MethodLayout{ - Description: "Splits the string on a given seperator and returns all the chunks in an array. Default seperator is `\" \"`", - Example: `๐Ÿš€ > "a,b,c,d".split(",") -=> ["a", "b", "c", "d"] - -๐Ÿš€ > "test and another test".split() -=> ["test", "and", "another", "test"]`, ArgPattern: Args( OptArg(STRING_OBJ), ), @@ -241,9 +185,6 @@ func init() { }, "lines": ObjectMethod{ Layout: MethodLayout{ - Description: "Splits the string at newline escape sequence and return all chunks in an array. Shorthand for `string.split(\"\\n\")`.", - Example: `๐Ÿš€ > "test\ntest2".lines() -=> ["test", "test2"]`, ReturnPattern: Args( Arg(ARRAY_OBJ), ), @@ -264,9 +205,6 @@ func init() { }, "strip": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns a copy of the string with all leading and trailing whitespaces removed.", - Example: `๐Ÿš€ > " test ".strip() -=> "test"`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -278,14 +216,6 @@ func init() { }, "strip!": ObjectMethod{ Layout: MethodLayout{ - Description: "Removes all leading and trailing whitespaces in the string.", - Example: ` -๐Ÿš€ > a = " test " -=> " test " -๐Ÿš€ > a.strip!() -=> nil -๐Ÿš€ > a -=> "test"`, ReturnPattern: Args( Arg(NIL_OBJ), ), @@ -298,9 +228,6 @@ func init() { }, "downcase": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the string with all uppercase letters replaced with lowercase counterparts.", - Example: `๐Ÿš€ > "TeST".downcase() -=> test`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -312,14 +239,6 @@ func init() { }, "downcase!": ObjectMethod{ Layout: MethodLayout{ - Description: "Replaces all upcase characters with lowercase counterparts.", - Example: ` -๐Ÿš€ > a = "TeST" -=> TeST -๐Ÿš€ > a.downcase!() -=> nil -๐Ÿš€ > a -=> test`, ReturnPattern: Args( Arg(NIL_OBJ), ), @@ -332,9 +251,6 @@ func init() { }, "upcase": ObjectMethod{ Layout: MethodLayout{ - Description: "Returns the string with all lowercase letters replaced with uppercase counterparts.", - Example: `๐Ÿš€ > "test".upcase() -=> TEST`, ReturnPattern: Args( Arg(STRING_OBJ), ), @@ -346,14 +262,6 @@ func init() { }, "upcase!": ObjectMethod{ Layout: MethodLayout{ - Description: "Replaces all lowercase characters with upcase counterparts.", - Example: ` -๐Ÿš€ > a = "test" -=> test -๐Ÿš€ > a.upcase!() -=> nil -๐Ÿš€ > a -=> TEST`, ReturnPattern: Args( Arg(NIL_OBJ), ), diff --git a/stdlib/http.go b/stdlib/http.go index 2753f53..a9fdb55 100644 --- a/stdlib/http.go +++ b/stdlib/http.go @@ -11,7 +11,6 @@ func init() { httpFunctions["new"] = object.NewBuiltinFunction( "new", object.MethodLayout{ - Description: "Creates a new instance of HTTP", ReturnPattern: object.Args( object.Arg(object.HTTP_OBJ), ), diff --git a/stdlib/io.go b/stdlib/io.go index d88ee02..f4068c9 100644 --- a/stdlib/io.go +++ b/stdlib/io.go @@ -11,7 +11,6 @@ func init() { ioFunctions["open"] = object.NewBuiltinFunction( "open", object.MethodLayout{ - Description: "Opens a file pointer to the file at the path, mode and permission can be set optionally.", ArgPattern: object.Args( object.Arg(object.STRING_OBJ), object.OptArg(object.STRING_OBJ), @@ -20,8 +19,6 @@ func init() { ReturnPattern: object.Args( object.Arg(object.FILE_OBJ), ), - Example: `๐Ÿš€ > IO.open("main.go", "r", "0644") -=> `, }, func(_ object.Environment, args ...object.Object) object.Object { mode := "r" diff --git a/stdlib/json.go b/stdlib/json.go index ebff7bf..c24aa49 100644 --- a/stdlib/json.go +++ b/stdlib/json.go @@ -13,11 +13,6 @@ func init() { jsonFunctions["parse"] = object.NewBuiltinFunction( "parse", object.MethodLayout{ - Description: "Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT.", - Example: `๐Ÿš€ > JSON.parse('{"test": 123}') -=> {"test": 123.0} -๐Ÿš€ > JSON.parse('["test", 123]') -=> ["test", 123.0]`, ReturnPattern: object.Args( object.Arg(object.HASH_OBJ), ), diff --git a/stdlib/math.go b/stdlib/math.go index 25be427..f085861 100644 --- a/stdlib/math.go +++ b/stdlib/math.go @@ -28,9 +28,6 @@ func init() { mathFunctions["acos"] = object.NewBuiltinFunction("acos", object.MethodLayout{ - Description: "Returns the arccosine, in radians, of the argument", - Example: `๐Ÿš€ > Math.acos(1.0) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -41,9 +38,6 @@ func init() { ) mathFunctions["asin"] = object.NewBuiltinFunction("asin", object.MethodLayout{ - Description: "Returns the arcsine, in radians, of the argument", - Example: `๐Ÿš€ > Math.asin(0.0) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -54,9 +48,6 @@ func init() { ) mathFunctions["atan"] = object.NewBuiltinFunction("atan", object.MethodLayout{ - Description: "Returns the arctangent, in radians, of the argument", - Example: `๐Ÿš€ > Math.atan(0.0) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -67,9 +58,6 @@ func init() { ) mathFunctions["ceil"] = object.NewBuiltinFunction("ceil", object.MethodLayout{ - Description: "Returns the least integer value greater or equal to the argument", - Example: `๐Ÿš€ > Math.ceil(1.49) -=> 2.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -80,9 +68,6 @@ func init() { ) mathFunctions["copysign"] = object.NewBuiltinFunction("copysign", object.MethodLayout{ - Description: "Returns a value with the magnitude of first argument and sign of second argument", - Example: `๐Ÿš€ > Math.copysign(3.2, -1.0) -=> -3.2`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ), object.Arg(object.FLOAT_OBJ)), }, @@ -94,9 +79,6 @@ func init() { ) mathFunctions["cos"] = object.NewBuiltinFunction("cos", object.MethodLayout{ - Description: "Returns the cosine of the radion argument", - Example: `๐Ÿš€ > Math.cos(Pi/2) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -107,9 +89,6 @@ func init() { ) mathFunctions["exp"] = object.NewBuiltinFunction("exp", object.MethodLayout{ - Description: "Returns e**argument, the base-e exponential of argument", - Example: `๐Ÿš€ > Math.exp(1.0) -=> 2.72`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -120,9 +99,6 @@ func init() { ) mathFunctions["floor"] = object.NewBuiltinFunction("floor", object.MethodLayout{ - Description: "Returns the greatest integer value less than or equal to argument", - Example: `๐Ÿš€ > Math.floor(1.51) -=> 1.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -133,9 +109,6 @@ func init() { ) mathFunctions["log"] = object.NewBuiltinFunction("log", object.MethodLayout{ - Description: "Returns the natural logarithm of argument", - Example: `๐Ÿš€ > Math.log(2.7183) -=> 1.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -146,9 +119,6 @@ func init() { ) mathFunctions["log10"] = object.NewBuiltinFunction("log10", object.MethodLayout{ - Description: "Returns the decimal logarithm of argument", - Example: `๐Ÿš€ > Math.log(100.0) -=> 2.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -159,9 +129,6 @@ func init() { ) mathFunctions["log2"] = object.NewBuiltinFunction("log2", object.MethodLayout{ - Description: "Returns the binary logarithm of argument", - Example: `๐Ÿš€ > Math.log2(256.0) -=> 8.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -172,9 +139,6 @@ func init() { ) mathFunctions["max"] = object.NewBuiltinFunction("max", object.MethodLayout{ - Description: "Returns the larger of the two numbers", - Example: `๐Ÿš€ > Math.max(5.0, 10.0) -=> 10.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ), object.Arg(object.FLOAT_OBJ)), }, @@ -186,9 +150,6 @@ func init() { ) mathFunctions["min"] = object.NewBuiltinFunction("min", object.MethodLayout{ - Description: "Returns the smaller of the two numbers", - Example: `๐Ÿš€ > Math.min(5.0, 10.0) -=> 5.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ), object.Arg(object.FLOAT_OBJ)), }, @@ -200,9 +161,6 @@ func init() { ) mathFunctions["pow"] = object.NewBuiltinFunction("pow", object.MethodLayout{ - Description: "Returns argument1**argument2, the base-argument1 exponential of argument2", - Example: `๐Ÿš€ > Math.pow(2.0, 3.0) -=> 8.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ), object.Arg(object.FLOAT_OBJ)), }, @@ -214,9 +172,6 @@ func init() { ) mathFunctions["rand"] = object.NewBuiltinFunction("rand", object.MethodLayout{ - Description: "Returns a pseudo-random number in the half-open interval [0.0, 1.0].", - Example: `๐Ÿš€ > Math.rand() -=> 0.6046602879796196`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, func(_ object.Environment, args ...object.Object) object.Object { @@ -225,9 +180,6 @@ func init() { ) mathFunctions["remainder"] = object.NewBuiltinFunction("remainder", object.MethodLayout{ - Description: "Returns the IEEE 754 floating-point remainder of argument1/argument2", - Example: `๐Ÿš€ > Math.remainder(100.0, 30.0) -=> 10.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ), object.Arg(object.FLOAT_OBJ)), }, @@ -239,9 +191,6 @@ func init() { ) mathFunctions["round"] = object.NewBuiltinFunction("round", object.MethodLayout{ - Description: "Returns the nearest integer, rounding half away from zero", - Example: `๐Ÿš€ > Math.round(73.3) -=> 73.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -252,9 +201,6 @@ func init() { ) mathFunctions["sin"] = object.NewBuiltinFunction("sin", object.MethodLayout{ - Description: "Returns the sine of the radion argument", - Example: `๐Ÿš€ > Math.sin(Pi) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -265,9 +211,6 @@ func init() { ) mathFunctions["sqrt"] = object.NewBuiltinFunction("sqrt", object.MethodLayout{ - Description: "Returns the square root of argument", - Example: `๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) -=> 5.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, @@ -278,9 +221,6 @@ func init() { ) mathFunctions["tan"] = object.NewBuiltinFunction("tan", object.MethodLayout{ - Description: "Returns the tangent of the radion argument", - Example: `๐Ÿš€ > Math.tan(0.0) -=> 0.0`, ReturnPattern: object.Args(object.Arg(object.FLOAT_OBJ)), ArgPattern: object.Args(object.Arg(object.FLOAT_OBJ)), }, diff --git a/stdlib/os.go b/stdlib/os.go index 1fd6b38..446bda1 100644 --- a/stdlib/os.go +++ b/stdlib/os.go @@ -14,12 +14,9 @@ func init() { osFunctions["exit"] = object.NewBuiltinFunction( "exit", object.MethodLayout{ - Description: "Terminates the program with the given exit code.", ArgPattern: object.Args( object.Arg(object.INTEGER_OBJ), ), - Example: `๐Ÿš€ > OS.exit(1) -exit status 1`, }, func(_ object.Environment, args ...object.Object) object.Object { os.Exit(int(args[0].(*object.Integer).Value)) @@ -30,14 +27,10 @@ exit status 1`, osFunctions["raise"] = object.NewBuiltinFunction( "raise", object.MethodLayout{ - Description: "Terminates the program with the given exit code and prints the error message.", ArgPattern: object.Args( object.Arg(object.INTEGER_OBJ), object.Arg(object.STRING_OBJ), ), - Example: `๐Ÿš€ > OS.raise(1, "broken") -๐Ÿ”ฅ RocketLang raised an error: "broken" -exit status 1`, }, func(_ object.Environment, args ...object.Object) object.Object { fmt.Printf("๐Ÿ”ฅ RocketLang raised an error: %s\n", args[1].Inspect()) diff --git a/stdlib/std.go b/stdlib/std.go index 0f088ab..4acdb0f 100644 --- a/stdlib/std.go +++ b/stdlib/std.go @@ -18,18 +18,18 @@ func init() { raiseFunction, ) - RegisterModule("Math", "", mathFunctions, mathProperties) - RegisterModule("HTTP", "", httpFunctions, httpProperties) - RegisterModule("JSON", "", jsonFunctions, jsonProperties) - RegisterModule("IO", "", ioFunctions, ioProperties) - RegisterModule("OS", "", osFunctions, osProperties) - RegisterModule("Time", "", timeFunctions, timeProperties) + RegisterModule("Math", mathFunctions, mathProperties) + RegisterModule("HTTP", httpFunctions, httpProperties) + RegisterModule("JSON", jsonFunctions, jsonProperties) + RegisterModule("IO", ioFunctions, ioProperties) + RegisterModule("OS", osFunctions, osProperties) + RegisterModule("Time", timeFunctions, timeProperties) } func RegisterFunction(name string, layout object.MethodLayout, function func(object.Environment, ...object.Object) object.Object) { Functions[name] = object.NewBuiltinFunction(name, layout, function) } -func RegisterModule(name string, description string, funcs map[string]*object.BuiltinFunction, props map[string]*object.BuiltinProperty) { - Modules[name] = object.NewBuiltinModule(name, description, funcs, props) +func RegisterModule(name string, funcs map[string]*object.BuiltinFunction, props map[string]*object.BuiltinProperty) { + Modules[name] = object.NewBuiltinModule(name, funcs, props) } diff --git a/stdlib/time.go b/stdlib/time.go index f3e953f..45b5203 100644 --- a/stdlib/time.go +++ b/stdlib/time.go @@ -53,11 +53,6 @@ func init() { timeFunctions["format"] = object.NewBuiltinFunction( "format", object.MethodLayout{ - Description: `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.`, ArgPattern: object.Args( object.Arg(object.INTEGER_OBJ), object.Arg(object.STRING_OBJ), @@ -65,10 +60,6 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl ReturnPattern: object.Args( object.Arg(object.STRING_OBJ), ), - Example: `๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") -ยป "Mon Oct 31 00:08:10 2022" -๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") -ยป "Mon Oct 31 00:28:43 2022"`, }, func(_ object.Environment, args ...object.Object) object.Object { unixTimestamp := args[0].(*object.Integer) @@ -81,11 +72,6 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl timeFunctions["parse"] = object.NewBuiltinFunction( "parse", object.MethodLayout{ - Description: `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.`, ArgPattern: object.Args( object.Arg(object.STRING_OBJ), object.Arg(object.STRING_OBJ), @@ -93,10 +79,6 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl ReturnPattern: object.Args( object.Arg(object.STRING_OBJ), ), - Example: `๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") -ยป 1647993600 -๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") -ยป 1647993600`, }, func(_ object.Environment, args ...object.Object) object.Object { timeString := args[0].(*object.String) @@ -112,14 +94,12 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl timeFunctions["sleep"] = object.NewBuiltinFunction( "sleep", object.MethodLayout{ - Description: "Stops the RocketLang routine for at least the stated duration in seconds", ArgPattern: object.Args( object.Arg(object.INTEGER_OBJ), ), ReturnPattern: object.Args( object.Arg(object.NIL_OBJ), ), - Example: `๐Ÿš€ > Time.sleep(2)`, }, func(_ object.Environment, args ...object.Object) object.Object { time.Sleep(time.Duration(args[0].(*object.Integer).Value) * time.Second) @@ -128,11 +108,9 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl timeFunctions["unix"] = object.NewBuiltinFunction( "unix", object.MethodLayout{ - Description: "Returns the current time as unix timestamp", ReturnPattern: object.Args( object.Arg(object.INTEGER_OBJ), ), - Example: `๐Ÿš€ > Time.Unix()`, }, func(_ object.Environment, args ...object.Object) object.Object { return object.NewInteger(time.Now().Unix()) From 6edc06aadfa1ad218e6ac1e2b98bc4325e744503 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Thu, 3 Nov 2022 18:12:29 +0100 Subject: [PATCH 2/6] refactor documentation generator --- docs/generate.go | 347 ++++++++++++++------------------------ docs/templates/builtin.md | 4 +- 2 files changed, 126 insertions(+), 225 deletions(-) diff --git a/docs/generate.go b/docs/generate.go index fce9976..28aa39e 100644 --- a/docs/generate.go +++ b/docs/generate.go @@ -3,8 +3,11 @@ package main import ( "fmt" "os" + "strings" "text/template" + "gopkg.in/yaml.v3" + "github.com/flipez/rocket-lang/object" "github.com/flipez/rocket-lang/stdlib" ) @@ -15,247 +18,145 @@ type templateData struct { Example string LiteralMethods map[string]object.ObjectMethod DefaultMethods map[string]object.ObjectMethod -} - -type builtinTemplateData struct { - Title string - Description string - Example string - Functions map[string]object.BuiltinFunction - Properties map[string]object.BuiltinProperty + Functions map[string]*object.BuiltinFunction + Properties map[string]*object.BuiltinProperty } func main() { - default_methods := object.ListObjectMethods()["*"] - string_methods := object.ListObjectMethods()[object.STRING_OBJ] - integer_methods := object.ListObjectMethods()[object.INTEGER_OBJ] - array_methods := object.ListObjectMethods()[object.ARRAY_OBJ] - hash_methods := object.ListObjectMethods()[object.HASH_OBJ] - boolean_methods := object.ListObjectMethods()[object.BOOLEAN_OBJ] - error_methods := object.ListObjectMethods()[object.ERROR_OBJ] - file_methods := object.ListObjectMethods()[object.FILE_OBJ] - nil_methods := object.ListObjectMethods()[object.NIL_OBJ] - float_methods := object.ListObjectMethods()[object.FLOAT_OBJ] - http_methods := object.ListObjectMethods()[object.HTTP_OBJ] - - tempData := templateData{ - Title: "String", - Example: `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' -`, - LiteralMethods: string_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/string.md", tempData) - - tempData = templateData{ - Title: "Array", - Example: `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] -`, - LiteralMethods: array_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/array.md", tempData) - - tempData = templateData{ - Title: "Hash", - Example: `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`, - LiteralMethods: hash_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/hash.md", tempData) - - tempData = templateData{ - Title: "Boolean", - Description: "A Boolean can represent two values: `true` and `false` and can be used in control flows.", - Example: `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;`, - LiteralMethods: boolean_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/boolean.md", tempData) - - tempData = templateData{ - Title: "Error", - Description: `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. -`, - Example: `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" -`, - LiteralMethods: error_methods, - DefaultMethods: default_methods, + defaultMethods, err := loadTemplateData("object", object.ListObjectMethods()["*"]) + if err != nil { + fmt.Printf("error loading doc for default literal methods: %s\n", err) + return } - create_doc("docs/templates/literal.md", "docs/docs/literals/error.md", tempData) - - tempData = templateData{ - Title: "File", - Example: `input = open("examples/aoc/2021/day-1/input").lines()`, - LiteralMethods: file_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/file.md", tempData) - tempData = templateData{ - Title: "Nil", - Description: `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'.`, - LiteralMethods: nil_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/nil.md", tempData) - - tempData = templateData{ - Title: "Integer", - Example: `a = 1; + for objType, methods := range object.ListObjectMethods() { + if objType == "*" { + continue + } + name := strings.ToLower(string(objType)) + + tempData, err := loadTemplateData(name, methods) + if err != nil { + fmt.Printf("error loading template data for literal %s: %s\n", name, err) + return + } + + tempData.DefaultMethods = defaultMethods.LiteralMethods + + err = createDoc( + "docs/templates/literal.md", + fmt.Sprintf("docs/docs/literals/%s.md", name), + tempData, + ) + if err != nil { + fmt.Printf("error creating documentation for literal %s: %s\n", name, err) + return + } + } -b = a + 2; + // builtin module docs + for _, module := range stdlib.Modules { + tempData, err := loadBuiltinTemplateData(module) + if err != nil { + fmt.Printf("error loading template data for module %s: %s\n", module.Name, err) + return + } + err = createDoc( + "docs/templates/builtin.md", + fmt.Sprintf("docs/docs/builtins/%s.md", module.Name), + tempData, + ) + if err != nil { + fmt.Printf("error creating documentation for module %s: %s\n", module.Name, err) + return + } + } +} -is_true = 1 == 1; -is_false = 1 == 2;`, - Description: `An integer can be positiv or negative and is always internally represented by a 64-Bit Integer. +func createDoc(path string, target string, data any) error { + f, err := os.Create(target) + if err != nil { + return err + } + return template.Must(template.ParseFiles(path)).Execute(f, data) +} -To cast a negative integer a digit can be prefixed with a - eg. -456.`, - LiteralMethods: integer_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/integer.md", tempData) +func loadTemplateData(name string, methods map[string]object.ObjectMethod) (*templateData, error) { + content, err := os.ReadFile(fmt.Sprintf("docs/object/%s.yml", name)) + if err != nil { + return nil, err + } - tempData = templateData{Title: "Float", LiteralMethods: float_methods, DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/float.md", tempData) + var docData struct { + Title string `yaml:"title"` + Description string `yaml:"description"` + Example string `yaml:"example"` + Methods map[string]struct { + Description string `yaml:"description"` + Example string `yaml:"example"` + } `yaml:"methods"` + } + if err := yaml.Unmarshal(content, &docData); err != nil { + return nil, err + } - tempData = templateData{ - Title: "HTTP", - Example: `def test() - puts(request["body"]) - return("test") -end + tempData := templateData{ + Title: docData.Title, + Description: docData.Description, + Example: docData.Example, + LiteralMethods: make(map[string]object.ObjectMethod), + } -HTTP.handle("/", test) + for name, method := range methods { + objMethod := object.ObjectMethod{ + Layout: method.Layout, + } + if v, ok := docData.Methods[name]; ok { + objMethod.Layout.Description = v.Description + objMethod.Layout.Example = v.Example + } + tempData.LiteralMethods[name] = objMethod + } -HTTP.listen(3000) + return &tempData, nil +} -// Example request hash: -// {"protocol": "HTTP/1.1", "protocolMajor": 1, "protocolMinor": 1, "body": "servus", "method": "POST", "host": "localhost:3000", "contentLength": 6}`, - LiteralMethods: http_methods, - DefaultMethods: default_methods} - create_doc("docs/templates/literal.md", "docs/docs/literals/http.md", tempData) +func loadBuiltinTemplateData(module *object.BuiltinModule) (*templateData, error) { + content, err := os.ReadFile(fmt.Sprintf("docs/builtins/%s.yml", strings.ToLower(module.Name))) + if err != nil { + return nil, err + } - // builtin module docs - for _, module := range stdlib.Modules { - create_doc("docs/templates/builtin.md", fmt.Sprintf("docs/docs/builtins/%s.md", module.Name), module) + var docData struct { + Description string `yaml:"description"` + Example string `yaml:"example"` + Functions map[string]struct { + Description string `yaml:"description"` + Example string `yaml:"example"` + } `yaml:"functions"` + } + if err := yaml.Unmarshal(content, &docData); err != nil { + return nil, err } -} -func create_doc(path string, target string, data any) bool { - f, err := os.Create(target) - if err != nil { - panic(err) + tempData := templateData{ + Title: module.Name, + Description: docData.Description, + Example: docData.Example, + Functions: make(map[string]*object.BuiltinFunction), + Properties: module.Properties, } - t := template.Must(template.ParseFiles(path)) - err = t.Execute(f, data) - if err != nil { - panic(err) + for name, function := range module.Functions { + fn := &object.BuiltinFunction{ + Layout: function.Layout, + } + if v, ok := docData.Functions[name]; ok { + fn.Layout.Description = v.Description + fn.Layout.Example = v.Example + } + tempData.Functions[name] = fn } - return true + return &tempData, nil } diff --git a/docs/templates/builtin.md b/docs/templates/builtin.md index cb23cdd..20da7fd 100644 --- a/docs/templates/builtin.md +++ b/docs/templates/builtin.md @@ -1,4 +1,4 @@ -# {{ .Name }} +# {{ .Title }} {{ .Description }} @@ -28,4 +28,4 @@ | ---- | ----- | {{ range $propertyName, $property := .Properties -}} | {{ $propertyName }} | {{ $property.Value.Value }} | -{{ end }} \ No newline at end of file +{{ end }} From c5b59b2e3c7fb513fbb6da012f8fe4d5a0e696ed Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Thu, 3 Nov 2022 18:12:57 +0100 Subject: [PATCH 3/6] generate documentation --- docs/docs/builtins/HTTP.md | 1 + docs/docs/builtins/IO.md | 6 +- docs/docs/builtins/JSON.md | 10 ++- docs/docs/builtins/Math.md | 21 +++++ docs/docs/builtins/OS.md | 3 + docs/docs/builtins/Time.md | 9 +- docs/docs/literals/array.md | 83 +++++++++-------- docs/docs/literals/boolean.md | 32 ++++--- docs/docs/literals/error.md | 36 ++++---- docs/docs/literals/file.md | 27 +++--- docs/docs/literals/float.md | 46 ++++++---- docs/docs/literals/hash.md | 37 ++++---- docs/docs/literals/http.md | 34 ++++--- docs/docs/literals/integer.md | 62 +++++++------ docs/docs/literals/nil.md | 47 +++++++--- docs/docs/literals/string.md | 162 ++++++++++++++++++---------------- 16 files changed, 366 insertions(+), 250 deletions(-) diff --git a/docs/docs/builtins/HTTP.md b/docs/docs/builtins/HTTP.md index 32f4f31..ae3436f 100644 --- a/docs/docs/builtins/HTTP.md +++ b/docs/docs/builtins/HTTP.md @@ -16,3 +16,4 @@ Creates a new instance of HTTP ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/docs/builtins/IO.md b/docs/docs/builtins/IO.md index 4bd8fdd..87558d7 100644 --- a/docs/docs/builtins/IO.md +++ b/docs/docs/builtins/IO.md @@ -12,8 +12,9 @@ Opens a file pointer to the file at the path, mode and permission can be set opt ```js -๐Ÿš€ > IO.open("main.go", "r", "0644") -=> +๐Ÿš€ ยป IO.open("main.go", "r", "0644") +ยป + ``` @@ -21,3 +22,4 @@ Opens a file pointer to the file at the path, mode and permission can be set opt ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/docs/builtins/JSON.md b/docs/docs/builtins/JSON.md index 695b228..0dfdb4a 100644 --- a/docs/docs/builtins/JSON.md +++ b/docs/docs/builtins/JSON.md @@ -12,10 +12,11 @@ Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. ```js -๐Ÿš€ > JSON.parse('{"test": 123}') -=> {"test": 123.0} -๐Ÿš€ > JSON.parse('["test", 123]') -=> ["test", 123.0] +๐Ÿš€ ยป JSON.parse('{"test": 123}') +ยป {"test": 123.0} +๐Ÿš€ ยป JSON.parse('["test", 123]') +ยป ["test", 123.0] + ``` @@ -23,3 +24,4 @@ Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/docs/builtins/Math.md b/docs/docs/builtins/Math.md index 65eed4a..49829e9 100644 --- a/docs/docs/builtins/Math.md +++ b/docs/docs/builtins/Math.md @@ -21,6 +21,7 @@ Returns the arccosine, in radians, of the argument ```js ๐Ÿš€ > Math.acos(1.0) => 0.0 + ``` @@ -33,6 +34,7 @@ Returns the arcsine, in radians, of the argument ```js ๐Ÿš€ > Math.asin(0.0) => 0.0 + ``` @@ -45,6 +47,7 @@ Returns the arctangent, in radians, of the argument ```js ๐Ÿš€ > Math.atan(0.0) => 0.0 + ``` @@ -57,6 +60,7 @@ Returns the least integer value greater or equal to the argument ```js ๐Ÿš€ > Math.ceil(1.49) => 2.0 + ``` @@ -69,6 +73,7 @@ Returns a value with the magnitude of first argument and sign of second argument ```js ๐Ÿš€ > Math.copysign(3.2, -1.0) => -3.2 + ``` @@ -81,6 +86,7 @@ Returns the cosine of the radion argument ```js ๐Ÿš€ > Math.cos(Pi/2) => 0.0 + ``` @@ -93,6 +99,7 @@ Returns e**argument, the base-e exponential of argument ```js ๐Ÿš€ > Math.exp(1.0) => 2.72 + ``` @@ -105,6 +112,7 @@ Returns the greatest integer value less than or equal to argument ```js ๐Ÿš€ > Math.floor(1.51) => 1.0 + ``` @@ -117,6 +125,7 @@ Returns the natural logarithm of argument ```js ๐Ÿš€ > Math.log(2.7183) => 1.0 + ``` @@ -129,6 +138,7 @@ Returns the decimal logarithm of argument ```js ๐Ÿš€ > Math.log(100.0) => 2.0 + ``` @@ -141,6 +151,7 @@ Returns the binary logarithm of argument ```js ๐Ÿš€ > Math.log2(256.0) => 8.0 + ``` @@ -153,6 +164,7 @@ Returns the larger of the two numbers ```js ๐Ÿš€ > Math.max(5.0, 10.0) => 10.0 + ``` @@ -165,6 +177,7 @@ Returns the smaller of the two numbers ```js ๐Ÿš€ > Math.min(5.0, 10.0) => 5.0 + ``` @@ -177,6 +190,7 @@ Returns argument1**argument2, the base-argument1 exponential of argument2 ```js ๐Ÿš€ > Math.pow(2.0, 3.0) => 8.0 + ``` @@ -189,6 +203,7 @@ Returns a pseudo-random number in the half-open interval [0.0, 1.0]. ```js ๐Ÿš€ > Math.rand() => 0.6046602879796196 + ``` @@ -201,6 +216,7 @@ Returns the IEEE 754 floating-point remainder of argument1/argument2 ```js ๐Ÿš€ > Math.remainder(100.0, 30.0) => 10.0 + ``` @@ -213,6 +229,7 @@ Returns the nearest integer, rounding half away from zero ```js ๐Ÿš€ > Math.round(73.3) => 73.0 + ``` @@ -225,6 +242,7 @@ Returns the sine of the radion argument ```js ๐Ÿš€ > Math.sin(Pi) => 0.0 + ``` @@ -237,6 +255,7 @@ Returns the square root of argument ```js ๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) => 5.0 + ``` @@ -249,6 +268,7 @@ Returns the tangent of the radion argument ```js ๐Ÿš€ > Math.tan(0.0) => 0.0 + ``` @@ -267,3 +287,4 @@ Returns the tangent of the radion argument | SqrtE | 1.6487212707001282 | | SqrtPhi | 1.272019649514069 | | SqrtPi | 1.772453850905516 | + diff --git a/docs/docs/builtins/OS.md b/docs/docs/builtins/OS.md index cfb4674..aa619dc 100644 --- a/docs/docs/builtins/OS.md +++ b/docs/docs/builtins/OS.md @@ -14,6 +14,7 @@ Terminates the program with the given exit code. ```js ๐Ÿš€ > OS.exit(1) exit status 1 + ``` @@ -27,6 +28,7 @@ Terminates the program with the given exit code and prints the error message. ๐Ÿš€ > OS.raise(1, "broken") ๐Ÿ”ฅ RocketLang raised an error: "broken" exit status 1 + ``` @@ -34,3 +36,4 @@ exit status 1 ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/docs/builtins/Time.md b/docs/docs/builtins/Time.md index bc9748d..9049dc9 100644 --- a/docs/docs/builtins/Time.md +++ b/docs/docs/builtins/Time.md @@ -8,18 +8,20 @@ ### format(INTEGER, STRING) > Returns `STRING` -Formats the given unix timestamp with the given layout. +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. + ```js ๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") ยป "Mon Oct 31 00:08:10 2022" ๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") ยป "Mon Oct 31 00:28:43 2022" + ``` @@ -33,11 +35,13 @@ You can also use some but not all [formats present in many other languages](http Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdlib/time.go) to see which formatters are supported. + ```js ๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") ยป 1647993600 ๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") ยป 1647993600 + ``` @@ -49,6 +53,7 @@ Stops the RocketLang routine for at least the stated duration in seconds ```js ๐Ÿš€ > Time.sleep(2) + ``` @@ -60,6 +65,7 @@ Returns the current time as unix timestamp ```js ๐Ÿš€ > Time.Unix() + ``` @@ -83,3 +89,4 @@ Returns the current time as unix timestamp | 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/docs/literals/array.md b/docs/docs/literals/array.md index 301da6a..bb23356 100644 --- a/docs/docs/literals/array.md +++ b/docs/docs/literals/array.md @@ -32,8 +32,9 @@ Returns the first element of the array. Shorthand for `array[0]` ```js -๐Ÿš€ > ["a", "b", 1, 2].first() -=> "a" +๐Ÿš€ ยป ["a", "b", 1, 2].first() +ยป "a" + ``` @@ -44,8 +45,9 @@ Returns the index of the given element in the array if found. Otherwise return ` ```js -๐Ÿš€ > ["a", "b", 1, 2].index(1) -=> 2 +๐Ÿš€ ยป ["a", "b", 1, 2].index(1) +ยป 2 + ``` @@ -56,8 +58,9 @@ Returns the last element of the array. ```js -๐Ÿš€ > ["a", "b", 1, 2].last() -=> 2 +๐Ÿš€ ยป ["a", "b", 1, 2].last() +ยป 2 + ``` @@ -68,8 +71,9 @@ Reverses the elements of the array ```js -๐Ÿš€ > ["a", "b", 1, 2].reverse() -=> [2, 1, "b", "a"] +๐Ÿš€ ยป ["a", "b", 1, 2].reverse() +ยป [2, 1, "b", "a"] + ``` @@ -80,8 +84,9 @@ Returns the amount of elements in the array. ```js -๐Ÿš€ > ["a", "b", 1, 2].size() -=> 4 +๐Ÿš€ ยป ["a", "b", 1, 2].size() +ยป 4 + ``` @@ -94,6 +99,7 @@ Sorts the array if it contains only one type of STRING, INTEGER or FLOAT ```js ๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() ยป [2.0, 3.1, 3.4] + ``` @@ -104,8 +110,9 @@ Returns a copy of the array with deduplicated elements. Raises an error if a ele ```js -๐Ÿš€ > ["a", 1, 1, 2].uniq() -=> [1, 2, "a"] +๐Ÿš€ ยป ["a", 1, 1, 2].uniq() +ยป [1, 2, "a"] + ``` @@ -116,12 +123,13 @@ Removes the last element of the array and returns it. ```js -๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yeet() -=> 3 -๐Ÿš€ > a -=> [1, 2] +๐Ÿš€ ยป a = [1,2,3] +ยป [1, 2, 3] +๐Ÿš€ ยป a.yeet() +ยป 3 +๐Ÿš€ ยป a +ยป [1, 2] + ``` @@ -132,12 +140,13 @@ Adds the given object as last element to the array. ```js -๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yoink("a") -=> nil -๐Ÿš€ > a -=> [1, 2, 3, "a"] +๐Ÿš€ ยป a = [1,2,3] +ยป [1, 2, 3] +๐Ÿš€ ยป a.yoink("a") +ยป nil +๐Ÿš€ ยป a +ยป [1, 2, 3, "a"] + ``` @@ -150,8 +159,9 @@ Adds the given object as last element to the array. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -160,10 +170,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -172,8 +183,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -182,8 +194,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/boolean.md b/docs/docs/literals/boolean.md index 75cf27a..0443946 100644 --- a/docs/docs/literals/boolean.md +++ b/docs/docs/literals/boolean.md @@ -14,6 +14,7 @@ is_true = a == a; is_false = a == b; is_true = a != b; + ``` ## Literal Specific Methods @@ -25,8 +26,9 @@ Converts a boolean into a String representation and returns `"true"` or `"false" ```js -๐Ÿš€ > true.plz_s() -=> "true" +๐Ÿš€ ยป true.plz_s() +ยป "true" + ``` @@ -39,8 +41,9 @@ Converts a boolean into a String representation and returns `"true"` or `"false" Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -49,10 +52,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -61,8 +65,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -71,8 +76,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/error.md b/docs/docs/literals/error.md index 38d8708..7bbaa35 100644 --- a/docs/docs/literals/error.md +++ b/docs/docs/literals/error.md @@ -51,16 +51,6 @@ Please note that performing `.msg()` on a ERROR object does result in a STRING o ::: -```js -ยป def test() -puts(nope) -rescue e -puts((rescued error: + e.msg())) -end -๐Ÿš€ ยป test() -"rescued error:identifier not found: nope" -``` - ## Generic Literal Methods @@ -71,8 +61,9 @@ end Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -81,10 +72,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -93,8 +85,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -103,8 +96,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/file.md b/docs/docs/literals/file.md index 0564f79..b9477a6 100644 --- a/docs/docs/literals/file.md +++ b/docs/docs/literals/file.md @@ -5,6 +5,7 @@ ```js input = open("examples/aoc/2021/day-1/input").lines() + ``` ## Literal Specific Methods @@ -67,8 +68,9 @@ Writes the given string to the file. Returns number of written bytes on success. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -77,10 +79,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -89,8 +92,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -99,8 +103,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/float.md b/docs/docs/literals/float.md index ac54e80..d62be43 100644 --- a/docs/docs/literals/float.md +++ b/docs/docs/literals/float.md @@ -11,6 +11,12 @@ Returns self +```js +๐Ÿš€ ยป 123.456.plz_f() +ยป 123.456 + +``` + ### plz_i() > Returns `INTEGER` @@ -19,10 +25,9 @@ Converts the float into an integer. ```js -๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_i() -=> "123" +๐Ÿš€ ยป 123.456.plz_i() +ยป 123 + ``` @@ -33,10 +38,9 @@ Returns a string representation of the float. ```js -๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_s() -=> "123.456" +๐Ÿš€ ยป 123.456.plz_s() +ยป "123.456" + ``` @@ -49,8 +53,9 @@ Returns a string representation of the float. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -59,10 +64,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -71,8 +77,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -81,8 +88,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/hash.md b/docs/docs/literals/hash.md index 55da544..acebddb 100644 --- a/docs/docs/literals/hash.md +++ b/docs/docs/literals/hash.md @@ -26,6 +26,7 @@ true 3 "moo" true + ``` ## Literal Specific Methods @@ -37,8 +38,9 @@ Returns the keys of the hash. ```js -๐Ÿš€ > {"a": "1", "b": "2"}.keys() -=> ["a", "b"] +๐Ÿš€ ยป {"a": "1", "b": "2"}.keys() +ยป ["a", "b"] + ``` @@ -49,8 +51,9 @@ Returns the values of the hash. ```js -๐Ÿš€ > {"a": "1", "b": "2"}.values() -=> ["2", "1"] +๐Ÿš€ ยป {"a": "1", "b": "2"}.values() +ยป ["1", "2"] + ``` @@ -63,8 +66,9 @@ Returns the values of the hash. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -73,10 +77,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -85,8 +90,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -95,8 +101,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/http.md b/docs/docs/literals/http.md index 2f97732..3b48f64 100644 --- a/docs/docs/literals/http.md +++ b/docs/docs/literals/http.md @@ -15,6 +15,7 @@ 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 @@ -33,8 +34,10 @@ The response can be adjusted to the needs. It is a HASH supports the following c - "headers" needs to be a HASH(STRING:STRING) eg. headers["Content-Type"] = "text/plain". Default is {"Content-Type": "text/plain"} + ```js -๐Ÿš€ > HTTP.handle("/", callback_func) +๐Ÿš€ ยป HTTP.handle("/", callback_func) + ``` @@ -45,7 +48,8 @@ Starts a blocking webserver on the given port. ```js -๐Ÿš€ > HTTP.listen(3000) +๐Ÿš€ ยป HTTP.listen(3000) + ``` @@ -58,8 +62,9 @@ Starts a blocking webserver on the given port. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -68,10 +73,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -80,8 +86,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -90,8 +97,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/integer.md b/docs/docs/literals/integer.md index a5dd6e1..1cc2b70 100644 --- a/docs/docs/literals/integer.md +++ b/docs/docs/literals/integer.md @@ -5,6 +5,7 @@ An integer can be positiv or negative and is always internally represented by a To cast a negative integer a digit can be prefixed with a - eg. -456. + ```js a = 1; @@ -12,6 +13,7 @@ b = a + 2; is_true = 1 == 1; is_false = 1 == 2; + ``` ## Literal Specific Methods @@ -23,13 +25,9 @@ Converts the integer into a float. ```js -๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_f() -=> 456.0 +๐Ÿš€ ยป 1234.plz_f() +ยป 1234.0 -๐Ÿš€ > 1234.plz_f() -=> 1234.0 ``` @@ -39,6 +37,12 @@ Converts the integer into a float. Returns self +```js +๐Ÿš€ ยป 1234.plz_i() +ยป 1234 + +``` + ### plz_s(INTEGER) > Returns `STRING` @@ -47,17 +51,15 @@ Returns a string representation of the integer. Also takes an argument which rep ```js -๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_s() -=> "456" - -๐Ÿš€ > 1234.plz_s(2) -=> "10011010010" -๐Ÿš€ > 1234.plz_s(8) -=> "2322" -๐Ÿš€ > 1234.plz_s(10) -=> "1234" +๐Ÿš€ ยป 1234.plz_s() +ยป "1234" +๐Ÿš€ ยป 1234.plz_s(2) +ยป "10011010010" +๐Ÿš€ ยป 1234.plz_s(8) +ยป "2322" +๐Ÿš€ ยป 1234.plz_s(10) +ยป "1234" + ``` @@ -70,8 +72,9 @@ Returns a string representation of the integer. Also takes an argument which rep Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -80,10 +83,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -92,8 +96,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -102,8 +107,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/nil.md b/docs/docs/literals/nil.md index b3d55a1..aaa1618 100644 --- a/docs/docs/literals/nil.md +++ b/docs/docs/literals/nil.md @@ -1,7 +1,8 @@ # 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'. +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 @@ -12,6 +13,12 @@ Nil is the representation of "nothing". Returns zero float. +```js +๐Ÿš€ ยป nil.plz_f() +ยป 0.0 + +``` + ### plz_i() > Returns `INTEGER` @@ -19,6 +26,12 @@ Returns zero float. Returns zero integer. +```js +๐Ÿš€ ยป nil.plz_i() +ยป 0 + +``` + ### plz_s() > Returns `STRING` @@ -26,6 +39,12 @@ Returns zero integer. Returns empty string. +```js +๐Ÿš€ ยป nil.plz_s() +ยป "" + +``` + ## Generic Literal Methods @@ -36,8 +55,9 @@ Returns empty string. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -46,10 +66,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -58,8 +79,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -68,8 +90,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` diff --git a/docs/docs/literals/string.md b/docs/docs/literals/string.md index 9a06baf..3fb3bbc 100644 --- a/docs/docs/literals/string.md +++ b/docs/docs/literals/string.md @@ -51,12 +51,11 @@ Counts how often a given substring occurs in the string. ```js -๐Ÿš€ > "test".count("t") -=> 2 -๐Ÿš€ > "test".count("f") -=> 0 -๐Ÿš€ > "test1".count("1") -=> 1 +๐Ÿš€ ยป "test".count("t") +ยป 2 +๐Ÿš€ ยป "test".count("f") +ยป 0 + ``` @@ -67,8 +66,9 @@ Returns the string with all uppercase letters replaced with lowercase counterpar ```js -๐Ÿš€ > "TeST".downcase() -=> test +๐Ÿš€ ยป "TeST".downcase() +ยป "test" + ``` @@ -79,13 +79,13 @@ Replaces all upcase characters with lowercase counterparts. ```js +๐Ÿš€ ยป a = "TeST" +ยป "TeST" +๐Ÿš€ ยป a.downcase!() +ยป nil +๐Ÿš€ ยป a +ยป "test" -๐Ÿš€ > a = "TeST" -=> TeST -๐Ÿš€ > a.downcase!() -=> nil -๐Ÿš€ > a -=> test ``` @@ -96,10 +96,11 @@ Returns the character index of a given string if found. Otherwise returns `-1` ```js -๐Ÿš€ > "test".find("e") -=> 1 -๐Ÿš€ > "test".find("f") -=> -1 +๐Ÿš€ ยป "test".find("e") +ยป 1 +๐Ÿš€ ยป "test".find("f") +ยป -1 + ``` @@ -116,6 +117,7 @@ Formats according to a format specifier and returns the resulting string ยป "test1.50" ๐Ÿš€ ยป "test%s".format("test") ยป "testtest" + ``` @@ -126,8 +128,9 @@ Splits the string at newline escape sequence and return all chunks in an array. ```js -๐Ÿš€ > "test\ntest2".lines() -=> ["test", "test2"] +๐Ÿš€ ยป "test\ntest2".lines() +ยป ["test\ntest2"] + ``` @@ -138,20 +141,17 @@ Interprets the string as an integer with an optional given base. The default bas ```js -๐Ÿš€ > "1234".plz_i() -=> 1234 +๐Ÿš€ ยป "1234".plz_i() +ยป 1234 +๐Ÿš€ ยป "1234".plz_i(8) +ยป 668 +๐Ÿš€ ยป "0x1234".plz_i(8) +ยป 668 +๐Ÿš€ ยป "0x1234".plz_i() +ยป 668 +๐Ÿš€ ยป "0x1234".plz_i(10) +ยป 0 -๐Ÿš€ > "1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i() -=> 668 - -๐Ÿš€ > "0x1234".plz_i(10) -=> 0 ``` @@ -162,8 +162,9 @@ Replaces the first string with the second string in the given string. ```js -๐Ÿš€ > "test".replace("t", "f") -=> "fesf" +๐Ÿš€ ยป "test".replace("t", "f") +ยป "fesf" + ``` @@ -174,8 +175,9 @@ Returns a copy of the string with all characters reversed. ```js -๐Ÿš€ > "stressed".reverse() -=> "desserts" +๐Ÿš€ ยป "stressed".reverse() +ยป "desserts" + ``` @@ -186,12 +188,13 @@ Replaces all the characters in a string in reverse order. ```js -๐Ÿš€ > a = "stressed" -=> "stressed" -๐Ÿš€ > a.reverse!() -=> nil -๐Ÿš€ > a -=> "desserts" +๐Ÿš€ ยป a = "stressed" +ยป "stressed" +๐Ÿš€ ยป a.reverse!() +ยป nil +๐Ÿš€ ยป a +ยป "desserts" + ``` @@ -202,8 +205,9 @@ Returns the amount of characters in the string. ```js -๐Ÿš€ > "test".size() -=> 4 +๐Ÿš€ ยป "test".size() +ยป 4 + ``` @@ -214,11 +218,11 @@ Splits the string on a given seperator and returns all the chunks in an array. D ```js -๐Ÿš€ > "a,b,c,d".split(",") -=> ["a", "b", "c", "d"] +๐Ÿš€ ยป "a,b,c,d".split(",") +ยป ["a", "b", "c", "d"] +๐Ÿš€ ยป "test and another test".split() +ยป ["test", "and", "another", "test"] -๐Ÿš€ > "test and another test".split() -=> ["test", "and", "another", "test"] ``` @@ -229,8 +233,9 @@ Returns a copy of the string with all leading and trailing whitespaces removed. ```js -๐Ÿš€ > " test ".strip() -=> "test" +๐Ÿš€ ยป " test ".strip() +ยป "test" + ``` @@ -241,13 +246,13 @@ Removes all leading and trailing whitespaces in the string. ```js +๐Ÿš€ ยป a = " test " +ยป " test " +๐Ÿš€ ยป a.strip!() +ยป nil +๐Ÿš€ ยป a +ยป "test" -๐Ÿš€ > a = " test " -=> " test " -๐Ÿš€ > a.strip!() -=> nil -๐Ÿš€ > a -=> "test" ``` @@ -258,8 +263,9 @@ Returns the string with all lowercase letters replaced with uppercase counterpar ```js -๐Ÿš€ > "test".upcase() -=> TEST +๐Ÿš€ ยป "test".upcase() +ยป "TEST" + ``` @@ -270,13 +276,13 @@ Replaces all lowercase characters with upcase counterparts. ```js +๐Ÿš€ ยป a = "test" +ยป "test" +๐Ÿš€ ยป a.upcase!() +ยป nil +๐Ÿš€ ยป a +ยป "TEST" -๐Ÿš€ > a = "test" -=> test -๐Ÿš€ > a.upcase!() -=> nil -๐Ÿš€ > a -=> TEST ``` @@ -289,8 +295,9 @@ Replaces all lowercase characters with upcase counterparts. Returns an array of all supported methods names. ```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] +๐Ÿš€ ยป "test".methods() +ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + ``` ### to_json() @@ -299,10 +306,11 @@ Returns an array of all supported methods names. Returns the object as json notation. ```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" +๐Ÿš€ ยป a = {"test": 1234} +ยป {"test": 1234} +๐Ÿš€ ยป a.to_json() +ยป "{\"test\":1234}" + ``` ### type() @@ -311,8 +319,9 @@ Returns the object as json notation. Returns the type of the object. ```js -๐Ÿš€ > "test".type() -=> "STRING" +๐Ÿš€ ยป "test".type() +ยป "STRING" + ``` ### wat() @@ -321,8 +330,9 @@ Returns the type of the object. Returns the supported methods with usage information. ```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() +๐Ÿš€ ยป true.wat() +ยป "BOOLEAN supports the following methods: + plz_s()" + ``` From a2f9fb1699da0f46739ffd0f1d20a0cbff824f77 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Fri, 18 Nov 2022 17:43:59 +0100 Subject: [PATCH 4/6] docs: split up example into in- and output --- docs/builtins/io.yml | 7 +- docs/builtins/json.yml | 11 ++- docs/builtins/math.yml | 140 ++++++++++++++------------ docs/builtins/os.yml | 10 +- docs/builtins/time.yml | 32 +++--- docs/docs/builtins/IO.md | 9 +- docs/docs/builtins/JSON.md | 13 ++- docs/docs/builtins/Math.md | 180 ++++++++++++++++++++++++++-------- docs/docs/builtins/OS.md | 14 ++- docs/docs/builtins/Time.md | 37 +++++-- docs/docs/literals/array.md | 147 ++++++++++++++++++++------- docs/docs/literals/boolean.md | 59 ++++++++--- docs/docs/literals/error.md | 50 +++++++--- docs/docs/literals/file.md | 50 +++++++--- docs/docs/literals/float.md | 77 +++++++++++---- docs/docs/literals/hash.md | 68 ++++++++++--- docs/docs/literals/http.md | 56 ++++++++--- docs/docs/literals/integer.md | 89 ++++++++++++----- docs/docs/literals/nil.md | 77 +++++++++++---- docs/docs/literals/string.md | 180 ++++++++-------------------------- docs/generate.go | 14 ++- docs/literals/array.yml | 79 ++++++++------- docs/literals/boolean.yml | 7 +- docs/literals/float.yml | 21 ++-- docs/literals/hash.yml | 14 +-- docs/literals/http.yml | 8 +- docs/literals/integer.yml | 33 ++++--- docs/literals/nil.yml | 21 ++-- docs/literals/object.yml | 34 ++++--- docs/templates/builtin.md | 9 +- docs/templates/literal.md | 18 +++- object/builtin.go | 3 +- object/object.go | 3 +- 33 files changed, 1020 insertions(+), 550 deletions(-) diff --git a/docs/builtins/io.yml b/docs/builtins/io.yml index 3162a11..45dce84 100644 --- a/docs/builtins/io.yml +++ b/docs/builtins/io.yml @@ -1,6 +1,7 @@ functions: open: description: "Opens a file pointer to the file at the path, mode and permission can be set optionally." - example: | - ๐Ÿš€ ยป IO.open("main.go", "r", "0644") - ยป + input: | + IO.open("main.go", "r", "0644") + output: | + diff --git a/docs/builtins/json.yml b/docs/builtins/json.yml index 4ea9150..ed95106 100644 --- a/docs/builtins/json.yml +++ b/docs/builtins/json.yml @@ -1,8 +1,9 @@ functions: parse: description: "Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT." - example: | - ๐Ÿš€ ยป JSON.parse('{"test": 123}') - ยป {"test": 123.0} - ๐Ÿš€ ยป JSON.parse('["test", 123]') - ยป ["test", 123.0] + input: | + JSON.parse('{"test": 123}') + JSON.parse('["test", 123]') + output: | + {"test": 123.0} + ["test", 123.0] diff --git a/docs/builtins/math.yml b/docs/builtins/math.yml index 72a1805..07fd9e1 100644 --- a/docs/builtins/math.yml +++ b/docs/builtins/math.yml @@ -3,101 +3,121 @@ functions: description: "" acos: description: "Returns the arccosine, in radians, of the argument" - example: | - ๐Ÿš€ > Math.acos(1.0) - => 0.0 + input: | + Math.acos(1.0) + output: | + 0.0 asin: description: "Returns the arcsine, in radians, of the argument" - example: | - ๐Ÿš€ > Math.asin(0.0) - => 0.0 + input: | + Math.asin(0.0) + output: | + 0.0 atan: description: "Returns the arctangent, in radians, of the argument" - example: | - ๐Ÿš€ > Math.atan(0.0) - => 0.0 + input: | + Math.atan(0.0) + output: | + 0.0 ceil: description: "Returns the least integer value greater or equal to the argument" - example: | - ๐Ÿš€ > Math.ceil(1.49) - => 2.0 + input: | + Math.ceil(1.49) + output: | + 2.0 copysign: description: "Returns a value with the magnitude of first argument and sign of second argument" - example: | - ๐Ÿš€ > Math.copysign(3.2, -1.0) - => -3.2 + input: | + Math.copysign(3.2, -1.0) + output: | + -3.2 cos: description: "Returns the cosine of the radion argument" - example: | - ๐Ÿš€ > Math.cos(Pi/2) - => 0.0 + input: | + Math.cos(Pi/2) + output: | + 0.0 exp: description: "Returns e**argument, the base-e exponential of argument" - example: | - ๐Ÿš€ > Math.exp(1.0) - => 2.72 + input: | + Math.exp(1.0) + output: | + 2.72 floor: description: "Returns the greatest integer value less than or equal to argument" - example: | - ๐Ÿš€ > Math.floor(1.51) - => 1.0 + input: | + Math.floor(1.51) + output: | + 1.0 log: description: "Returns the natural logarithm of argument" - example: | - ๐Ÿš€ > Math.log(2.7183) - => 1.0 + input: | + Math.log(2.7183) + output: | + 1.0 log10: description: "Returns the decimal logarithm of argument" - example: | - ๐Ÿš€ > Math.log(100.0) - => 2.0 + input: | + Math.log(100.0) + output: | + 2.0 log2: description: "Returns the binary logarithm of argument" - example: | - ๐Ÿš€ > Math.log2(256.0) - => 8.0 + input: | + Math.log2(256.0) + output: | + 8.0 max: description: "Returns the larger of the two numbers" - example: | - ๐Ÿš€ > Math.max(5.0, 10.0) - => 10.0 + input: | + Math.max(5.0, 10.0) + output: | + 10.0 min: description: "Returns the smaller of the two numbers" - example: | - ๐Ÿš€ > Math.min(5.0, 10.0) - => 5.0 + input: | + Math.min(5.0, 10.0) + output: | + 5.0 pow: description: "Returns argument1**argument2, the base-argument1 exponential of argument2" - example: | - ๐Ÿš€ > Math.pow(2.0, 3.0) - => 8.0 + input: | + Math.pow(2.0, 3.0) + output: | + 8.0 rand: description: "Returns a pseudo-random number in the half-open interval [0.0, 1.0]." - example: | - ๐Ÿš€ > Math.rand() - => 0.6046602879796196 + input: | + Math.rand() + output: | + 0.6046602879796196 remainder: description: "Returns the IEEE 754 floating-point remainder of argument1/argument2" - example: | - ๐Ÿš€ > Math.remainder(100.0, 30.0) - => 10.0 + input: | + Math.remainder(100.0, 30.0) + output: | + 10.0 round: description: "Returns the nearest integer, rounding half away from zero" - example: | - ๐Ÿš€ > Math.round(73.3) - => 73.0 + input: | + Math.round(73.3) + output: | + 73.0 sin: description: "Returns the sine of the radion argument" - example: | - ๐Ÿš€ > Math.sin(Pi) - => 0.0 + input: | + Math.sin(Pi) + output: | + 0.0 sqrt: description: "Returns the square root of argument" - example: | - ๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) - => 5.0 + input: | + Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) + output: | + 5.0 tan: description: "Returns the tangent of the radion argument" - example: | - ๐Ÿš€ > Math.tan(0.0) - => 0.0 + input: | + Math.tan(0.0) + output: | + 0.0 diff --git a/docs/builtins/os.yml b/docs/builtins/os.yml index 1a22693..d7db40b 100644 --- a/docs/builtins/os.yml +++ b/docs/builtins/os.yml @@ -1,12 +1,14 @@ functions: exit: description: "Terminates the program with the given exit code." - example: | - ๐Ÿš€ > OS.exit(1) + input: | + OS.exit(1) + output: | exit status 1 raise: description: "Terminates the program with the given exit code and prints the error message." - example: | - ๐Ÿš€ > OS.raise(1, "broken") + input: | + OS.raise(1, "broken") + output: | ๐Ÿ”ฅ RocketLang raised an error: "broken" exit status 1 diff --git a/docs/builtins/time.yml b/docs/builtins/time.yml index 8db33d1..2fd0d6c 100644 --- a/docs/builtins/time.yml +++ b/docs/builtins/time.yml @@ -6,11 +6,12 @@ functions: [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. - example: | - ๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") - ยป "Mon Oct 31 00:08:10 2022" - ๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") - ยป "Mon Oct 31 00:28:43 2022" + input: | + Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") + Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") + output: | + "Mon Oct 31 00:08:10 2022" + "Mon Oct 31 00:28:43 2022" parse: description: | Parses a given string with the given format to a unix timestamp. @@ -18,16 +19,19 @@ functions: [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. - example: | - ๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") - ยป 1647993600 - ๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") - ยป 1647993600 + input: | + Time.parse("2022-03-23", "2006-01-02") + Time.parse("2022-03-23", "%Y-%m-%d") + output: | + 1647993600 + 1647993600 sleep: description: "Stops the RocketLang routine for at least the stated duration in seconds" - example: | - ๐Ÿš€ > Time.sleep(2) + input: | + Time.sleep(2) unix: description: "Returns the current time as unix timestamp" - example: | - ๐Ÿš€ > Time.Unix() + input: | + Time.unix() + output: | + 1668788502 diff --git a/docs/docs/builtins/IO.md b/docs/docs/builtins/IO.md index 87558d7..8cee320 100644 --- a/docs/docs/builtins/IO.md +++ b/docs/docs/builtins/IO.md @@ -12,11 +12,16 @@ Opens a file pointer to the file at the path, mode and permission can be set opt ```js -๐Ÿš€ ยป IO.open("main.go", "r", "0644") -ยป +IO.open("main.go", "r", "0644") ``` +```js + + +``` + + ## Properties diff --git a/docs/docs/builtins/JSON.md b/docs/docs/builtins/JSON.md index 0dfdb4a..b30f51e 100644 --- a/docs/docs/builtins/JSON.md +++ b/docs/docs/builtins/JSON.md @@ -12,13 +12,18 @@ Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. ```js -๐Ÿš€ ยป JSON.parse('{"test": 123}') -ยป {"test": 123.0} -๐Ÿš€ ยป JSON.parse('["test", 123]') -ยป ["test", 123.0] +JSON.parse('{"test": 123}') +JSON.parse('["test", 123]') ``` +```js +{"test": 123.0} +["test", 123.0] + +``` + + ## Properties diff --git a/docs/docs/builtins/Math.md b/docs/docs/builtins/Math.md index 49829e9..b6303ac 100644 --- a/docs/docs/builtins/Math.md +++ b/docs/docs/builtins/Math.md @@ -19,12 +19,17 @@ Returns the arccosine, in radians, of the argument ```js -๐Ÿš€ > Math.acos(1.0) -=> 0.0 +Math.acos(1.0) + +``` + +```js +0.0 ``` + ### asin(FLOAT) > Returns `FLOAT` @@ -32,11 +37,16 @@ Returns the arcsine, in radians, of the argument ```js -๐Ÿš€ > Math.asin(0.0) -=> 0.0 +Math.asin(0.0) ``` +```js +0.0 + +``` + + ### atan(FLOAT) > Returns `FLOAT` @@ -45,11 +55,16 @@ Returns the arctangent, in radians, of the argument ```js -๐Ÿš€ > Math.atan(0.0) -=> 0.0 +Math.atan(0.0) ``` +```js +0.0 + +``` + + ### ceil(FLOAT) > Returns `FLOAT` @@ -58,12 +73,17 @@ Returns the least integer value greater or equal to the argument ```js -๐Ÿš€ > Math.ceil(1.49) -=> 2.0 +Math.ceil(1.49) + +``` + +```js +2.0 ``` + ### copysign(FLOAT, FLOAT) > Returns `FLOAT` @@ -71,12 +91,17 @@ Returns a value with the magnitude of first argument and sign of second argument ```js -๐Ÿš€ > Math.copysign(3.2, -1.0) -=> -3.2 +Math.copysign(3.2, -1.0) + +``` + +```js +-3.2 ``` + ### cos(FLOAT) > Returns `FLOAT` @@ -84,12 +109,17 @@ Returns the cosine of the radion argument ```js -๐Ÿš€ > Math.cos(Pi/2) -=> 0.0 +Math.cos(Pi/2) + +``` + +```js +0.0 ``` + ### exp(FLOAT) > Returns `FLOAT` @@ -97,11 +127,16 @@ Returns e**argument, the base-e exponential of argument ```js -๐Ÿš€ > Math.exp(1.0) -=> 2.72 +Math.exp(1.0) ``` +```js +2.72 + +``` + + ### floor(FLOAT) > Returns `FLOAT` @@ -110,11 +145,16 @@ Returns the greatest integer value less than or equal to argument ```js -๐Ÿš€ > Math.floor(1.51) -=> 1.0 +Math.floor(1.51) ``` +```js +1.0 + +``` + + ### log(FLOAT) > Returns `FLOAT` @@ -123,12 +163,17 @@ Returns the natural logarithm of argument ```js -๐Ÿš€ > Math.log(2.7183) -=> 1.0 +Math.log(2.7183) + +``` + +```js +1.0 ``` + ### log10(FLOAT) > Returns `FLOAT` @@ -136,12 +181,17 @@ Returns the decimal logarithm of argument ```js -๐Ÿš€ > Math.log(100.0) -=> 2.0 +Math.log(100.0) + +``` + +```js +2.0 ``` + ### log2(FLOAT) > Returns `FLOAT` @@ -149,12 +199,17 @@ Returns the binary logarithm of argument ```js -๐Ÿš€ > Math.log2(256.0) -=> 8.0 +Math.log2(256.0) + +``` + +```js +8.0 ``` + ### max(FLOAT, FLOAT) > Returns `FLOAT` @@ -162,11 +217,16 @@ Returns the larger of the two numbers ```js -๐Ÿš€ > Math.max(5.0, 10.0) -=> 10.0 +Math.max(5.0, 10.0) ``` +```js +10.0 + +``` + + ### min(FLOAT, FLOAT) > Returns `FLOAT` @@ -175,11 +235,16 @@ Returns the smaller of the two numbers ```js -๐Ÿš€ > Math.min(5.0, 10.0) -=> 5.0 +Math.min(5.0, 10.0) ``` +```js +5.0 + +``` + + ### pow(FLOAT, FLOAT) > Returns `FLOAT` @@ -188,12 +253,17 @@ Returns argument1**argument2, the base-argument1 exponential of argument2 ```js -๐Ÿš€ > Math.pow(2.0, 3.0) -=> 8.0 +Math.pow(2.0, 3.0) + +``` + +```js +8.0 ``` + ### rand() > Returns `FLOAT` @@ -201,12 +271,17 @@ Returns a pseudo-random number in the half-open interval [0.0, 1.0]. ```js -๐Ÿš€ > Math.rand() -=> 0.6046602879796196 +Math.rand() + +``` + +```js +0.6046602879796196 ``` + ### remainder(FLOAT, FLOAT) > Returns `FLOAT` @@ -214,12 +289,17 @@ Returns the IEEE 754 floating-point remainder of argument1/argument2 ```js -๐Ÿš€ > Math.remainder(100.0, 30.0) -=> 10.0 +Math.remainder(100.0, 30.0) + +``` + +```js +10.0 ``` + ### round(FLOAT) > Returns `FLOAT` @@ -227,11 +307,16 @@ Returns the nearest integer, rounding half away from zero ```js -๐Ÿš€ > Math.round(73.3) -=> 73.0 +Math.round(73.3) ``` +```js +73.0 + +``` + + ### sin(FLOAT) > Returns `FLOAT` @@ -240,11 +325,16 @@ Returns the sine of the radion argument ```js -๐Ÿš€ > Math.sin(Pi) -=> 0.0 +Math.sin(Pi) ``` +```js +0.0 + +``` + + ### sqrt(FLOAT) > Returns `FLOAT` @@ -253,12 +343,17 @@ Returns the square root of argument ```js -๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) -=> 5.0 +Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) + +``` + +```js +5.0 ``` + ### tan(FLOAT) > Returns `FLOAT` @@ -266,13 +361,18 @@ Returns the tangent of the radion argument ```js -๐Ÿš€ > Math.tan(0.0) -=> 0.0 +Math.tan(0.0) + +``` + +```js +0.0 ``` + ## Properties | Name | Value | | ---- | ----- | diff --git a/docs/docs/builtins/OS.md b/docs/docs/builtins/OS.md index aa619dc..ccee166 100644 --- a/docs/docs/builtins/OS.md +++ b/docs/docs/builtins/OS.md @@ -12,12 +12,17 @@ Terminates the program with the given exit code. ```js -๐Ÿš€ > OS.exit(1) +OS.exit(1) + +``` + +```js exit status 1 ``` + ### raise(INTEGER, STRING) > Returns `` @@ -25,7 +30,11 @@ Terminates the program with the given exit code and prints the error message. ```js -๐Ÿš€ > OS.raise(1, "broken") +OS.raise(1, "broken") + +``` + +```js ๐Ÿ”ฅ RocketLang raised an error: "broken" exit status 1 @@ -33,6 +42,7 @@ exit status 1 + ## Properties | Name | Value | | ---- | ----- | diff --git a/docs/docs/builtins/Time.md b/docs/docs/builtins/Time.md index 9049dc9..24b5fe2 100644 --- a/docs/docs/builtins/Time.md +++ b/docs/docs/builtins/Time.md @@ -17,14 +17,19 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl ```js -๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") -ยป "Mon Oct 31 00:08:10 2022" -๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") -ยป "Mon Oct 31 00:28:43 2022" +Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") +Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") + +``` + +```js +"Mon Oct 31 00:08:10 2022" +"Mon Oct 31 00:28:43 2022" ``` + ### parse(STRING, STRING) > Returns `STRING` @@ -37,14 +42,19 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl ```js -๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") -ยป 1647993600 -๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") -ยป 1647993600 +Time.parse("2022-03-23", "2006-01-02") +Time.parse("2022-03-23", "%Y-%m-%d") + +``` + +```js +1647993600 +1647993600 ``` + ### sleep(INTEGER) > Returns `NIL` @@ -52,11 +62,12 @@ Stops the RocketLang routine for at least the stated duration in seconds ```js -๐Ÿš€ > Time.sleep(2) +Time.sleep(2) ``` + ### unix() > Returns `INTEGER` @@ -64,12 +75,18 @@ Returns the current time as unix timestamp ```js -๐Ÿš€ > Time.Unix() +Time.unix() + +``` + +```js +1668788502 ``` + ## Properties | Name | Value | | ---- | ----- | diff --git a/docs/docs/literals/array.md b/docs/docs/literals/array.md index bb23356..9b65780 100644 --- a/docs/docs/literals/array.md +++ b/docs/docs/literals/array.md @@ -32,11 +32,16 @@ Returns the first element of the array. Shorthand for `array[0]` ```js -๐Ÿš€ ยป ["a", "b", 1, 2].first() -ยป "a" +["a", "b", 1, 2].first() ``` +```js +"a" + +``` + + ### index(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) > Returns `INTEGER` @@ -45,11 +50,16 @@ Returns the index of the given element in the array if found. Otherwise return ` ```js -๐Ÿš€ ยป ["a", "b", 1, 2].index(1) -ยป 2 +["a", "b", 1, 2].index(1) ``` +```js +2 + +``` + + ### last() > Returns `STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE` @@ -58,11 +68,16 @@ Returns the last element of the array. ```js -๐Ÿš€ ยป ["a", "b", 1, 2].last() -ยป 2 +["a", "b", 1, 2].last() ``` +```js +2 + +``` + + ### reverse() > Returns `ARRAY` @@ -71,12 +86,17 @@ Reverses the elements of the array ```js -๐Ÿš€ ยป ["a", "b", 1, 2].reverse() -ยป [2, 1, "b", "a"] +["a", "b", 1, 2].reverse() + +``` + +```js +[2, 1, "b", "a"] ``` + ### size() > Returns `INTEGER` @@ -84,12 +104,17 @@ Returns the amount of elements in the array. ```js -๐Ÿš€ ยป ["a", "b", 1, 2].size() -ยป 4 +["a", "b", 1, 2].size() + +``` + +```js +4 ``` + ### sort() > Returns `ARRAY` @@ -97,12 +122,17 @@ Sorts the array if it contains only one type of STRING, INTEGER or FLOAT ```js -๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() -ยป [2.0, 3.1, 3.4] +[3.4, 3.1, 2.0].sort() + +``` + +```js +[2.0, 3.1, 3.4] ``` + ### uniq() > Returns `ARRAY|ERROR` @@ -110,12 +140,17 @@ Returns a copy of the array with deduplicated elements. Raises an error if a ele ```js -๐Ÿš€ ยป ["a", 1, 1, 2].uniq() -ยป [1, 2, "a"] +["a", 1, 1, 2].uniq() + +``` + +```js +[1, 2, "a"] ``` + ### yeet() > Returns `STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE` @@ -123,16 +158,21 @@ Removes the last element of the array and returns it. ```js -๐Ÿš€ ยป a = [1,2,3] -ยป [1, 2, 3] -๐Ÿš€ ยป a.yeet() -ยป 3 -๐Ÿš€ ยป a -ยป [1, 2] +a = [1,2,3] +a.yeet() +a + +``` + +```js +[1, 2, 3] +3 +[1, 2] ``` + ### yoink(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE) > Returns `NIL` @@ -140,17 +180,22 @@ Adds the given object as last element to the array. ```js -๐Ÿš€ ยป a = [1,2,3] -ยป [1, 2, 3] -๐Ÿš€ ยป a.yoink("a") -ยป nil -๐Ÿš€ ยป a -ยป [1, 2, 3, "a"] +a = [1,2,3] +a.yoink("a") +a + +``` + +```js +[1, 2, 3] +nil +[1, 2, 3, "a"] ``` + ## Generic Literal Methods ### methods() @@ -158,45 +203,73 @@ Adds the given object as last element to the array. Returns an array of all supported methods names. + +```js +"test".methods() + +``` + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] ``` + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + +```js +"test".type() + +``` + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"STRING" ``` + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/docs/literals/boolean.md b/docs/docs/literals/boolean.md index 0443946..5fca7cb 100644 --- a/docs/docs/literals/boolean.md +++ b/docs/docs/literals/boolean.md @@ -26,11 +26,16 @@ Converts a boolean into a String representation and returns `"true"` or `"false" ```js -๐Ÿš€ ยป true.plz_s() -ยป "true" +true.plz_s() ``` +```js +"true" + +``` + + ## Generic Literal Methods @@ -40,45 +45,73 @@ Converts a boolean into a String representation and returns `"true"` or `"false" Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + +```js +"test".type() + +``` + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"STRING" ``` + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + +```js +true.wat() + +``` + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +"BOOLEAN supports the following methods: + plz_s()" ``` + + diff --git a/docs/docs/literals/error.md b/docs/docs/literals/error.md index 7bbaa35..b1ed2ad 100644 --- a/docs/docs/literals/error.md +++ b/docs/docs/literals/error.md @@ -60,45 +60,73 @@ Please note that performing `.msg()` on a ERROR object does result in a STRING o Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +a = {"test": 1234} +a.to_json() ``` +```js +{"test": 1234} +"{\"test\":1234}" + +``` + + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/docs/literals/file.md b/docs/docs/literals/file.md index b9477a6..278307f 100644 --- a/docs/docs/literals/file.md +++ b/docs/docs/literals/file.md @@ -67,45 +67,73 @@ Writes the given string to the file. Returns number of written bytes on success. Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +a = {"test": 1234} +a.to_json() ``` +```js +{"test": 1234} +"{\"test\":1234}" + +``` + + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/docs/literals/float.md b/docs/docs/literals/float.md index d62be43..b621fc7 100644 --- a/docs/docs/literals/float.md +++ b/docs/docs/literals/float.md @@ -12,11 +12,16 @@ Returns self ```js -๐Ÿš€ ยป 123.456.plz_f() -ยป 123.456 +123.456.plz_f() ``` +```js +123.456 + +``` + + ### plz_i() > Returns `INTEGER` @@ -25,11 +30,16 @@ Converts the float into an integer. ```js -๐Ÿš€ ยป 123.456.plz_i() -ยป 123 +123.456.plz_i() ``` +```js +123 + +``` + + ### plz_s() > Returns `STRING` @@ -38,13 +48,18 @@ Returns a string representation of the float. ```js -๐Ÿš€ ยป 123.456.plz_s() -ยป "123.456" +123.456.plz_s() + +``` + +```js +"123.456" ``` + ## Generic Literal Methods ### methods() @@ -52,45 +67,73 @@ Returns a string representation of the float. Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + +```js +true.wat() + +``` + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +"BOOLEAN supports the following methods: + plz_s()" ``` + + diff --git a/docs/docs/literals/hash.md b/docs/docs/literals/hash.md index acebddb..24fb1f9 100644 --- a/docs/docs/literals/hash.md +++ b/docs/docs/literals/hash.md @@ -38,11 +38,16 @@ Returns the keys of the hash. ```js -๐Ÿš€ ยป {"a": "1", "b": "2"}.keys() -ยป ["a", "b"] +{"a": "1", "b": "2"}.keys() ``` +```js +["a", "b"] + +``` + + ### values() > Returns `ARRAY` @@ -51,11 +56,16 @@ Returns the values of the hash. ```js -๐Ÿš€ ยป {"a": "1", "b": "2"}.values() -ยป ["1", "2"] +{"a": "1", "b": "2"}.values() ``` +```js +["1", "2"] + +``` + + ## Generic Literal Methods @@ -65,45 +75,73 @@ Returns the values of the hash. Returns an array of all supported methods names. + +```js +"test".methods() + +``` + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] ``` + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + +```js +"test".type() + +``` + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"STRING" ``` + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/docs/literals/http.md b/docs/docs/literals/http.md index 3b48f64..cef3c52 100644 --- a/docs/docs/literals/http.md +++ b/docs/docs/literals/http.md @@ -36,11 +36,12 @@ The response can be adjusted to the needs. It is a HASH supports the following c ```js -๐Ÿš€ ยป HTTP.handle("/", callback_func) +HTTP.handle("/", callback_func) ``` + ### listen(INTEGER) > Returns `NIL|ERROR` @@ -48,12 +49,13 @@ Starts a blocking webserver on the given port. ```js -๐Ÿš€ ยป HTTP.listen(3000) +HTTP.listen(3000) ``` + ## Generic Literal Methods ### methods() @@ -61,45 +63,73 @@ Starts a blocking webserver on the given port. Returns an array of all supported methods names. + +```js +"test".methods() + +``` + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] ``` + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + +```js +"test".type() + +``` + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"STRING" ``` + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/docs/literals/integer.md b/docs/docs/literals/integer.md index 1cc2b70..6e17702 100644 --- a/docs/docs/literals/integer.md +++ b/docs/docs/literals/integer.md @@ -25,11 +25,16 @@ Converts the integer into a float. ```js -๐Ÿš€ ยป 1234.plz_f() -ยป 1234.0 +1234.plz_f() ``` +```js +1234.0 + +``` + + ### plz_i() > Returns `INTEGER` @@ -38,11 +43,16 @@ Returns self ```js -๐Ÿš€ ยป 1234.plz_i() -ยป 1234 +1234.plz_i() ``` +```js +1234 + +``` + + ### plz_s(INTEGER) > Returns `STRING` @@ -51,19 +61,24 @@ Returns a string representation of the integer. Also takes an argument which rep ```js -๐Ÿš€ ยป 1234.plz_s() -ยป "1234" -๐Ÿš€ ยป 1234.plz_s(2) -ยป "10011010010" -๐Ÿš€ ยป 1234.plz_s(8) -ยป "2322" -๐Ÿš€ ยป 1234.plz_s(10) -ยป "1234" +1234.plz_s() +1234.plz_s(2) +1234.plz_s(8) +1234.plz_s(10) + +``` + +```js +"1234" +"10011010010" +"2322" +"1234" ``` + ## Generic Literal Methods ### methods() @@ -71,45 +86,73 @@ Returns a string representation of the integer. Also takes an argument which rep Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + +```js +true.wat() + +``` + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +"BOOLEAN supports the following methods: + plz_s()" ``` + + diff --git a/docs/docs/literals/nil.md b/docs/docs/literals/nil.md index aaa1618..3d55116 100644 --- a/docs/docs/literals/nil.md +++ b/docs/docs/literals/nil.md @@ -14,11 +14,16 @@ Returns zero float. ```js -๐Ÿš€ ยป nil.plz_f() -ยป 0.0 +nil.plz_f() ``` +```js +0.0 + +``` + + ### plz_i() > Returns `INTEGER` @@ -27,11 +32,16 @@ Returns zero integer. ```js -๐Ÿš€ ยป nil.plz_i() -ยป 0 +nil.plz_i() ``` +```js +0 + +``` + + ### plz_s() > Returns `STRING` @@ -40,13 +50,18 @@ Returns empty string. ```js -๐Ÿš€ ยป nil.plz_s() -ยป "" +nil.plz_s() + +``` + +```js +"" ``` + ## Generic Literal Methods ### methods() @@ -54,45 +69,73 @@ Returns empty string. Returns an array of all supported methods names. + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +"test".methods() ``` +```js +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + +``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + +```js +true.wat() + +``` + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +"BOOLEAN supports the following methods: + plz_s()" ``` + + diff --git a/docs/docs/literals/string.md b/docs/docs/literals/string.md index 3fb3bbc..a121a62 100644 --- a/docs/docs/literals/string.md +++ b/docs/docs/literals/string.md @@ -50,14 +50,6 @@ puts(s) Counts how often a given substring occurs in the string. -```js -๐Ÿš€ ยป "test".count("t") -ยป 2 -๐Ÿš€ ยป "test".count("f") -ยป 0 - -``` - ### downcase() > Returns `STRING` @@ -65,12 +57,6 @@ Counts how often a given substring occurs in the string. Returns the string with all uppercase letters replaced with lowercase counterparts. -```js -๐Ÿš€ ยป "TeST".downcase() -ยป "test" - -``` - ### downcase!() > Returns `NIL` @@ -78,16 +64,6 @@ Returns the string with all uppercase letters replaced with lowercase counterpar Replaces all upcase characters with lowercase counterparts. -```js -๐Ÿš€ ยป a = "TeST" -ยป "TeST" -๐Ÿš€ ยป a.downcase!() -ยป nil -๐Ÿš€ ยป a -ยป "test" - -``` - ### find(STRING) > Returns `INTEGER` @@ -95,14 +71,6 @@ Replaces all upcase characters with lowercase counterparts. Returns the character index of a given string if found. Otherwise returns `-1` -```js -๐Ÿš€ ยป "test".find("e") -ยป 1 -๐Ÿš€ ยป "test".find("f") -ยป -1 - -``` - ### format(STRING|INTEGER|FLOAT|BOOLEAN|ARRAY|HASH) > Returns `STRING` @@ -110,16 +78,6 @@ Returns the character index of a given string if found. Otherwise returns `-1` Formats according to a format specifier and returns the resulting string -```js -๐Ÿš€ ยป "test%9d".format(1) -ยป "test 1" -๐Ÿš€ ยป "test%1.2f".format(1.5) -ยป "test1.50" -๐Ÿš€ ยป "test%s".format("test") -ยป "testtest" - -``` - ### lines() > Returns `ARRAY` @@ -127,12 +85,6 @@ Formats according to a format specifier and returns the resulting string Splits the string at newline escape sequence and return all chunks in an array. Shorthand for `string.split("\n")`. -```js -๐Ÿš€ ยป "test\ntest2".lines() -ยป ["test\ntest2"] - -``` - ### plz_i(INTEGER) > Returns `INTEGER` @@ -140,20 +92,6 @@ Splits the string at newline escape sequence and return all chunks in an array. 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`. -```js -๐Ÿš€ ยป "1234".plz_i() -ยป 1234 -๐Ÿš€ ยป "1234".plz_i(8) -ยป 668 -๐Ÿš€ ยป "0x1234".plz_i(8) -ยป 668 -๐Ÿš€ ยป "0x1234".plz_i() -ยป 668 -๐Ÿš€ ยป "0x1234".plz_i(10) -ยป 0 - -``` - ### replace(STRING, STRING) > Returns `STRING` @@ -161,12 +99,6 @@ Interprets the string as an integer with an optional given base. The default bas Replaces the first string with the second string in the given string. -```js -๐Ÿš€ ยป "test".replace("t", "f") -ยป "fesf" - -``` - ### reverse() > Returns `STRING` @@ -174,12 +106,6 @@ Replaces the first string with the second string in the given string. Returns a copy of the string with all characters reversed. -```js -๐Ÿš€ ยป "stressed".reverse() -ยป "desserts" - -``` - ### reverse!() > Returns `NIL` @@ -187,16 +113,6 @@ Returns a copy of the string with all characters reversed. Replaces all the characters in a string in reverse order. -```js -๐Ÿš€ ยป a = "stressed" -ยป "stressed" -๐Ÿš€ ยป a.reverse!() -ยป nil -๐Ÿš€ ยป a -ยป "desserts" - -``` - ### size() > Returns `INTEGER` @@ -204,12 +120,6 @@ Replaces all the characters in a string in reverse order. Returns the amount of characters in the string. -```js -๐Ÿš€ ยป "test".size() -ยป 4 - -``` - ### split(STRING) > Returns `ARRAY` @@ -217,14 +127,6 @@ Returns the amount of characters in the string. Splits the string on a given seperator and returns all the chunks in an array. Default seperator is `" "` -```js -๐Ÿš€ ยป "a,b,c,d".split(",") -ยป ["a", "b", "c", "d"] -๐Ÿš€ ยป "test and another test".split() -ยป ["test", "and", "another", "test"] - -``` - ### strip() > Returns `STRING` @@ -232,12 +134,6 @@ Splits the string on a given seperator and returns all the chunks in an array. D Returns a copy of the string with all leading and trailing whitespaces removed. -```js -๐Ÿš€ ยป " test ".strip() -ยป "test" - -``` - ### strip!() > Returns `NIL` @@ -245,16 +141,6 @@ Returns a copy of the string with all leading and trailing whitespaces removed. Removes all leading and trailing whitespaces in the string. -```js -๐Ÿš€ ยป a = " test " -ยป " test " -๐Ÿš€ ยป a.strip!() -ยป nil -๐Ÿš€ ยป a -ยป "test" - -``` - ### upcase() > Returns `STRING` @@ -262,12 +148,6 @@ Removes all leading and trailing whitespaces in the string. Returns the string with all lowercase letters replaced with uppercase counterparts. -```js -๐Ÿš€ ยป "test".upcase() -ยป "TEST" - -``` - ### upcase!() > Returns `NIL` @@ -275,16 +155,6 @@ Returns the string with all lowercase letters replaced with uppercase counterpar Replaces all lowercase characters with upcase counterparts. -```js -๐Ÿš€ ยป a = "test" -ยป "test" -๐Ÿš€ ยป a.upcase!() -ยป nil -๐Ÿš€ ยป a -ยป "TEST" - -``` - ## Generic Literal Methods @@ -294,45 +164,73 @@ Replaces all lowercase characters with upcase counterparts. Returns an array of all supported methods names. + +```js +"test".methods() + +``` + ```js -๐Ÿš€ ยป "test".methods() -ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] +["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] ``` + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. + +```js +a = {"test": 1234} +a.to_json() + +``` + ```js -๐Ÿš€ ยป a = {"test": 1234} -ยป {"test": 1234} -๐Ÿš€ ยป a.to_json() -ยป "{\"test\":1234}" +{"test": 1234} +"{\"test\":1234}" ``` + + ### type() > Returns `STRING` Returns the type of the object. + ```js -๐Ÿš€ ยป "test".type() -ยป "STRING" +"test".type() ``` +```js +"STRING" + +``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. + ```js -๐Ÿš€ ยป true.wat() -ยป "BOOLEAN supports the following methods: - plz_s()" +true.wat() ``` +```js +"BOOLEAN supports the following methods: + plz_s()" + +``` + + + diff --git a/docs/generate.go b/docs/generate.go index 28aa39e..e2a0cc8 100644 --- a/docs/generate.go +++ b/docs/generate.go @@ -82,7 +82,7 @@ func createDoc(path string, target string, data any) error { } func loadTemplateData(name string, methods map[string]object.ObjectMethod) (*templateData, error) { - content, err := os.ReadFile(fmt.Sprintf("docs/object/%s.yml", name)) + content, err := os.ReadFile(fmt.Sprintf("docs/literals/%s.yml", name)) if err != nil { return nil, err } @@ -93,7 +93,8 @@ func loadTemplateData(name string, methods map[string]object.ObjectMethod) (*tem Example string `yaml:"example"` Methods map[string]struct { Description string `yaml:"description"` - Example string `yaml:"example"` + Input string `yaml:"input"` + Output string `yaml:"output"` } `yaml:"methods"` } if err := yaml.Unmarshal(content, &docData); err != nil { @@ -113,7 +114,8 @@ func loadTemplateData(name string, methods map[string]object.ObjectMethod) (*tem } if v, ok := docData.Methods[name]; ok { objMethod.Layout.Description = v.Description - objMethod.Layout.Example = v.Example + objMethod.Layout.Input = v.Input + objMethod.Layout.Output = v.Output } tempData.LiteralMethods[name] = objMethod } @@ -132,7 +134,8 @@ func loadBuiltinTemplateData(module *object.BuiltinModule) (*templateData, error Example string `yaml:"example"` Functions map[string]struct { Description string `yaml:"description"` - Example string `yaml:"example"` + Input string `yaml:"input"` + Output string `yaml:"output"` } `yaml:"functions"` } if err := yaml.Unmarshal(content, &docData); err != nil { @@ -153,7 +156,8 @@ func loadBuiltinTemplateData(module *object.BuiltinModule) (*templateData, error } if v, ok := docData.Functions[name]; ok { fn.Layout.Description = v.Description - fn.Layout.Example = v.Example + fn.Layout.Input = v.Input + fn.Layout.Output = v.Output } tempData.Functions[name] = fn } diff --git a/docs/literals/array.yml b/docs/literals/array.yml index 8e337d7..4f7f7de 100644 --- a/docs/literals/array.yml +++ b/docs/literals/array.yml @@ -20,54 +20,63 @@ example: | methods: reverse: description: "Reverses the elements of the array" - example: | - ๐Ÿš€ ยป ["a", "b", 1, 2].reverse() - ยป [2, 1, "b", "a"] + input: | + ["a", "b", 1, 2].reverse() + output: | + [2, 1, "b", "a"] size: description: "Returns the amount of elements in the array." - example: | - ๐Ÿš€ ยป ["a", "b", 1, 2].size() - ยป 4 + input: | + ["a", "b", 1, 2].size() + output: | + 4 sort: description: "Sorts the array if it contains only one type of STRING, INTEGER or FLOAT" - example: | - ๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() - ยป [2.0, 3.1, 3.4] + input: | + [3.4, 3.1, 2.0].sort() + output: | + [2.0, 3.1, 3.4] uniq: description: "Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable." - example: | - ๐Ÿš€ ยป ["a", 1, 1, 2].uniq() - ยป [1, 2, "a"] + input: | + ["a", 1, 1, 2].uniq() + output: | + [1, 2, "a"] index: description: "Returns the index of the given element in the array if found. Otherwise return `-1`." - example: | - ๐Ÿš€ ยป ["a", "b", 1, 2].index(1) - ยป 2 + input: | + ["a", "b", 1, 2].index(1) + output: | + 2 first: description: "Returns the first element of the array. Shorthand for `array[0]`" - example: | - ๐Ÿš€ ยป ["a", "b", 1, 2].first() - ยป "a" + input: | + ["a", "b", 1, 2].first() + output: | + "a" last: description: "Returns the last element of the array." - example: | - ๐Ÿš€ ยป ["a", "b", 1, 2].last() - ยป 2 + input: | + ["a", "b", 1, 2].last() + output: | + 2 yeet: description: "Removes the last element of the array and returns it." - example: | - ๐Ÿš€ ยป a = [1,2,3] - ยป [1, 2, 3] - ๐Ÿš€ ยป a.yeet() - ยป 3 - ๐Ÿš€ ยป a - ยป [1, 2] + input: | + a = [1,2,3] + a.yeet() + a + output: | + [1, 2, 3] + 3 + [1, 2] yoink: description: "Adds the given object as last element to the array." - example: | - ๐Ÿš€ ยป a = [1,2,3] - ยป [1, 2, 3] - ๐Ÿš€ ยป a.yoink("a") - ยป nil - ๐Ÿš€ ยป a - ยป [1, 2, 3, "a"] + input: | + a = [1,2,3] + a.yoink("a") + a + output: | + [1, 2, 3] + nil + [1, 2, 3, "a"] diff --git a/docs/literals/boolean.yml b/docs/literals/boolean.yml index ba80cb7..f063b83 100644 --- a/docs/literals/boolean.yml +++ b/docs/literals/boolean.yml @@ -14,6 +14,7 @@ example: | methods: plz_s: description: "Converts a boolean into a String representation and returns `\"true\"` or `\"false\"` based on the value." - example: | - ๐Ÿš€ ยป true.plz_s() - ยป "true" + input: | + true.plz_s() + output: | + "true" diff --git a/docs/literals/float.yml b/docs/literals/float.yml index f510294..81d845d 100644 --- a/docs/literals/float.yml +++ b/docs/literals/float.yml @@ -2,16 +2,19 @@ title: "Float" methods: plz_f: description: "Returns self" - example: | - ๐Ÿš€ ยป 123.456.plz_f() - ยป 123.456 + input: | + 123.456.plz_f() + output: | + 123.456 plz_s: description: "Returns a string representation of the float." - example: | - ๐Ÿš€ ยป 123.456.plz_s() - ยป "123.456" + input: | + 123.456.plz_s() + output: | + "123.456" plz_i: description: "Converts the float into an integer." - example: | - ๐Ÿš€ ยป 123.456.plz_i() - ยป 123 + input: | + 123.456.plz_i() + output: | + 123 diff --git a/docs/literals/hash.yml b/docs/literals/hash.yml index 4dd4ac8..35db209 100644 --- a/docs/literals/hash.yml +++ b/docs/literals/hash.yml @@ -25,11 +25,13 @@ example: | methods: keys: description: "Returns the keys of the hash." - example: | - ๐Ÿš€ ยป {"a": "1", "b": "2"}.keys() - ยป ["a", "b"] + input: | + {"a": "1", "b": "2"}.keys() + output: | + ["a", "b"] values: description: "Returns the values of the hash." - example: | - ๐Ÿš€ ยป {"a": "1", "b": "2"}.values() - ยป ["1", "2"] + input: | + {"a": "1", "b": "2"}.values() + output: | + ["1", "2"] diff --git a/docs/literals/http.yml b/docs/literals/http.yml index d3b0abe..3c8abe7 100644 --- a/docs/literals/http.yml +++ b/docs/literals/http.yml @@ -14,8 +14,8 @@ example: | methods: listen: description: "Starts a blocking webserver on the given port." - example: | - ๐Ÿš€ ยป HTTP.listen(3000) + input: | + HTTP.listen(3000) handle: description: | Adds a handle to the global HTTP server. Needs to be done before starting one via .listen(). @@ -27,5 +27,5 @@ methods: - "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"} - example: | - ๐Ÿš€ ยป HTTP.handle("/", callback_func) + input: | + HTTP.handle("/", callback_func) diff --git a/docs/literals/integer.yml b/docs/literals/integer.yml index 32aa57c..b210b02 100644 --- a/docs/literals/integer.yml +++ b/docs/literals/integer.yml @@ -13,22 +13,25 @@ example: | methods: plz_s: description: "Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems" - example: | - ๐Ÿš€ ยป 1234.plz_s() - ยป "1234" - ๐Ÿš€ ยป 1234.plz_s(2) - ยป "10011010010" - ๐Ÿš€ ยป 1234.plz_s(8) - ยป "2322" - ๐Ÿš€ ยป 1234.plz_s(10) - ยป "1234" + input: | + 1234.plz_s() + 1234.plz_s(2) + 1234.plz_s(8) + 1234.plz_s(10) + output: | + "1234" + "10011010010" + "2322" + "1234" plz_i: description: "Returns self" - example: | - ๐Ÿš€ ยป 1234.plz_i() - ยป 1234 + input: | + 1234.plz_i() + output: | + 1234 plz_f: description: "Converts the integer into a float." - example: | - ๐Ÿš€ ยป 1234.plz_f() - ยป 1234.0 + input: | + 1234.plz_f() + output: | + 1234.0 diff --git a/docs/literals/nil.yml b/docs/literals/nil.yml index dad9d0b..9dcbdb1 100644 --- a/docs/literals/nil.yml +++ b/docs/literals/nil.yml @@ -5,16 +5,19 @@ description: | methods: plz_s: description: "Returns empty string." - example: | - ๐Ÿš€ ยป nil.plz_s() - ยป "" + input: | + nil.plz_s() + output: | + "" plz_i: description: "Returns zero integer." - example: | - ๐Ÿš€ ยป nil.plz_i() - ยป 0 + input: | + nil.plz_i() + output: | + 0 plz_f: description: "Returns zero float." - example: | - ๐Ÿš€ ยป nil.plz_f() - ยป 0.0 + input: | + nil.plz_f() + output: | + 0.0 diff --git a/docs/literals/object.yml b/docs/literals/object.yml index 6a4b0d8..8253e9a 100644 --- a/docs/literals/object.yml +++ b/docs/literals/object.yml @@ -1,24 +1,28 @@ methods: to_json: description: "Returns the object as json notation." - example: | - ๐Ÿš€ ยป a = {"test": 1234} - ยป {"test": 1234} - ๐Ÿš€ ยป a.to_json() - ยป "{\"test\":1234}" + input: | + a = {"test": 1234} + a.to_json() + output: | + {"test": 1234} + "{\"test\":1234}" methods: description: "Returns an array of all supported methods names." - example: | - ๐Ÿš€ ยป "test".methods() - ยป ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] + input: | + "test".methods() + output: | + ["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] wat: description: "Returns the supported methods with usage information." - example: | - ๐Ÿš€ ยป true.wat() - ยป "BOOLEAN supports the following methods: - plz_s()" + input: | + true.wat() + output: | + "BOOLEAN supports the following methods: + plz_s()" type: description: "Returns the type of the object." - example: | - ๐Ÿš€ ยป "test".type() - ยป "STRING" + input: | + "test".type() + output: | + "STRING" diff --git a/docs/templates/builtin.md b/docs/templates/builtin.md index 20da7fd..c7e7f3e 100644 --- a/docs/templates/builtin.md +++ b/docs/templates/builtin.md @@ -16,10 +16,15 @@ {{ $function.Layout.Description }} -{{ if $function.Layout.Example }} +{{ if $function.Layout.Input }} ```js -{{ $function.Layout.Example }} +{{ $function.Layout.Input }} ``` +{{ if $function.Layout.Output }} +```js +{{ $function.Layout.Output }} +``` +{{ end}} {{ end }} {{ end }} diff --git a/docs/templates/literal.md b/docs/templates/literal.md index bbc250c..cd245b2 100644 --- a/docs/templates/literal.md +++ b/docs/templates/literal.md @@ -14,10 +14,15 @@ {{ $object.Layout.Description }} -{{ if $object.Layout.Example }} +{{ if $object.Layout.Input }} ```js -{{ $object.Layout.Example }} +{{ $object.Layout.Input }} ``` +{{ if $object.Layout.Output }} +```js +{{ $object.Layout.Output }} +``` +{{ end}} {{ end }} {{ end }} @@ -28,7 +33,14 @@ {{ $object.Layout.Description }} +{{ if $object.Layout.Input }} ```js -{{ $object.Layout.Example }} +{{ $object.Layout.Input }} ``` +{{ if $object.Layout.Output }} +```js +{{ $object.Layout.Output }} +``` +{{ end}} +{{ end }} {{ end }} diff --git a/object/builtin.go b/object/builtin.go index acbb4ff..81f776b 100644 --- a/object/builtin.go +++ b/object/builtin.go @@ -3,7 +3,8 @@ package object type BuiltinModule struct { Name string Description string - Example string + Input string + Output string Functions map[string]*BuiltinFunction Properties map[string]*BuiltinProperty } diff --git a/object/object.go b/object/object.go index 2aaf707..110d177 100644 --- a/object/object.go +++ b/object/object.go @@ -110,7 +110,8 @@ type MethodLayout struct { ArgPattern []Argument ReturnPattern []Argument Description string - Example string + Input string + Output string } func (ml MethodLayout) requiredArgs() []Argument { From 53ececab506484b7e91c1d43ac552bf97b680045 Mon Sep 17 00:00:00 2001 From: Flipez Date: Fri, 25 Nov 2022 12:46:55 +0100 Subject: [PATCH 5/6] Update rendered output Signed-off-by: Flipez --- docs/components/CodeBlockSimple.js | 28 +++ docs/docs/builtins/HTTP.md | 4 + docs/docs/builtins/IO.md | 15 +- docs/docs/builtins/JSON.md | 17 +- docs/docs/builtins/Math.md | 264 +++++++---------------------- docs/docs/builtins/OS.md | 28 +-- docs/docs/builtins/Time.md | 46 ++--- docs/docs/literals/array.md | 171 +++++-------------- docs/docs/literals/boolean.md | 67 ++------ docs/docs/literals/error.md | 56 ++---- docs/docs/literals/file.md | 68 +++----- docs/docs/literals/float.md | 93 +++------- docs/docs/literals/hash.md | 80 +++------ docs/docs/literals/http.md | 64 ++----- docs/docs/literals/integer.md | 93 +++------- docs/docs/literals/nil.md | 93 +++------- docs/docs/literals/string.md | 86 +++++----- docs/generate.go | 2 +- docs/templates/builtin.md | 15 +- docs/templates/literal.md | 28 ++- 20 files changed, 403 insertions(+), 915 deletions(-) create mode 100644 docs/components/CodeBlockSimple.js diff --git a/docs/components/CodeBlockSimple.js b/docs/components/CodeBlockSimple.js new file mode 100644 index 0000000..7f2ea6b --- /dev/null +++ b/docs/components/CodeBlockSimple.js @@ -0,0 +1,28 @@ +import React from 'react'; +import CodeBlock from '@theme/CodeBlock'; + +class CodeBlockSimple extends React.Component { + constructor(props){ + super(props); + } + + render() { + return ( +
+ + {this.props.input} + + { this.props.output ? ( + + {this.props.output} + ) : ("") } +
+ ); + } +} + +export default CodeBlockSimple \ No newline at end of file diff --git a/docs/docs/builtins/HTTP.md b/docs/docs/builtins/HTTP.md index ae3436f..f50737d 100644 --- a/docs/docs/builtins/HTTP.md +++ b/docs/docs/builtins/HTTP.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # HTTP @@ -13,6 +15,8 @@ Creates a new instance of HTTP + + ## Properties | Name | Value | | ---- | ----- | diff --git a/docs/docs/builtins/IO.md b/docs/docs/builtins/IO.md index 8cee320..98669ab 100644 --- a/docs/docs/builtins/IO.md +++ b/docs/docs/builtins/IO.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # IO @@ -11,16 +13,9 @@ Opens a file pointer to the file at the path, mode and permission can be set optionally. -```js -IO.open("main.go", "r", "0644") - -``` - -```js - - -``` - + diff --git a/docs/docs/builtins/JSON.md b/docs/docs/builtins/JSON.md index b30f51e..285f04e 100644 --- a/docs/docs/builtins/JSON.md +++ b/docs/docs/builtins/JSON.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # JSON @@ -11,18 +13,11 @@ Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. -```js -JSON.parse('{"test": 123}') -JSON.parse('["test", 123]') - -``` - -```js -{"test": 123.0} + diff --git a/docs/docs/builtins/Math.md b/docs/docs/builtins/Math.md index b6303ac..fdbaac1 100644 --- a/docs/docs/builtins/Math.md +++ b/docs/docs/builtins/Math.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Math @@ -12,22 +14,17 @@ + + ### acos(FLOAT) > Returns `FLOAT` Returns the arccosine, in radians, of the argument -```js -Math.acos(1.0) - -``` - -```js -0.0 - -``` - + ### asin(FLOAT) @@ -36,16 +33,9 @@ Math.acos(1.0) Returns the arcsine, in radians, of the argument -```js -Math.asin(0.0) - -``` - -```js -0.0 - -``` - + ### atan(FLOAT) @@ -54,16 +44,9 @@ Math.asin(0.0) Returns the arctangent, in radians, of the argument -```js -Math.atan(0.0) - -``` - -```js -0.0 - -``` - + ### ceil(FLOAT) @@ -72,16 +55,9 @@ Math.atan(0.0) Returns the least integer value greater or equal to the argument -```js -Math.ceil(1.49) - -``` - -```js -2.0 - -``` - + ### copysign(FLOAT, FLOAT) @@ -90,16 +66,9 @@ Math.ceil(1.49) Returns a value with the magnitude of first argument and sign of second argument -```js -Math.copysign(3.2, -1.0) - -``` - -```js --3.2 - -``` - + ### cos(FLOAT) @@ -108,16 +77,9 @@ Math.copysign(3.2, -1.0) Returns the cosine of the radion argument -```js -Math.cos(Pi/2) - -``` - -```js -0.0 - -``` - + ### exp(FLOAT) @@ -126,16 +88,9 @@ Math.cos(Pi/2) Returns e**argument, the base-e exponential of argument -```js -Math.exp(1.0) - -``` - -```js -2.72 - -``` - + ### floor(FLOAT) @@ -144,16 +99,9 @@ Math.exp(1.0) Returns the greatest integer value less than or equal to argument -```js -Math.floor(1.51) - -``` - -```js -1.0 - -``` - + ### log(FLOAT) @@ -162,16 +110,9 @@ Math.floor(1.51) Returns the natural logarithm of argument -```js -Math.log(2.7183) - -``` - -```js -1.0 - -``` - + ### log10(FLOAT) @@ -180,16 +121,9 @@ Math.log(2.7183) Returns the decimal logarithm of argument -```js -Math.log(100.0) - -``` - -```js -2.0 - -``` - + ### log2(FLOAT) @@ -198,16 +132,9 @@ Math.log(100.0) Returns the binary logarithm of argument -```js -Math.log2(256.0) - -``` - -```js -8.0 - -``` - + ### max(FLOAT, FLOAT) @@ -216,16 +143,9 @@ Math.log2(256.0) Returns the larger of the two numbers -```js -Math.max(5.0, 10.0) - -``` - -```js -10.0 - -``` - + ### min(FLOAT, FLOAT) @@ -234,16 +154,9 @@ Math.max(5.0, 10.0) Returns the smaller of the two numbers -```js -Math.min(5.0, 10.0) - -``` - -```js -5.0 - -``` - + ### pow(FLOAT, FLOAT) @@ -252,16 +165,9 @@ Math.min(5.0, 10.0) Returns argument1**argument2, the base-argument1 exponential of argument2 -```js -Math.pow(2.0, 3.0) - -``` - -```js -8.0 - -``` - + ### rand() @@ -270,16 +176,9 @@ Math.pow(2.0, 3.0) Returns a pseudo-random number in the half-open interval [0.0, 1.0]. -```js -Math.rand() - -``` - -```js -0.6046602879796196 - -``` - + ### remainder(FLOAT, FLOAT) @@ -288,16 +187,9 @@ Math.rand() Returns the IEEE 754 floating-point remainder of argument1/argument2 -```js -Math.remainder(100.0, 30.0) - -``` - -```js -10.0 - -``` - + ### round(FLOAT) @@ -306,16 +198,9 @@ Math.remainder(100.0, 30.0) Returns the nearest integer, rounding half away from zero -```js -Math.round(73.3) - -``` - -```js -73.0 - -``` - + ### sin(FLOAT) @@ -324,16 +209,9 @@ Math.round(73.3) Returns the sine of the radion argument -```js -Math.sin(Pi) - -``` - -```js -0.0 - -``` - + ### sqrt(FLOAT) @@ -342,16 +220,9 @@ Math.sin(Pi) Returns the square root of argument -```js -Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) - -``` - -```js -5.0 - -``` - + ### tan(FLOAT) @@ -360,16 +231,9 @@ Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) Returns the tangent of the radion argument -```js -Math.tan(0.0) - -``` - -```js -0.0 - -``` - + diff --git a/docs/docs/builtins/OS.md b/docs/docs/builtins/OS.md index ccee166..762026e 100644 --- a/docs/docs/builtins/OS.md +++ b/docs/docs/builtins/OS.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # OS @@ -11,16 +13,9 @@ Terminates the program with the given exit code. -```js -OS.exit(1) - -``` - -```js -exit status 1 - -``` - + ### raise(INTEGER, STRING) @@ -29,17 +24,10 @@ exit status 1 Terminates the program with the given exit code and prints the error message. -```js -OS.raise(1, "broken") - -``` - -```js -๐Ÿ”ฅ RocketLang raised an error: "broken" + diff --git a/docs/docs/builtins/Time.md b/docs/docs/builtins/Time.md index 24b5fe2..e4f3ac2 100644 --- a/docs/docs/builtins/Time.md +++ b/docs/docs/builtins/Time.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Time @@ -16,18 +18,11 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl -```js -Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") + ### parse(STRING, STRING) @@ -41,18 +36,11 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl -```js -Time.parse("2022-03-23", "2006-01-02") + ### sleep(INTEGER) @@ -61,10 +49,9 @@ Time.parse("2022-03-23", "%Y-%m-%d") Stops the RocketLang routine for at least the stated duration in seconds -```js -Time.sleep(2) -``` + @@ -74,16 +61,9 @@ Time.sleep(2) Returns the current time as unix timestamp -```js -Time.unix() - -``` - -```js -1668788502 - -``` - + diff --git a/docs/docs/literals/array.md b/docs/docs/literals/array.md index 9b65780..f41197e 100644 --- a/docs/docs/literals/array.md +++ b/docs/docs/literals/array.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Array @@ -31,16 +33,9 @@ puts(a[1:-2]) Returns the first element of the array. Shorthand for `array[0]` -```js -["a", "b", 1, 2].first() - -``` - -```js -"a" - -``` - + ### index(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) @@ -49,16 +44,9 @@ Returns the first element of the array. Shorthand for `array[0]` Returns the index of the given element in the array if found. Otherwise return `-1`. -```js -["a", "b", 1, 2].index(1) - -``` - -```js -2 - -``` - + ### last() @@ -67,16 +55,9 @@ Returns the index of the given element in the array if found. Otherwise return ` Returns the last element of the array. -```js -["a", "b", 1, 2].last() - -``` - -```js -2 - -``` - + ### reverse() @@ -85,16 +66,9 @@ Returns the last element of the array. Reverses the elements of the array -```js -["a", "b", 1, 2].reverse() - -``` - -```js -[2, 1, "b", "a"] - -``` - + ### size() @@ -103,16 +77,9 @@ Reverses the elements of the array Returns the amount of elements in the array. -```js -["a", "b", 1, 2].size() - -``` - -```js -4 - -``` - + ### sort() @@ -121,16 +88,9 @@ Returns the amount of elements in the array. Sorts the array if it contains only one type of STRING, INTEGER or FLOAT -```js -[3.4, 3.1, 2.0].sort() - -``` - -```js -[2.0, 3.1, 3.4] - -``` - + ### uniq() @@ -139,16 +99,9 @@ Sorts the array if it contains only one type of STRING, INTEGER or FLOAT Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable. -```js -["a", 1, 1, 2].uniq() - -``` - -```js -[1, 2, "a"] - -``` - + ### yeet() @@ -157,20 +110,13 @@ Returns a copy of the array with deduplicated elements. Raises an error if a ele Removes the last element of the array and returns it. -```js -a = [1,2,3] + ### yoink(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE) @@ -179,20 +125,13 @@ a Adds the given object as last element to the array. -```js -a = [1,2,3] + @@ -204,16 +143,9 @@ nil Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -222,18 +154,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -242,16 +167,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -260,16 +178,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/boolean.md b/docs/docs/literals/boolean.md index 5fca7cb..2be124a 100644 --- a/docs/docs/literals/boolean.md +++ b/docs/docs/literals/boolean.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Boolean A Boolean can represent two values: `true` and `false` and can be used in control flows. @@ -25,16 +27,9 @@ is_true = a != b; Converts a boolean into a String representation and returns `"true"` or `"false"` based on the value. -```js -true.plz_s() - -``` - -```js -"true" - -``` - + @@ -46,16 +41,9 @@ true.plz_s() Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -64,18 +52,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -84,16 +65,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -102,16 +76,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/error.md b/docs/docs/literals/error.md index b1ed2ad..abce018 100644 --- a/docs/docs/literals/error.md +++ b/docs/docs/literals/error.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Error An Error is created by RocketLang if unallowed or invalid code is run. @@ -53,6 +55,8 @@ Please note that performing `.msg()` on a ERROR object does result in a STRING o + + ## Generic Literal Methods ### methods() @@ -61,16 +65,9 @@ Please note that performing `.msg()` on a ERROR object does result in a STRING o Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -79,18 +76,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -99,16 +89,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -117,16 +100,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/file.md b/docs/docs/literals/file.md index 278307f..d6250e0 100644 --- a/docs/docs/literals/file.md +++ b/docs/docs/literals/file.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # File @@ -17,6 +19,8 @@ Closes the file pointer. Returns always `true`. + + ### content() > Returns `STRING|ERROR` @@ -24,6 +28,8 @@ Reads content of the file and returns it. Resets the position to 0 after read. + + ### lines() > Returns `ARRAY|ERROR` @@ -31,6 +37,8 @@ If successfull, returns all lines of the file as array elements, otherwise `nil` + + ### position() > Returns `INTEGER` @@ -38,6 +46,8 @@ Returns the position of the current file handle. -1 if the file is closed. + + ### read(INTEGER) > Returns `STRING|ERROR` @@ -45,6 +55,8 @@ Reads the given amount of bytes from the file. Sets the position to the bytes th + + ### seek(INTEGER, INTEGER) > Returns `INTEGER|ERROR` @@ -52,6 +64,8 @@ Seek sets the offset for the next Read or Write on file to offset, interpreted a + + ### write(STRING) > Returns `INTEGER|ERROR` @@ -60,6 +74,8 @@ Writes the given string to the file. Returns number of written bytes on success. + + ## Generic Literal Methods ### methods() @@ -68,16 +84,9 @@ Writes the given string to the file. Returns number of written bytes on success. Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -86,18 +95,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -106,16 +108,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -124,16 +119,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/float.md b/docs/docs/literals/float.md index b621fc7..c0e67d0 100644 --- a/docs/docs/literals/float.md +++ b/docs/docs/literals/float.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Float @@ -11,16 +13,9 @@ Returns self -```js -123.456.plz_f() - -``` - -```js -123.456 - -``` - + ### plz_i() @@ -29,16 +24,9 @@ Returns self Converts the float into an integer. -```js -123.456.plz_i() - -``` - -```js -123 - -``` - + ### plz_s() @@ -47,16 +35,9 @@ Converts the float into an integer. Returns a string representation of the float. -```js -123.456.plz_s() - -``` - -```js -"123.456" - -``` - + @@ -68,16 +49,9 @@ Returns a string representation of the float. Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -86,18 +60,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -106,16 +73,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -124,16 +84,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/hash.md b/docs/docs/literals/hash.md index 24fb1f9..c682fc2 100644 --- a/docs/docs/literals/hash.md +++ b/docs/docs/literals/hash.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Hash @@ -37,16 +39,9 @@ true Returns the keys of the hash. -```js -{"a": "1", "b": "2"}.keys() - -``` - -```js -["a", "b"] - -``` - + ### values() @@ -55,16 +50,9 @@ Returns the keys of the hash. Returns the values of the hash. -```js -{"a": "1", "b": "2"}.values() - -``` - -```js -["1", "2"] - -``` - + @@ -76,16 +64,9 @@ Returns the values of the hash. Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -94,18 +75,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -114,16 +88,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -132,16 +99,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/http.md b/docs/docs/literals/http.md index cef3c52..17d0b2c 100644 --- a/docs/docs/literals/http.md +++ b/docs/docs/literals/http.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # HTTP @@ -35,10 +37,9 @@ The response can be adjusted to the needs. It is a HASH supports the following c -```js -HTTP.handle("/", callback_func) -``` + @@ -48,10 +49,9 @@ HTTP.handle("/", callback_func) Starts a blocking webserver on the given port. -```js -HTTP.listen(3000) -``` + @@ -64,16 +64,9 @@ HTTP.listen(3000) Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -82,18 +75,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -102,16 +88,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -120,16 +99,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/integer.md b/docs/docs/literals/integer.md index 6e17702..de30750 100644 --- a/docs/docs/literals/integer.md +++ b/docs/docs/literals/integer.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Integer An integer can be positiv or negative and is always internally represented by a 64-Bit Integer. @@ -24,16 +26,9 @@ is_false = 1 == 2; Converts the integer into a float. -```js -1234.plz_f() - -``` - -```js -1234.0 - -``` - + ### plz_i() @@ -42,16 +37,9 @@ Converts the integer into a float. Returns self -```js -1234.plz_i() - -``` - -```js -1234 - -``` - + ### plz_s(INTEGER) @@ -60,22 +48,15 @@ Returns self Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems -```js -1234.plz_s() + @@ -87,16 +68,9 @@ Returns a string representation of the integer. Also takes an argument which rep Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -105,18 +79,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -125,16 +92,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -143,16 +103,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/nil.md b/docs/docs/literals/nil.md index 3d55116..9562939 100644 --- a/docs/docs/literals/nil.md +++ b/docs/docs/literals/nil.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Nil Nil is the representation of "nothing". @@ -13,16 +15,9 @@ It will be returned if something returns nothing (eg. puts or an empty break/nex Returns zero float. -```js -nil.plz_f() - -``` - -```js -0.0 - -``` - + ### plz_i() @@ -31,16 +26,9 @@ nil.plz_f() Returns zero integer. -```js -nil.plz_i() - -``` - -```js -0 - -``` - + ### plz_s() @@ -49,16 +37,9 @@ nil.plz_i() Returns empty string. -```js -nil.plz_s() - -``` - -```js -"" - -``` - + @@ -70,16 +51,9 @@ nil.plz_s() Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -88,18 +62,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -108,16 +75,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -126,16 +86,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/docs/literals/string.md b/docs/docs/literals/string.md index a121a62..430b46d 100644 --- a/docs/docs/literals/string.md +++ b/docs/docs/literals/string.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # String @@ -51,6 +53,8 @@ Counts how often a given substring occurs in the string. + + ### downcase() > Returns `STRING` @@ -58,6 +62,8 @@ Returns the string with all uppercase letters replaced with lowercase counterpar + + ### downcase!() > Returns `NIL` @@ -65,6 +71,8 @@ Replaces all upcase characters with lowercase counterparts. + + ### find(STRING) > Returns `INTEGER` @@ -72,6 +80,8 @@ Returns the character index of a given string if found. Otherwise returns `-1` + + ### format(STRING|INTEGER|FLOAT|BOOLEAN|ARRAY|HASH) > Returns `STRING` @@ -79,6 +89,8 @@ Formats according to a format specifier and returns the resulting string + + ### lines() > Returns `ARRAY` @@ -86,6 +98,8 @@ Splits the string at newline escape sequence and return all chunks in an array. + + ### plz_i(INTEGER) > Returns `INTEGER` @@ -93,6 +107,8 @@ Interprets the string as an integer with an optional given base. The default bas + + ### replace(STRING, STRING) > Returns `STRING` @@ -100,6 +116,8 @@ Replaces the first string with the second string in the given string. + + ### reverse() > Returns `STRING` @@ -107,6 +125,8 @@ Returns a copy of the string with all characters reversed. + + ### reverse!() > Returns `NIL` @@ -114,6 +134,8 @@ Replaces all the characters in a string in reverse order. + + ### size() > Returns `INTEGER` @@ -121,6 +143,8 @@ Returns the amount of characters in the string. + + ### split(STRING) > Returns `ARRAY` @@ -128,6 +152,8 @@ Splits the string on a given seperator and returns all the chunks in an array. D + + ### strip() > Returns `STRING` @@ -135,6 +161,8 @@ Returns a copy of the string with all leading and trailing whitespaces removed. + + ### strip!() > Returns `NIL` @@ -142,6 +170,8 @@ Removes all leading and trailing whitespaces in the string. + + ### upcase() > Returns `STRING` @@ -149,6 +179,8 @@ Returns the string with all lowercase letters replaced with uppercase counterpar + + ### upcase!() > Returns `NIL` @@ -157,6 +189,8 @@ Replaces all lowercase characters with upcase counterparts. + + ## Generic Literal Methods ### methods() @@ -165,16 +199,9 @@ Replaces all lowercase characters with upcase counterparts. Returns an array of all supported methods names. -```js -"test".methods() - -``` - -```js -["upcase", "find", "format", "reverse", "split", "replace", "strip!", "count", "reverse!", "lines", "downcase!", "upcase!", "size", "plz_i", "strip", "downcase"] - -``` - + ### to_json() @@ -183,18 +210,11 @@ Returns an array of all supported methods names. Returns the object as json notation. -```js -a = {"test": 1234} + ### type() @@ -203,16 +223,9 @@ a.to_json() Returns the type of the object. -```js -"test".type() - -``` - -```js -"STRING" - -``` - + ### wat() @@ -221,16 +234,9 @@ Returns the type of the object. Returns the supported methods with usage information. -```js -true.wat() - -``` - -```js -"BOOLEAN supports the following methods: + diff --git a/docs/generate.go b/docs/generate.go index e2a0cc8..1514c9c 100644 --- a/docs/generate.go +++ b/docs/generate.go @@ -156,7 +156,7 @@ func loadBuiltinTemplateData(module *object.BuiltinModule) (*templateData, error } if v, ok := docData.Functions[name]; ok { fn.Layout.Description = v.Description - fn.Layout.Input = v.Input + fn.Layout.Input = strings.ReplaceAll(v.Input, "'", "'") fn.Layout.Output = v.Output } tempData.Functions[name] = fn diff --git a/docs/templates/builtin.md b/docs/templates/builtin.md index c7e7f3e..fa61641 100644 --- a/docs/templates/builtin.md +++ b/docs/templates/builtin.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # {{ .Title }} {{ .Description }} @@ -16,15 +18,12 @@ {{ $function.Layout.Description }} +{{ if and $function.Layout.Input $function.Layout.Output}} + +{{ else }} {{ if $function.Layout.Input }} -```js -{{ $function.Layout.Input }} -``` -{{ if $function.Layout.Output }} -```js -{{ $function.Layout.Output }} -``` -{{ end}} + +{{ end }} {{ end }} {{ end }} diff --git a/docs/templates/literal.md b/docs/templates/literal.md index cd245b2..f6bb027 100644 --- a/docs/templates/literal.md +++ b/docs/templates/literal.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # {{ .Title }} {{ .Description }} @@ -14,15 +16,12 @@ {{ $object.Layout.Description }} +{{ if and $object.Layout.Input $object.Layout.Output}} + +{{ else }} {{ if $object.Layout.Input }} -```js -{{ $object.Layout.Input }} -``` -{{ if $object.Layout.Output }} -```js -{{ $object.Layout.Output }} -``` -{{ end}} + +{{ end }} {{ end }} {{ end }} @@ -33,14 +32,11 @@ {{ $object.Layout.Description }} +{{ if and $object.Layout.Input $object.Layout.Output}} + +{{ else }} {{ if $object.Layout.Input }} -```js -{{ $object.Layout.Input }} -``` -{{ if $object.Layout.Output }} -```js -{{ $object.Layout.Output }} -``` -{{ end}} + +{{ end }} {{ end }} {{ end }} From 74525fe881fa786cc1a4f79224247852b1748d65 Mon Sep 17 00:00:00 2001 From: Flipez Date: Fri, 25 Nov 2022 13:02:47 +0100 Subject: [PATCH 6/6] Update latest stable version Signed-off-by: Flipez --- .../version-v0.20.1/builtins/HTTP.md | 5 + .../version-v0.20.1/builtins/IO.md | 10 +- .../version-v0.20.1/builtins/JSON.md | 14 +- .../version-v0.20.1/builtins/Math.md | 145 +++++++--------- .../version-v0.20.1/builtins/OS.md | 17 +- .../version-v0.20.1/builtins/Time.md | 42 ++--- .../version-v0.20.1/literals/array.md | 123 +++++++------- .../version-v0.20.1/literals/boolean.md | 52 +++--- .../version-v0.20.1/literals/error.md | 54 +++--- .../version-v0.20.1/literals/file.md | 59 ++++--- .../version-v0.20.1/literals/float.md | 66 ++++---- .../version-v0.20.1/literals/hash.md | 59 ++++--- .../version-v0.20.1/literals/http.md | 60 ++++--- .../version-v0.20.1/literals/integer.md | 84 +++++----- .../version-v0.20.1/literals/nil.md | 59 ++++--- .../version-v0.20.1/literals/string.md | 158 ++++-------------- 16 files changed, 491 insertions(+), 516 deletions(-) diff --git a/docs/versioned_docs/version-v0.20.1/builtins/HTTP.md b/docs/versioned_docs/version-v0.20.1/builtins/HTTP.md index 32f4f31..f50737d 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/HTTP.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/HTTP.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # HTTP @@ -13,6 +15,9 @@ Creates a new instance of HTTP + + ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.20.1/builtins/IO.md b/docs/versioned_docs/version-v0.20.1/builtins/IO.md index 4bd8fdd..98669ab 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/IO.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/IO.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # IO @@ -11,13 +13,13 @@ Opens a file pointer to the file at the path, mode and permission can be set optionally. -```js -๐Ÿš€ > IO.open("main.go", "r", "0644") -=> -``` + ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.20.1/builtins/JSON.md b/docs/versioned_docs/version-v0.20.1/builtins/JSON.md index 695b228..285f04e 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/JSON.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/JSON.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # JSON @@ -11,15 +13,15 @@ Takes a STRING and parses it to a HASH or ARRAY. Numbers are always FLOAT. -```js -๐Ÿš€ > JSON.parse('{"test": 123}') -=> {"test": 123.0} -๐Ÿš€ > JSON.parse('["test", 123]') -=> ["test", 123.0] -``` + ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.20.1/builtins/Math.md b/docs/versioned_docs/version-v0.20.1/builtins/Math.md index 65eed4a..fdbaac1 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/Math.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/Math.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Math @@ -12,16 +14,17 @@ + + ### acos(FLOAT) > Returns `FLOAT` Returns the arccosine, in radians, of the argument -```js -๐Ÿš€ > Math.acos(1.0) -=> 0.0 -``` + ### asin(FLOAT) @@ -30,10 +33,9 @@ Returns the arccosine, in radians, of the argument Returns the arcsine, in radians, of the argument -```js -๐Ÿš€ > Math.asin(0.0) -=> 0.0 -``` + ### atan(FLOAT) @@ -42,10 +44,9 @@ Returns the arcsine, in radians, of the argument Returns the arctangent, in radians, of the argument -```js -๐Ÿš€ > Math.atan(0.0) -=> 0.0 -``` + ### ceil(FLOAT) @@ -54,10 +55,9 @@ Returns the arctangent, in radians, of the argument Returns the least integer value greater or equal to the argument -```js -๐Ÿš€ > Math.ceil(1.49) -=> 2.0 -``` + ### copysign(FLOAT, FLOAT) @@ -66,10 +66,9 @@ Returns the least integer value greater or equal to the argument Returns a value with the magnitude of first argument and sign of second argument -```js -๐Ÿš€ > Math.copysign(3.2, -1.0) -=> -3.2 -``` + ### cos(FLOAT) @@ -78,10 +77,9 @@ Returns a value with the magnitude of first argument and sign of second argument Returns the cosine of the radion argument -```js -๐Ÿš€ > Math.cos(Pi/2) -=> 0.0 -``` + ### exp(FLOAT) @@ -90,10 +88,9 @@ Returns the cosine of the radion argument Returns e**argument, the base-e exponential of argument -```js -๐Ÿš€ > Math.exp(1.0) -=> 2.72 -``` + ### floor(FLOAT) @@ -102,10 +99,9 @@ Returns e**argument, the base-e exponential of argument Returns the greatest integer value less than or equal to argument -```js -๐Ÿš€ > Math.floor(1.51) -=> 1.0 -``` + ### log(FLOAT) @@ -114,10 +110,9 @@ Returns the greatest integer value less than or equal to argument Returns the natural logarithm of argument -```js -๐Ÿš€ > Math.log(2.7183) -=> 1.0 -``` + ### log10(FLOAT) @@ -126,10 +121,9 @@ Returns the natural logarithm of argument Returns the decimal logarithm of argument -```js -๐Ÿš€ > Math.log(100.0) -=> 2.0 -``` + ### log2(FLOAT) @@ -138,10 +132,9 @@ Returns the decimal logarithm of argument Returns the binary logarithm of argument -```js -๐Ÿš€ > Math.log2(256.0) -=> 8.0 -``` + ### max(FLOAT, FLOAT) @@ -150,10 +143,9 @@ Returns the binary logarithm of argument Returns the larger of the two numbers -```js -๐Ÿš€ > Math.max(5.0, 10.0) -=> 10.0 -``` + ### min(FLOAT, FLOAT) @@ -162,10 +154,9 @@ Returns the larger of the two numbers Returns the smaller of the two numbers -```js -๐Ÿš€ > Math.min(5.0, 10.0) -=> 5.0 -``` + ### pow(FLOAT, FLOAT) @@ -174,10 +165,9 @@ Returns the smaller of the two numbers Returns argument1**argument2, the base-argument1 exponential of argument2 -```js -๐Ÿš€ > Math.pow(2.0, 3.0) -=> 8.0 -``` + ### rand() @@ -186,10 +176,9 @@ Returns argument1**argument2, the base-argument1 exponential of argument2 Returns a pseudo-random number in the half-open interval [0.0, 1.0]. -```js -๐Ÿš€ > Math.rand() -=> 0.6046602879796196 -``` + ### remainder(FLOAT, FLOAT) @@ -198,10 +187,9 @@ Returns a pseudo-random number in the half-open interval [0.0, 1.0]. Returns the IEEE 754 floating-point remainder of argument1/argument2 -```js -๐Ÿš€ > Math.remainder(100.0, 30.0) -=> 10.0 -``` + ### round(FLOAT) @@ -210,10 +198,9 @@ Returns the IEEE 754 floating-point remainder of argument1/argument2 Returns the nearest integer, rounding half away from zero -```js -๐Ÿš€ > Math.round(73.3) -=> 73.0 -``` + ### sin(FLOAT) @@ -222,10 +209,9 @@ Returns the nearest integer, rounding half away from zero Returns the sine of the radion argument -```js -๐Ÿš€ > Math.sin(Pi) -=> 0.0 -``` + ### sqrt(FLOAT) @@ -234,10 +220,9 @@ Returns the sine of the radion argument Returns the square root of argument -```js -๐Ÿš€ > Math.sqrt(3.0 * 3.0 + 4.0 * 4.0) -=> 5.0 -``` + ### tan(FLOAT) @@ -246,10 +231,9 @@ Returns the square root of argument Returns the tangent of the radion argument -```js -๐Ÿš€ > Math.tan(0.0) -=> 0.0 -``` + @@ -267,3 +251,4 @@ Returns the tangent of the radion argument | SqrtE | 1.6487212707001282 | | SqrtPhi | 1.272019649514069 | | SqrtPi | 1.772453850905516 | + diff --git a/docs/versioned_docs/version-v0.20.1/builtins/OS.md b/docs/versioned_docs/version-v0.20.1/builtins/OS.md index cfb4674..762026e 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/OS.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/OS.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # OS @@ -11,10 +13,9 @@ Terminates the program with the given exit code. -```js -๐Ÿš€ > OS.exit(1) -exit status 1 -``` + ### raise(INTEGER, STRING) @@ -23,14 +24,14 @@ exit status 1 Terminates the program with the given exit code and prints the error message. -```js -๐Ÿš€ > OS.raise(1, "broken") -๐Ÿ”ฅ RocketLang raised an error: "broken" + ## Properties | Name | Value | | ---- | ----- | + diff --git a/docs/versioned_docs/version-v0.20.1/builtins/Time.md b/docs/versioned_docs/version-v0.20.1/builtins/Time.md index bc9748d..e4f3ac2 100644 --- a/docs/versioned_docs/version-v0.20.1/builtins/Time.md +++ b/docs/versioned_docs/version-v0.20.1/builtins/Time.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Time @@ -8,19 +10,19 @@ ### format(INTEGER, STRING) > Returns `STRING` -Formats the given unix timestamp with the given layout. +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. -```js -๐Ÿš€ ยป Time.format(Time.unix(), "Mon Jan _2 15:04:05 2006") -ยป "Mon Oct 31 00:08:10 2022" -๐Ÿš€ ยป Time.format(Time.unix(), "%a %b %e %H:%M:%S %Y") -ยป "Mon Oct 31 00:28:43 2022" -``` + + ### parse(STRING, STRING) @@ -33,12 +35,12 @@ You can also use some but not all [formats present in many other languages](http Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdlib/time.go) to see which formatters are supported. -```js -๐Ÿš€ ยป Time.parse("2022-03-23", "2006-01-02") -ยป 1647993600 -๐Ÿš€ ยป Time.parse("2022-03-23", "%Y-%m-%d") -ยป 1647993600 -``` + + ### sleep(INTEGER) @@ -47,9 +49,10 @@ Take a look at [the source](https://github.com/Flipez/rocket-lang/blob/main/stdl Stops the RocketLang routine for at least the stated duration in seconds -```js -๐Ÿš€ > Time.sleep(2) -``` + + + ### unix() @@ -58,9 +61,9 @@ Stops the RocketLang routine for at least the stated duration in seconds Returns the current time as unix timestamp -```js -๐Ÿš€ > Time.Unix() -``` + @@ -83,3 +86,4 @@ Returns the current time as unix timestamp | 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.20.1/literals/array.md b/docs/versioned_docs/version-v0.20.1/literals/array.md index 301da6a..f41197e 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/array.md +++ b/docs/versioned_docs/version-v0.20.1/literals/array.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Array @@ -31,10 +33,9 @@ puts(a[1:-2]) Returns the first element of the array. Shorthand for `array[0]` -```js -๐Ÿš€ > ["a", "b", 1, 2].first() -=> "a" -``` + ### index(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FILE) @@ -43,10 +44,9 @@ Returns the first element of the array. Shorthand for `array[0]` Returns the index of the given element in the array if found. Otherwise return `-1`. -```js -๐Ÿš€ > ["a", "b", 1, 2].index(1) -=> 2 -``` + ### last() @@ -55,10 +55,9 @@ Returns the index of the given element in the array if found. Otherwise return ` Returns the last element of the array. -```js -๐Ÿš€ > ["a", "b", 1, 2].last() -=> 2 -``` + ### reverse() @@ -67,10 +66,9 @@ Returns the last element of the array. Reverses the elements of the array -```js -๐Ÿš€ > ["a", "b", 1, 2].reverse() -=> [2, 1, "b", "a"] -``` + ### size() @@ -79,10 +77,9 @@ Reverses the elements of the array Returns the amount of elements in the array. -```js -๐Ÿš€ > ["a", "b", 1, 2].size() -=> 4 -``` + ### sort() @@ -91,10 +88,9 @@ Returns the amount of elements in the array. Sorts the array if it contains only one type of STRING, INTEGER or FLOAT -```js -๐Ÿš€ ยป [3.4, 3.1, 2.0].sort() -ยป [2.0, 3.1, 3.4] -``` + ### uniq() @@ -103,10 +99,9 @@ Sorts the array if it contains only one type of STRING, INTEGER or FLOAT Returns a copy of the array with deduplicated elements. Raises an error if a element is not hashable. -```js -๐Ÿš€ > ["a", 1, 1, 2].uniq() -=> [1, 2, "a"] -``` + ### yeet() @@ -115,14 +110,13 @@ Returns a copy of the array with deduplicated elements. Raises an error if a ele Removes the last element of the array and returns it. -```js -๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yeet() -=> 3 -๐Ÿš€ > a -=> [1, 2] -``` + ### yoink(STRING|ARRAY|HASH|BOOLEAN|INTEGER|NIL|FUNCTION|FILE) @@ -131,14 +125,13 @@ Removes the last element of the array and returns it. Adds the given object as last element to the array. -```js -๐Ÿš€ > a = [1,2,3] -=> [1, 2, 3] -๐Ÿš€ > a.yoink("a") -=> nil -๐Ÿš€ > a -=> [1, 2, 3, "a"] -``` + @@ -149,41 +142,45 @@ Adds the given object as last element to the array. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/boolean.md b/docs/versioned_docs/version-v0.20.1/literals/boolean.md index 75cf27a..2be124a 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/boolean.md +++ b/docs/versioned_docs/version-v0.20.1/literals/boolean.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Boolean A Boolean can represent two values: `true` and `false` and can be used in control flows. @@ -14,6 +16,7 @@ is_true = a == a; is_false = a == b; is_true = a != b; + ``` ## Literal Specific Methods @@ -24,10 +27,9 @@ is_true = a != b; Converts a boolean into a String representation and returns `"true"` or `"false"` based on the value. -```js -๐Ÿš€ > true.plz_s() -=> "true" -``` + @@ -38,41 +40,45 @@ Converts a boolean into a String representation and returns `"true"` or `"false" Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/error.md b/docs/versioned_docs/version-v0.20.1/literals/error.md index 38d8708..abce018 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/error.md +++ b/docs/versioned_docs/version-v0.20.1/literals/error.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Error An Error is created by RocketLang if unallowed or invalid code is run. @@ -51,15 +53,7 @@ Please note that performing `.msg()` on a ERROR object does result in a STRING o ::: -```js -ยป def test() -puts(nope) -rescue e -puts((rescued error: + e.msg())) -end -๐Ÿš€ ยป test() -"rescued error:identifier not found: nope" -``` + @@ -70,41 +64,45 @@ end Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/file.md b/docs/versioned_docs/version-v0.20.1/literals/file.md index 0564f79..d6250e0 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/file.md +++ b/docs/versioned_docs/version-v0.20.1/literals/file.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # File @@ -5,6 +7,7 @@ ```js input = open("examples/aoc/2021/day-1/input").lines() + ``` ## Literal Specific Methods @@ -16,6 +19,8 @@ Closes the file pointer. Returns always `true`. + + ### content() > Returns `STRING|ERROR` @@ -23,6 +28,8 @@ Reads content of the file and returns it. Resets the position to 0 after read. + + ### lines() > Returns `ARRAY|ERROR` @@ -30,6 +37,8 @@ If successfull, returns all lines of the file as array elements, otherwise `nil` + + ### position() > Returns `INTEGER` @@ -37,6 +46,8 @@ Returns the position of the current file handle. -1 if the file is closed. + + ### read(INTEGER) > Returns `STRING|ERROR` @@ -44,6 +55,8 @@ Reads the given amount of bytes from the file. Sets the position to the bytes th + + ### seek(INTEGER, INTEGER) > Returns `INTEGER|ERROR` @@ -51,6 +64,8 @@ Seek sets the offset for the next Read or Write on file to offset, interpreted a + + ### write(STRING) > Returns `INTEGER|ERROR` @@ -59,6 +74,8 @@ Writes the given string to the file. Returns number of written bytes on success. + + ## Generic Literal Methods ### methods() @@ -66,41 +83,45 @@ Writes the given string to the file. Returns number of written bytes on success. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/float.md b/docs/versioned_docs/version-v0.20.1/literals/float.md index ac54e80..c0e67d0 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/float.md +++ b/docs/versioned_docs/version-v0.20.1/literals/float.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Float @@ -11,6 +13,10 @@ Returns self + + ### plz_i() > Returns `INTEGER` @@ -18,12 +24,9 @@ Returns self Converts the float into an integer. -```js -๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_i() -=> "123" -``` + ### plz_s() @@ -32,12 +35,9 @@ Converts the float into an integer. Returns a string representation of the float. -```js -๐Ÿš€ > a = 123.456 -=> 123.456 -๐Ÿš€ > a.plz_s() -=> "123.456" -``` + @@ -48,41 +48,45 @@ Returns a string representation of the float. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/hash.md b/docs/versioned_docs/version-v0.20.1/literals/hash.md index 55da544..c682fc2 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/hash.md +++ b/docs/versioned_docs/version-v0.20.1/literals/hash.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Hash @@ -26,6 +28,7 @@ true 3 "moo" true + ``` ## Literal Specific Methods @@ -36,10 +39,9 @@ true Returns the keys of the hash. -```js -๐Ÿš€ > {"a": "1", "b": "2"}.keys() -=> ["a", "b"] -``` + ### values() @@ -48,10 +50,9 @@ Returns the keys of the hash. Returns the values of the hash. -```js -๐Ÿš€ > {"a": "1", "b": "2"}.values() -=> ["2", "1"] -``` + @@ -62,41 +63,45 @@ Returns the values of the hash. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/http.md b/docs/versioned_docs/version-v0.20.1/literals/http.md index 2f97732..17d0b2c 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/http.md +++ b/docs/versioned_docs/version-v0.20.1/literals/http.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # HTTP @@ -15,6 +17,7 @@ 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 @@ -33,9 +36,11 @@ The response can be adjusted to the needs. It is a HASH supports the following c - "headers" needs to be a HASH(STRING:STRING) eg. headers["Content-Type"] = "text/plain". Default is {"Content-Type": "text/plain"} -```js -๐Ÿš€ > HTTP.handle("/", callback_func) -``` + + + + ### listen(INTEGER) @@ -44,9 +49,10 @@ The response can be adjusted to the needs. It is a HASH supports the following c Starts a blocking webserver on the given port. -```js -๐Ÿš€ > HTTP.listen(3000) -``` + + + @@ -57,41 +63,45 @@ Starts a blocking webserver on the given port. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/integer.md b/docs/versioned_docs/version-v0.20.1/literals/integer.md index a5dd6e1..de30750 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/integer.md +++ b/docs/versioned_docs/version-v0.20.1/literals/integer.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # Integer An integer can be positiv or negative and is always internally represented by a 64-Bit Integer. @@ -5,6 +7,7 @@ An integer can be positiv or negative and is always internally represented by a To cast a negative integer a digit can be prefixed with a - eg. -456. + ```js a = 1; @@ -12,6 +15,7 @@ b = a + 2; is_true = 1 == 1; is_false = 1 == 2; + ``` ## Literal Specific Methods @@ -22,15 +26,9 @@ is_false = 1 == 2; Converts the integer into a float. -```js -๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_f() -=> 456.0 - -๐Ÿš€ > 1234.plz_f() -=> 1234.0 -``` + ### plz_i() @@ -39,6 +37,10 @@ Converts the integer into a float. Returns self + + ### plz_s(INTEGER) > Returns `STRING` @@ -46,19 +48,15 @@ Returns self Returns a string representation of the integer. Also takes an argument which represents the integer base to convert between different number systems -```js -๐Ÿš€ > a = 456 -=> 456 -๐Ÿš€ > a.plz_s() -=> "456" - -๐Ÿš€ > 1234.plz_s(2) -=> "10011010010" -๐Ÿš€ > 1234.plz_s(8) -=> "2322" -๐Ÿš€ > 1234.plz_s(10) -=> "1234" -``` + @@ -69,41 +67,45 @@ Returns a string representation of the integer. Also takes an argument which rep Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/nil.md b/docs/versioned_docs/version-v0.20.1/literals/nil.md index b3d55a1..9562939 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/nil.md +++ b/docs/versioned_docs/version-v0.20.1/literals/nil.md @@ -1,7 +1,10 @@ +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'. +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 @@ -12,6 +15,10 @@ Nil is the representation of "nothing". Returns zero float. + + ### plz_i() > Returns `INTEGER` @@ -19,6 +26,10 @@ Returns zero float. Returns zero integer. + + ### plz_s() > Returns `STRING` @@ -26,6 +37,10 @@ Returns zero integer. Returns empty string. + + ## Generic Literal Methods @@ -35,41 +50,45 @@ Returns empty string. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + + diff --git a/docs/versioned_docs/version-v0.20.1/literals/string.md b/docs/versioned_docs/version-v0.20.1/literals/string.md index 9a06baf..430b46d 100644 --- a/docs/versioned_docs/version-v0.20.1/literals/string.md +++ b/docs/versioned_docs/version-v0.20.1/literals/string.md @@ -1,3 +1,5 @@ +import CodeBlockSimple from '@site/components/CodeBlockSimple' + # String @@ -50,14 +52,7 @@ puts(s) Counts how often a given substring occurs in the string. -```js -๐Ÿš€ > "test".count("t") -=> 2 -๐Ÿš€ > "test".count("f") -=> 0 -๐Ÿš€ > "test1".count("1") -=> 1 -``` + ### downcase() @@ -66,10 +61,7 @@ Counts how often a given substring occurs in the string. Returns the string with all uppercase letters replaced with lowercase counterparts. -```js -๐Ÿš€ > "TeST".downcase() -=> test -``` + ### downcase!() @@ -78,15 +70,7 @@ Returns the string with all uppercase letters replaced with lowercase counterpar Replaces all upcase characters with lowercase counterparts. -```js -๐Ÿš€ > a = "TeST" -=> TeST -๐Ÿš€ > a.downcase!() -=> nil -๐Ÿš€ > a -=> test -``` ### find(STRING) @@ -95,12 +79,7 @@ Replaces all upcase characters with lowercase counterparts. Returns the character index of a given string if found. Otherwise returns `-1` -```js -๐Ÿš€ > "test".find("e") -=> 1 -๐Ÿš€ > "test".find("f") -=> -1 -``` + ### format(STRING|INTEGER|FLOAT|BOOLEAN|ARRAY|HASH) @@ -109,14 +88,7 @@ Returns the character index of a given string if found. Otherwise returns `-1` Formats according to a format specifier and returns the resulting string -```js -๐Ÿš€ ยป "test%9d".format(1) -ยป "test 1" -๐Ÿš€ ยป "test%1.2f".format(1.5) -ยป "test1.50" -๐Ÿš€ ยป "test%s".format("test") -ยป "testtest" -``` + ### lines() @@ -125,10 +97,7 @@ Formats according to a format specifier and returns the resulting string Splits the string at newline escape sequence and return all chunks in an array. Shorthand for `string.split("\n")`. -```js -๐Ÿš€ > "test\ntest2".lines() -=> ["test", "test2"] -``` + ### plz_i(INTEGER) @@ -137,22 +106,7 @@ Splits the string at newline escape sequence and return all chunks in an array. 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`. -```js -๐Ÿš€ > "1234".plz_i() -=> 1234 - -๐Ÿš€ > "1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i(8) -=> 668 - -๐Ÿš€ > "0x1234".plz_i() -=> 668 -๐Ÿš€ > "0x1234".plz_i(10) -=> 0 -``` ### replace(STRING, STRING) @@ -161,10 +115,7 @@ Interprets the string as an integer with an optional given base. The default bas Replaces the first string with the second string in the given string. -```js -๐Ÿš€ > "test".replace("t", "f") -=> "fesf" -``` + ### reverse() @@ -173,10 +124,7 @@ Replaces the first string with the second string in the given string. Returns a copy of the string with all characters reversed. -```js -๐Ÿš€ > "stressed".reverse() -=> "desserts" -``` + ### reverse!() @@ -185,14 +133,7 @@ Returns a copy of the string with all characters reversed. Replaces all the characters in a string in reverse order. -```js -๐Ÿš€ > a = "stressed" -=> "stressed" -๐Ÿš€ > a.reverse!() -=> nil -๐Ÿš€ > a -=> "desserts" -``` + ### size() @@ -201,10 +142,7 @@ Replaces all the characters in a string in reverse order. Returns the amount of characters in the string. -```js -๐Ÿš€ > "test".size() -=> 4 -``` + ### split(STRING) @@ -213,13 +151,7 @@ Returns the amount of characters in the string. Splits the string on a given seperator and returns all the chunks in an array. Default seperator is `" "` -```js -๐Ÿš€ > "a,b,c,d".split(",") -=> ["a", "b", "c", "d"] -๐Ÿš€ > "test and another test".split() -=> ["test", "and", "another", "test"] -``` ### strip() @@ -228,10 +160,7 @@ Splits the string on a given seperator and returns all the chunks in an array. D Returns a copy of the string with all leading and trailing whitespaces removed. -```js -๐Ÿš€ > " test ".strip() -=> "test" -``` + ### strip!() @@ -240,15 +169,7 @@ Returns a copy of the string with all leading and trailing whitespaces removed. Removes all leading and trailing whitespaces in the string. -```js -๐Ÿš€ > a = " test " -=> " test " -๐Ÿš€ > a.strip!() -=> nil -๐Ÿš€ > a -=> "test" -``` ### upcase() @@ -257,10 +178,7 @@ Removes all leading and trailing whitespaces in the string. Returns the string with all lowercase letters replaced with uppercase counterparts. -```js -๐Ÿš€ > "test".upcase() -=> TEST -``` + ### upcase!() @@ -269,15 +187,7 @@ Returns the string with all lowercase letters replaced with uppercase counterpar Replaces all lowercase characters with upcase counterparts. -```js -๐Ÿš€ > a = "test" -=> test -๐Ÿš€ > a.upcase!() -=> nil -๐Ÿš€ > a -=> TEST -``` @@ -288,41 +198,45 @@ Replaces all lowercase characters with upcase counterparts. Returns an array of all supported methods names. -```js -๐Ÿš€ > "test".methods() -=> [count, downcase, find, reverse!, split, lines, upcase!, strip!, downcase!, size, plz_i, replace, reverse, strip, upcase] -``` + + + ### to_json() > Returns `STRING|ERROR` Returns the object as json notation. -```js -๐Ÿš€ > a = {"test": 1234} -=> {"test": 1234} -๐Ÿš€ > a.to_json() -=> "{"test":1234}" -``` + + + ### type() > Returns `STRING` Returns the type of the object. -```js -๐Ÿš€ > "test".type() -=> "STRING" -``` + + + ### wat() > Returns `STRING` Returns the supported methods with usage information. -```js -๐Ÿš€ > true.wat() -=> BOOLEAN supports the following methods: - plz_s() -``` + + +