Skip to content

Commit

Permalink
continue syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
kuviman committed Dec 4, 2024
1 parent ff7f7b3 commit 11fb05d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions examples/loops.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std.*;

for c :: char in chars "hello, world" {
if c == 'l' then ( continue );
if c == ' ' then ( break );
dbg c;
}
4 changes: 4 additions & 0 deletions std/lib.ks
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ impl syntax @"syntax".break_with_value = macro (.value) => `(
(current loop_context[_]).@"break" $value
);

impl syntax @"syntax".@"continue" = macro _ => `(
(current loop_context[()]).@"continue" () # TODO infer loop context arg
);

const chars :: string -> () with generator_handler[char] = native "chars";
const push_char :: (string, char) -> string = native "push_char";

Expand Down
2 changes: 1 addition & 1 deletion std/syntax.ks
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ syntax_module {
# syntax return <- 2 = "return" value;
syntax break_with_value <- 2 = "break" value;
syntax break_without_value <- 2 = "break";
# syntax continue_impl <- 2 = "continue";
syntax continue <- 2 = "continue";
syntax yield <- 2 = "yield" value;

syntax @"loop" <- 3 = "loop" "{" body "}";
Expand Down

0 comments on commit 11fb05d

Please sign in to comment.