diff --git a/examples/cpu_monitor.whale b/examples/cpu_monitor.whale deleted file mode 100644 index 475ec22..0000000 --- a/examples/cpu_monitor.whale +++ /dev/null @@ -1,9 +0,0 @@ -loop(' - speed = cpu_speed(); - message = "Current CPU clock: " + string(speed); - - output(message); - wait 300; -'); - - diff --git a/examples/fetch.ds b/examples/fetch.ds new file mode 100644 index 0000000..7a11fab --- /dev/null +++ b/examples/fetch.ds @@ -0,0 +1,4 @@ +raw_data = download("https://api.sampleapis.com/futurama/cast"); +data = from_json(raw_data); + +assert_equal("Billy West", data.0.name); diff --git a/examples/fetch.whale b/examples/fetch.whale deleted file mode 100644 index ad19c67..0000000 --- a/examples/fetch.whale +++ /dev/null @@ -1,4 +0,0 @@ -raw_data = download "https://api.sampleapis.com/futurama/cast"; -data = raw_data:from_json(); -first = data:get 0; -first.name diff --git a/examples/hello_world.whale b/examples/hello_world.whale deleted file mode 100644 index 83743f0..0000000 --- a/examples/hello_world.whale +++ /dev/null @@ -1 +0,0 @@ -output "Hello world!" diff --git a/examples/map.whale b/examples/map.whale deleted file mode 100644 index c2c89a1..0000000 --- a/examples/map.whale +++ /dev/null @@ -1,7 +0,0 @@ -x = 1; -y = 2; -z = 3; -a = "foo"; -b = "bar"; -c = "foobar"; -d = ("abc", "123", "xyz"); diff --git a/examples/random_user_data.whale b/examples/random_user_data.whale deleted file mode 100644 index b028177..0000000 --- a/examples/random_user_data.whale +++ /dev/null @@ -1,14 +0,0 @@ -create_user = ' - names = ("bob", "bill", "mary", "susan"); - (random_integer(), names:random(), random_integer(0, 100)) -'; - -create_table( - ("id", "name", "age"), - ( - repeat ( - create_user, - 10 - ) - ) -) \ No newline at end of file diff --git a/examples/toolbox.whale b/examples/toolbox.whale deleted file mode 100644 index 660fe86..0000000 --- a/examples/toolbox.whale +++ /dev/null @@ -1,21 +0,0 @@ -enable_copr_repositories = ("varlad/helix"); -enable_rpm_repositories ( - "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-38.noarch.rpm", - "https://mirrors.rpmfusion.org/free/fedora/rpmfusion-nonfree-release-38.noarch.rpm" -); -install_package ( - "bat", - "egl-wayland", - "fd-find", - "fish", - "fzf", - "lsd", - "kitty", - "helix", - "libwayland-cursor", - "libwayland-egl", - "wl-clipboard" -); - -sh "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"; -sh "cargo install starship zoxide"; \ No newline at end of file diff --git a/examples/wait.whale b/examples/wait.whale deleted file mode 100644 index 2aaec87..0000000 --- a/examples/wait.whale +++ /dev/null @@ -1,3 +0,0 @@ -output "foo..."; -wait 1; -output "bar!"; \ No newline at end of file diff --git a/src/interface.rs b/src/interface.rs index f44e864..850e94c 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -29,8 +29,21 @@ pub fn eval(string: &str) -> Result { /// ``` /// /// *See the [crate doc](index.html) for more examples and explanations of the expression format.* -pub fn eval_with_context(string: &str, context: &mut VariableMap) -> Result { - let split = string.split_once("::"); +pub fn eval_with_context(input: &str, context: &mut VariableMap) -> Result { + let without_comments = input + .lines() + .map(|line| { + let split = line.split_once('#'); + + if let Some((code, _comment)) = split { + code + } else { + line + } + }) + .collect::(); + + let split = without_comments.split_once("->"); if let Some((left, right)) = split { let left_result = tree::tokens_to_operator_tree(token::tokenize(left)?)? @@ -42,6 +55,7 @@ pub fn eval_with_context(string: &str, context: &mut VariableMap) -> Result