From b0028d48746f70e218c3cb85e1b124effffa2a62 Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Wed, 13 Sep 2023 11:59:21 -0700 Subject: [PATCH] add basic docs for lang things (#484) Signed-off-by: Jess Frazelle --- docs/{kcl.json => kcl/std.json} | 0 docs/{kcl.md => kcl/std.md} | 0 docs/kcl/types.md | 75 +++++++++++++++++++++++++++++++++ src/wasm-lib/kcl/src/std/mod.rs | 4 +- 4 files changed, 77 insertions(+), 2 deletions(-) rename docs/{kcl.json => kcl/std.json} (100%) rename docs/{kcl.md => kcl/std.md} (100%) create mode 100644 docs/kcl/types.md diff --git a/docs/kcl.json b/docs/kcl/std.json similarity index 100% rename from docs/kcl.json rename to docs/kcl/std.json diff --git a/docs/kcl.md b/docs/kcl/std.md similarity index 100% rename from docs/kcl.md rename to docs/kcl/std.md diff --git a/docs/kcl/types.md b/docs/kcl/types.md new file mode 100644 index 000000000..ee38dd607 --- /dev/null +++ b/docs/kcl/types.md @@ -0,0 +1,75 @@ +# Types + +`KCL` defines the following types and keywords the language. + +All these types can be nested in various forms where nesting applies. Like +arrays can hold objects and vice versa. + +## Boolean + +`true` or `false` work when defining values. + +## Variable declaration + +Variables are defined with the `let` keyword like so: + +``` +let myBool = false +``` + +## Array + +An array is defined with `[]` braces. What is inside the brackets can +be of any type. For example, the following is completely valid: + +``` +let myArray = ["thing", 2, false] +``` + +If you want to get a value from an array you can use the index like so: +`myArray[0]`. + + +## Object + +An object is defined with `{}` braces. Here is an example object: + +``` +let myObj = {a: 0, b: "thing"} +``` + +We support two different ways of getting properties from objects, you can call +`myObj.a` or `myObj["a"]` both work. + + +## Functions + +We also have support for defining your own functions. Functions can take in any +type of argument. Below is an example of the syntax: + +``` +fn myFn = (x) => { + return x +} +``` + +As you can see above `myFn` just returns whatever it is given. + + +## Binary expressions + +You can also do math! Let's show an example below: + +``` +let myMathExpression = 3 + 1 * 2 / 3 - 7 +``` + +You can nest expressions in parenthesis as well: + +``` +let myMathExpression = 3 + (1 * 2 / (3 - 7)) +``` + +Please if you find any issues using any of the above expressions or syntax +please file an issue with the `ast` label on the [modeling-app +repo](https://github.com/KittyCAD/modeling-app/issues/new). diff --git a/src/wasm-lib/kcl/src/std/mod.rs b/src/wasm-lib/kcl/src/std/mod.rs index d00b746c0..5f9dc30a8 100644 --- a/src/wasm-lib/kcl/src/std/mod.rs +++ b/src/wasm-lib/kcl/src/std/mod.rs @@ -591,7 +591,7 @@ mod tests { buf.push_str(&fn_docs); } - expectorate::assert_contents("../../../docs/kcl.md", &buf); + expectorate::assert_contents("../../../docs/kcl/std.md", &buf); } #[test] @@ -606,7 +606,7 @@ mod tests { } expectorate::assert_contents( - "../../../docs/kcl.json", + "../../../docs/kcl/std.json", &serde_json::to_string_pretty(&json_data).unwrap(), ); }