From 63ef3c0b5e5f5c218a76e4451f3bc76510c31b1c Mon Sep 17 00:00:00 2001 From: Araozu Date: Fri, 22 Nov 2024 07:09:32 -0500 Subject: [PATCH] feat: docs --- src/lexer/highlighter.ts | 2 +- .../en/latest/learn/03_flow-control/match.mdx | 11 ++++ .../en/latest/learn/03_flow-control/pipes.mdx | 52 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/pages/en/latest/learn/03_flow-control/pipes.mdx diff --git a/src/lexer/highlighter.ts b/src/lexer/highlighter.ts index bb922fa..87a3e7c 100644 --- a/src/lexer/highlighter.ts +++ b/src/lexer/highlighter.ts @@ -12,7 +12,7 @@ const error_classes = "underline underline-offset-4 decoration-wavy decoration-r * - The tokens as a list of elements * - An error message, if any */ -export async function native_highlighter(code: string, level = HighlightLevel.Syntactic): Promise<[string, string | null]> { +export async function native_highlighter(code: string, level = HighlightLevel.Lexic): Promise<[string, string | null]> { let formatted_code = leftTrimDedent(code).join("\n"); try { diff --git a/src/pages/en/latest/learn/03_flow-control/match.mdx b/src/pages/en/latest/learn/03_flow-control/match.mdx index 1bc1dc2..a5bbc52 100644 --- a/src/pages/en/latest/learn/03_flow-control/match.mdx +++ b/src/pages/en/latest/learn/03_flow-control/match.mdx @@ -42,5 +42,16 @@ case 1, 2, 3 { else { print("hello dear") } + +match customer_id +| 1 | 2 | 3 { + print("ehhhh") +} +| 4 | 5 { + print("ohhh") +} +| _ { + print("???") +} `} /> diff --git a/src/pages/en/latest/learn/03_flow-control/pipes.mdx b/src/pages/en/latest/learn/03_flow-control/pipes.mdx new file mode 100644 index 0000000..753b712 --- /dev/null +++ b/src/pages/en/latest/learn/03_flow-control/pipes.mdx @@ -0,0 +1,52 @@ +--- +layout: "../_wrapper.astro" +title: Pipes +--- +import Code from "@/components/Code.astro" + +# Pipes + +You can use pipes `|>` & `<|` to redirect output from an +expression as input to another. + +For example, instead of writing: + + + +You can use pipes: + + first_function + |> second_function + |> third_function +`} /> + +Or use it to group expressions: + + + +TBD: How to handle piping to functions with more than 1 param + +## Function composition + + Int { + x + 1 +} + +fun times_two(x: Int) -> Int { + x * 2 +} + +// (Int) -> (Int) +val plus_one_times_2 = add_one >> times_two + +print(plus_one_times_2(5)) // 12 +`} /> + +