From ea9d19b777174cbf0f7de346237f9f5b3d3a2d1d Mon Sep 17 00:00:00 2001 From: Francesco Cozzuto Date: Wed, 6 Aug 2025 00:23:10 +0200 Subject: [PATCH] Add minimal examples --- examples/000_comment.wl | 1 + examples/001_basic_html.wl | 45 ++++++++++++++++ examples/002_ifelse_and_while.wl | 58 ++++++++++++++++++++ examples/003_for_arrays_and_maps.wl | 83 +++++++++++++++++++++++++++++ examples/004_functions.wl | 26 +++++++++ main.c | 10 +++- main.wl | 1 - 7 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 examples/000_comment.wl create mode 100644 examples/001_basic_html.wl create mode 100644 examples/002_ifelse_and_while.wl create mode 100644 examples/003_for_arrays_and_maps.wl create mode 100644 examples/004_functions.wl diff --git a/examples/000_comment.wl b/examples/000_comment.wl new file mode 100644 index 0000000..279ca5e --- /dev/null +++ b/examples/000_comment.wl @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/001_basic_html.wl b/examples/001_basic_html.wl new file mode 100644 index 0000000..779b798 --- /dev/null +++ b/examples/001_basic_html.wl @@ -0,0 +1,45 @@ + + +I'm a link + + + +let name = "cozis" + +

Hello from \name

+ + + +let valueA = "Some value" + +

+ + + +let link = Click me + + + +link + +

You should click this link: \link

diff --git a/examples/002_ifelse_and_while.wl b/examples/002_ifelse_and_while.wl new file mode 100644 index 0000000..6c02faa --- /dev/null +++ b/examples/002_ifelse_and_while.wl @@ -0,0 +1,58 @@ + + +let a = 2 + +if a == 1: { + The condition is true +} else { + It is false +} + + + +

+ \if a == 1: { + The condition is true + } else { + It is false + } +

+ + + +let i = 0 +while i < 3: { + I'm link number \i + 1 + i = i + 1 +} + + + +i = 0 + \ No newline at end of file diff --git a/examples/003_for_arrays_and_maps.wl b/examples/003_for_arrays_and_maps.wl new file mode 100644 index 0000000..3f5cc62 --- /dev/null +++ b/examples/003_for_arrays_and_maps.wl @@ -0,0 +1,83 @@ + + + +let my_var = [1, 2, 3] + +my_var + + + +let my_map = { 1: "First", 2: "Second", 3: "Third" } + +my_map[2] + + + +let person = { "name": "Cozis" } +let person_no_quotes = { name: "Cozis" } + + + +for key in { A: 1, B: 2, C: 3 }: { + key +} + +for key, i in { A: 1, B: 2, C: 3 }: { + +} + + + +for val in [5, 3, 7]: + val + +for val, i in [5, 3, 7]: + i + + + +let links = ["http://github.com", "http://reddit.com"] + + diff --git a/examples/004_functions.wl b/examples/004_functions.wl new file mode 100644 index 0000000..f605abe --- /dev/null +++ b/examples/004_functions.wl @@ -0,0 +1,26 @@ + + + +fun say_hello(name) { + print "Hello to " + print name +} + +say_hello("cozis") + + + +fun say_hello_2(name) + Hello, \name! + +say_hello_2("cozis") diff --git a/main.c b/main.c index a0b45fd..d393b5d 100644 --- a/main.c +++ b/main.c @@ -4,9 +4,15 @@ #include "WL.h" -int main(void) +int main(int argc, char **argv) { - FILE *f = fopen("main.wl", "rb"); + if (argc < 2) { + printf("Missing file path\n"); + return -1; + } + char *file = argv[1]; + + FILE *f = fopen(file, "rb"); if (f == NULL) return -1; diff --git a/main.wl b/main.wl index cf913c4..1c51696 100644 --- a/main.wl +++ b/main.wl @@ -2,5 +2,4 @@ let set = {a: "G", b: "T", c: "K"} for item, i in set: {
  • \item \i \set[item]
  • - "\n" }