diff --git a/README.md b/README.md index 7922666..77d36a7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A very cool language * Growing [standard library](https://git.ton1.dev/toni/zern/src/branch/main/src/std) * Produces tiny static executables (11KB for `hello.zr`) * No libc required! -* Has type inference, pipe operator, variadics, dynamic arrays, hashmaps, DNS resolver, etc. +* Has type inference, variadics, dynamic arrays, hashmaps, DNS resolver, etc. ## Syntax ```rust @@ -17,7 +17,7 @@ func main[] : i64 while true io.println("Guess a number: ") - guess := io.read_line() |> str.trim() |> str.parse_i64() + guess := str.parse_i64(io.read_line()) if guess == answer io.println("You win!") @@ -28,20 +28,6 @@ func main[] : i64 io.println("Too high!") ``` -```rust -func square[x: i64] : i64 - return x * x - -func sum[a: i64, b: i64] : i64 - return a + b - -func main[] : i64 - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - |> alg.map(^square) - |> alg.reduce(^sum, 0) - |> io.println_i64() -``` - ## Quickstart ``` cargo install --git https://git.ton1.dev/toni/zern diff --git a/examples/functional.zr b/examples/functional.zr deleted file mode 100644 index c87fde1..0000000 --- a/examples/functional.zr +++ /dev/null @@ -1,11 +0,0 @@ -func square[x: i64] : i64 - return x * x - -func sum[a: i64, b: i64] : i64 - return a + b - -func main[] : i64 - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] - |> alg.map(^square) - |> alg.reduce(^sum, 0) - |> io.println_i64() diff --git a/examples/guess_number.zr b/examples/guess_number.zr index 361cc9d..2637acd 100644 --- a/examples/guess_number.zr +++ b/examples/guess_number.zr @@ -3,7 +3,7 @@ func main[] : i64 while true io.println("Guess a number: ") - guess := io.read_line() |> str.trim() |> str.parse_i64() + guess := str.parse_i64(io.read_line()) if guess == answer io.println("You win!") diff --git a/examples/puzzles/aoc2025_01.zr b/examples/puzzles/aoc2025_01.zr index 5483946..1b9b616 100644 --- a/examples/puzzles/aoc2025_01.zr +++ b/examples/puzzles/aoc2025_01.zr @@ -5,7 +5,7 @@ func part1[lines: Array] : void for i in 0..lines->size line : str = array.nth(lines, i) dir := line[0] - n := str.substr(line, 1, str.len(line) - 1) |> str.parse_i64() + n := str.parse_i64(str.substr(line, 1, str.len(line) - 1)) if dir == 'L' dial -= n @@ -28,7 +28,7 @@ func part2[lines: Array] : void for i in 0..lines->size line : str = array.nth(lines, i) dir := line[0] - n := str.substr(line, 1, str.len(line) - 1) |> str.parse_i64() + n := str.parse_i64(str.substr(line, 1, str.len(line) - 1)) if dir == 'L' for i in 0..n diff --git a/examples/puzzles/aoc2025_02.zr b/examples/puzzles/aoc2025_02.zr index 72d5252..d3cd10f 100644 --- a/examples/puzzles/aoc2025_02.zr +++ b/examples/puzzles/aoc2025_02.zr @@ -12,9 +12,9 @@ func part1[ranges: Array] : void sum := 0 for i in 0..ranges->size - parts := array.nth(ranges, i) |> str.split("-") - start := array.nth(parts, 0) |> str.parse_i64() - end := array.nth(parts, 1) |> str.parse_i64() + parts := str.split(array.nth(ranges, i), "-") + start := str.parse_i64(array.nth(parts, 0)) + end := str.parse_i64(array.nth(parts, 1)) for n in (start)..end+1 if part1_is_invalid_id(str.from_i64(n)) @@ -43,9 +43,9 @@ func part2[ranges: Array] : void sum := 0 for i in 0..ranges->size - parts := array.nth(ranges, i) |> str.split("-") - start := array.nth(parts, 0) |> str.parse_i64() - end := array.nth(parts, 1) |> str.parse_i64() + parts := str.split(array.nth(ranges, i), "-") + start := str.parse_i64(array.nth(parts, 0)) + end := str.parse_i64(array.nth(parts, 1)) for n in (start)..end+1 if part2_is_invalid_id(str.from_i64(n)) diff --git a/examples/puzzles/euler_13.zr b/examples/puzzles/euler_13.zr index 98b96ea..1916aa3 100644 --- a/examples/puzzles/euler_13.zr +++ b/examples/puzzles/euler_13.zr @@ -1,6 +1,4 @@ func main[] : i64 - // leaks a bit of memory but looks very cool - 37107287533 + 46376937677 + 74324986199 + 91942213363 + 23067588207 + 89261670696 + 28112879812 + 44274228917 + 47451445736 + 70386486105 + 62176457141 + 64906352462 + 92575867718 + 58203565325 + 80181199384 + 35398664372 + 86515506006 + 71693888707 + 54370070576 + 53282654108 + 36123272525 + 45876576172 + 17423706905 + 81142660418 + 51934325451 + 62467221648 + 15732444386 + 55037687525 + 18336384825 + 80386287592 + 78182833757 + 16726320100 + 48403098129 + 87086987551 + 59959406895 + 69793950679 + 41052684708 + 65378607361 + 35829035317 + 94953759765 + 88902802571 + 25267680276 + 36270218540 + 24074486908 + 91430288197 + 34413065578 + 23053081172 + 11487696932 + 63783299490 + 67720186971 + 95548255300 + 76085327132 + 37774242535 + 23701913275 + 29798860272 + 18495701454 + 38298203783 + 34829543829 + 40957953066 + 29746152185 + 41698116222 + 62467957194 + 23189706772 + 86188088225 + 11306739708 + 82959174767 + 97623331044 + 42846280183 + 55121603546 + 32238195734 + 75506164965 + 62177842752 + 32924185707 + 99518671430 + 73267460800 + 76841822524 + 97142617910 + 87783646182 + 10848802521 + 71329612474 + 62184073572 + 66627891981 + 60661826293 + 85786944089 + 66024396409 + 64913982680 + 16730939319 + 94809377245 + 78639167021 + 15368713711 + 40789923115 + 44889911501 + 41503128880 + 81234880673 + 82616570773 + 22918802058 + 77158542502 + 72107838435 + 20849603980 + 53503534226 - |> str.from_i64() - |> str.substr(0, 10) - |> io.println() + n := 37107287533 + 46376937677 + 74324986199 + 91942213363 + 23067588207 + 89261670696 + 28112879812 + 44274228917 + 47451445736 + 70386486105 + 62176457141 + 64906352462 + 92575867718 + 58203565325 + 80181199384 + 35398664372 + 86515506006 + 71693888707 + 54370070576 + 53282654108 + 36123272525 + 45876576172 + 17423706905 + 81142660418 + 51934325451 + 62467221648 + 15732444386 + 55037687525 + 18336384825 + 80386287592 + 78182833757 + 16726320100 + 48403098129 + 87086987551 + 59959406895 + 69793950679 + 41052684708 + 65378607361 + 35829035317 + 94953759765 + 88902802571 + 25267680276 + 36270218540 + 24074486908 + 91430288197 + 34413065578 + 23053081172 + 11487696932 + 63783299490 + 67720186971 + 95548255300 + 76085327132 + 37774242535 + 23701913275 + 29798860272 + 18495701454 + 38298203783 + 34829543829 + 40957953066 + 29746152185 + 41698116222 + 62467957194 + 23189706772 + 86188088225 + 11306739708 + 82959174767 + 97623331044 + 42846280183 + 55121603546 + 32238195734 + 75506164965 + 62177842752 + 32924185707 + 99518671430 + 73267460800 + 76841822524 + 97142617910 + 87783646182 + 10848802521 + 71329612474 + 62184073572 + 66627891981 + 60661826293 + 85786944089 + 66024396409 + 64913982680 + 16730939319 + 94809377245 + 78639167021 + 15368713711 + 40789923115 + 44889911501 + 41503128880 + 81234880673 + 82616570773 + 22918802058 + 77158542502 + 72107838435 + 20849603980 + 53503534226 + n_str := str.from_i64(n) + io.println(str.substr(n_str, 0, 10)) diff --git a/examples/sqlite_todo.zr b/examples/sqlite_todo.zr index ae619b0..bb998f7 100644 --- a/examples/sqlite_todo.zr +++ b/examples/sqlite_todo.zr @@ -30,7 +30,7 @@ func main[] : i64 io.println("0. Quit") io.print("\n> ") - choice := io.read_line() |> str.parse_i64() + choice := str.parse_i64(io.read_line()) if choice == 0 break @@ -46,7 +46,7 @@ func main[] : i64 io.println("============") else if choice == 2 io.print("\nEnter new task: ") - task := io.read_line() |> str.trim() + task := str.trim(io.read_line()) sqlite3_prepare_v2(db, "INSERT INTO todo(task) VALUES (?);", -1, ^stmt, 0) sqlite3_bind_text(stmt, 1, task, -1, 0) @@ -56,7 +56,7 @@ func main[] : i64 io.println("\nTask added\n") else if choice == 3 io.print("\nEnter task id: ") - id := io.read_line() |> str.parse_i64() + id := str.parse_i64(io.read_line()) sqlite3_prepare_v2(db, "DELETE FROM todo WHERE id = ?;", -1, ^stmt, 0) sqlite3_bind_int(stmt, 1, id, -1, 0) diff --git a/src/parser.rs b/src/parser.rs index 3f28b93..fdf1f6a 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -439,37 +439,7 @@ impl Parser { } fn expression(&mut self) -> Result { - self.pipe() - } - - fn pipe(&mut self) -> Result { - let mut expr = self.or_and()?; - - while self.match_token(&[TokenType::Pipe]) { - let pipe = self.previous().clone(); - let right = self.equality()?; - - match right.kind { - ExprKind::Call { - callee, - paren, - args, - } => { - let mut new_args = args; - new_args.insert(0, expr); - expr = Expr::new(ExprKind::Call { - callee, - paren, - args: new_args, - }) - } - _ => { - return error!(pipe.loc, "tried to pipe into a non-call expression"); - } - }; - } - - Ok(expr) + self.or_and() } fn or_and(&mut self) -> Result { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index a7804f9..a4f3cac 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -21,7 +21,6 @@ pub enum TokenType { BitOr, LogicalAnd, LogicalOr, - Pipe, DoubleDot, ShiftLeft, ShiftRight, @@ -202,9 +201,7 @@ impl Tokenizer { } } '|' => { - if self.match_char('>') { - self.add_token(TokenType::Pipe)? - } else if self.match_char('|') { + if self.match_char('|') { self.add_token(TokenType::LogicalOr)? } else { self.add_token(TokenType::BitOr)?