snail-lang 0.6.0__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. {snail_lang-0.6.0 → snail_lang-0.6.1}/Cargo.lock +7 -7
  2. {snail_lang-0.6.0 → snail_lang-0.6.1}/PKG-INFO +25 -3
  3. {snail_lang-0.6.0 → snail_lang-0.6.1}/README.md +24 -2
  4. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-ast/Cargo.toml +1 -1
  5. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-ast/src/ast.rs +33 -0
  6. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-core/Cargo.toml +1 -1
  7. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-core/src/lib.rs +34 -0
  8. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-error/Cargo.toml +1 -1
  9. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/Cargo.toml +1 -1
  10. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/constants.rs +5 -0
  11. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/expr.rs +349 -1
  12. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/lib.rs +3 -1
  13. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/map.rs +49 -0
  14. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/operators.rs +29 -1
  15. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/Cargo.toml +1 -1
  16. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/expr.rs +184 -24
  17. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/lib.rs +14 -0
  18. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/snail.pest +16 -7
  19. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/stmt.rs +4 -1
  20. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/string.rs +42 -1
  21. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/util.rs +3 -0
  22. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/parser.rs +221 -1
  23. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-python/Cargo.toml +1 -1
  24. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-python/src/lib.rs +89 -7
  25. {snail_lang-0.6.0 → snail_lang-0.6.1}/pyproject.toml +1 -1
  26. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/__init__.py +10 -2
  27. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/cli.py +33 -5
  28. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/__init__.py +60 -0
  29. snail_lang-0.6.1/python/snail/runtime/augmented.py +49 -0
  30. {snail_lang-0.6.0 → snail_lang-0.6.1}/Cargo.toml +0 -0
  31. {snail_lang-0.6.0 → snail_lang-0.6.1}/LICENSE +0 -0
  32. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-ast/README.md +0 -0
  33. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-ast/src/awk.rs +0 -0
  34. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-ast/src/lib.rs +0 -0
  35. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-core/README.md +0 -0
  36. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-error/README.md +0 -0
  37. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-error/src/lib.rs +0 -0
  38. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/README.md +0 -0
  39. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/awk.rs +0 -0
  40. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/helpers.rs +0 -0
  41. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/program.rs +0 -0
  42. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/py_ast.rs +0 -0
  43. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-lower/src/stmt.rs +0 -0
  44. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/README.md +0 -0
  45. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/awk.rs +0 -0
  46. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/src/literal.rs +0 -0
  47. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/common.rs +0 -0
  48. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/errors.rs +0 -0
  49. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/statements.rs +0 -0
  50. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/syntax_expressions.rs +0 -0
  51. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-parser/tests/syntax_strings.rs +0 -0
  52. {snail_lang-0.6.0 → snail_lang-0.6.1}/crates/snail-python/build.rs +0 -0
  53. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/compact_try.py +0 -0
  54. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/lazy_text.py +0 -0
  55. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/regex.py +0 -0
  56. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/structured_accessor.py +0 -0
  57. {snail_lang-0.6.0 → snail_lang-0.6.1}/python/snail/runtime/subprocess.py +0 -0
@@ -485,11 +485,11 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
485
485
 
486
486
  [[package]]
487
487
  name = "snail-ast"
488
- version = "0.6.0"
488
+ version = "0.6.1"
489
489
 
490
490
  [[package]]
491
491
  name = "snail-core"
492
- version = "0.6.0"
492
+ version = "0.6.1"
493
493
  dependencies = [
494
494
  "pyo3",
495
495
  "snail-ast",
@@ -500,14 +500,14 @@ dependencies = [
500
500
 
501
501
  [[package]]
502
502
  name = "snail-error"
503
- version = "0.6.0"
503
+ version = "0.6.1"
504
504
  dependencies = [
505
505
  "snail-ast",
506
506
  ]
507
507
 
508
508
  [[package]]
509
509
  name = "snail-lower"
510
- version = "0.6.0"
510
+ version = "0.6.1"
511
511
  dependencies = [
512
512
  "pyo3",
513
513
  "snail-ast",
@@ -516,7 +516,7 @@ dependencies = [
516
516
 
517
517
  [[package]]
518
518
  name = "snail-parser"
519
- version = "0.6.0"
519
+ version = "0.6.1"
520
520
  dependencies = [
521
521
  "pest",
522
522
  "pest_derive",
@@ -526,7 +526,7 @@ dependencies = [
526
526
 
527
527
  [[package]]
528
528
  name = "snail-proptest"
529
- version = "0.6.0"
529
+ version = "0.6.1"
530
530
  dependencies = [
531
531
  "proptest",
532
532
  "pyo3",
@@ -540,7 +540,7 @@ dependencies = [
540
540
 
541
541
  [[package]]
542
542
  name = "snail-python"
543
- version = "0.6.0"
543
+ version = "0.6.1"
544
544
  dependencies = [
545
545
  "pyo3",
546
546
  "snail-core",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snail-lang
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Requires-Dist: jmespath>=1.0.1
5
5
  Requires-Dist: maturin>=1.5 ; extra == 'dev'
6
6
  Requires-Dist: pytest ; extra == 'dev'
@@ -13,11 +13,10 @@ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
13
13
  <p align="center">
14
14
  <img src="logo.png" alt="Snail logo" width="200">
15
15
  </p>
16
- <p align="center"><em>What do you get when you shove a snake in a shell?</em></p>
17
16
 
18
17
  <h1 align="center">Snail</h1>
19
18
 
20
- **Snail** is a programming language that compiles to Python, combining Python's familiarity and extensive libraries with Perl/awk-inspired syntax for quick scripts and one-liners.
19
+ **Snail** is a programming language that compiles to Python, combining Python's familiarity and extensive libraries with Perl/awk-inspired syntax for quick scripts and one-liners. Its what you get when you shove a snake in a shell.
21
20
 
22
21
  ## AI Slop!
23
22
 
@@ -79,6 +78,28 @@ Begin/end blocks use CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and tear
79
78
  echo -e "5\n4\n3\n2\n1" | snail --awk --begin 'total = 0' --end 'print("Sum:", total)' '/^[0-9]+/ { total = total + int($1) }'
80
79
  ```
81
80
 
81
+ ### Map Mode
82
+
83
+ Process files one at a time instead of line-by-line:
84
+
85
+ ```snail-map
86
+ print("File:", $src)
87
+ print("Size:", len($text), "bytes")
88
+ ```
89
+
90
+ **Built-in variables:**
91
+
92
+ | Variable | Description |
93
+ |----------|-------------|
94
+ | `$src` | Current file path |
95
+ | `$fd` | Open file handle for the current file |
96
+ | `$text` | Lazy text view of the current file contents |
97
+
98
+ Begin/end blocks use CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown:
99
+ ```bash
100
+ snail --map --begin "print('start')" --end "print('done')" "print($src)" *.txt
101
+ ```
102
+
82
103
  ### Compact Error Handling
83
104
 
84
105
  The `?` operator makes error handling terse yet expressive:
@@ -238,6 +259,7 @@ Documentation is WIP
238
259
  - **[Language Reference](docs/REFERENCE.md)** — Complete syntax and semantics
239
260
  - **[examples/all_syntax.snail](examples/all_syntax.snail)** — Every feature in one file
240
261
  - **[examples/awk.snail](examples/awk.snail)** — Awk mode examples
262
+ - **[examples/map.snail](examples/map.snail)** — Map mode examples
241
263
 
242
264
  ## 🔌 Editor Support
243
265
 
@@ -1,11 +1,10 @@
1
1
  <p align="center">
2
2
  <img src="logo.png" alt="Snail logo" width="200">
3
3
  </p>
4
- <p align="center"><em>What do you get when you shove a snake in a shell?</em></p>
5
4
 
6
5
  <h1 align="center">Snail</h1>
7
6
 
8
- **Snail** is a programming language that compiles to Python, combining Python's familiarity and extensive libraries with Perl/awk-inspired syntax for quick scripts and one-liners.
7
+ **Snail** is a programming language that compiles to Python, combining Python's familiarity and extensive libraries with Perl/awk-inspired syntax for quick scripts and one-liners. Its what you get when you shove a snake in a shell.
9
8
 
10
9
  ## AI Slop!
11
10
 
@@ -67,6 +66,28 @@ Begin/end blocks use CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and tear
67
66
  echo -e "5\n4\n3\n2\n1" | snail --awk --begin 'total = 0' --end 'print("Sum:", total)' '/^[0-9]+/ { total = total + int($1) }'
68
67
  ```
69
68
 
69
+ ### Map Mode
70
+
71
+ Process files one at a time instead of line-by-line:
72
+
73
+ ```snail-map
74
+ print("File:", $src)
75
+ print("Size:", len($text), "bytes")
76
+ ```
77
+
78
+ **Built-in variables:**
79
+
80
+ | Variable | Description |
81
+ |----------|-------------|
82
+ | `$src` | Current file path |
83
+ | `$fd` | Open file handle for the current file |
84
+ | `$text` | Lazy text view of the current file contents |
85
+
86
+ Begin/end blocks use CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown:
87
+ ```bash
88
+ snail --map --begin "print('start')" --end "print('done')" "print($src)" *.txt
89
+ ```
90
+
70
91
  ### Compact Error Handling
71
92
 
72
93
  The `?` operator makes error handling terse yet expressive:
@@ -226,6 +247,7 @@ Documentation is WIP
226
247
  - **[Language Reference](docs/REFERENCE.md)** — Complete syntax and semantics
227
248
  - **[examples/all_syntax.snail](examples/all_syntax.snail)** — Every feature in one file
228
249
  - **[examples/awk.snail](examples/awk.snail)** — Awk mode examples
250
+ - **[examples/map.snail](examples/map.snail)** — Map mode examples
229
251
 
230
252
  ## 🔌 Editor Support
231
253
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-ast"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -216,6 +216,22 @@ pub enum Expr {
216
216
  right: Box<Expr>,
217
217
  span: SourceSpan,
218
218
  },
219
+ AugAssign {
220
+ target: Box<AssignTarget>,
221
+ op: AugAssignOp,
222
+ value: Box<Expr>,
223
+ span: SourceSpan,
224
+ },
225
+ PrefixIncr {
226
+ op: IncrOp,
227
+ target: Box<AssignTarget>,
228
+ span: SourceSpan,
229
+ },
230
+ PostfixIncr {
231
+ op: IncrOp,
232
+ target: Box<AssignTarget>,
233
+ span: SourceSpan,
234
+ },
219
235
  Compare {
220
236
  left: Box<Expr>,
221
237
  ops: Vec<CompareOp>,
@@ -403,6 +419,23 @@ pub enum BinaryOp {
403
419
  Pipeline,
404
420
  }
405
421
 
422
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
423
+ pub enum AugAssignOp {
424
+ Add,
425
+ Sub,
426
+ Mul,
427
+ Div,
428
+ FloorDiv,
429
+ Mod,
430
+ Pow,
431
+ }
432
+
433
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
434
+ pub enum IncrOp {
435
+ Increment,
436
+ Decrement,
437
+ }
438
+
406
439
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
407
440
  pub enum CompareOp {
408
441
  Eq,
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-core"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  edition.workspace = true
5
5
  readme = "README.md"
6
6
 
@@ -53,3 +53,37 @@ pub fn compile_awk_source_with_begin_end(
53
53
  let module = lower_awk_program_with_auto_print(py, &program, auto_print_last)?;
54
54
  Ok(module)
55
55
  }
56
+
57
+ /// Compile a map program with separate begin and end code blocks.
58
+ /// Each begin/end source is parsed as a map program.
59
+ pub fn compile_map_source_with_begin_end(
60
+ py: Python<'_>,
61
+ main_source: &str,
62
+ begin_sources: &[&str],
63
+ end_sources: &[&str],
64
+ auto_print_last: bool,
65
+ ) -> Result<PyObject, SnailError> {
66
+ let program = parse_map_program(main_source)?;
67
+ let mut begin_blocks = Vec::new();
68
+ for source in begin_sources {
69
+ let begin_program = parse_map_program(source)?;
70
+ if !begin_program.stmts.is_empty() {
71
+ begin_blocks.push(begin_program.stmts);
72
+ }
73
+ }
74
+ let mut end_blocks = Vec::new();
75
+ for source in end_sources {
76
+ let end_program = parse_map_program(source)?;
77
+ if !end_program.stmts.is_empty() {
78
+ end_blocks.push(end_program.stmts);
79
+ }
80
+ }
81
+ let module = lower_map_program_with_begin_end(
82
+ py,
83
+ &program,
84
+ &begin_blocks,
85
+ &end_blocks,
86
+ auto_print_last,
87
+ )?;
88
+ Ok(module)
89
+ }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-error"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-lower"
3
- version = "0.6.0"
3
+ version = "0.6.1"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -9,11 +9,16 @@ pub const SNAIL_JMESPATH_QUERY: &str = "__snail_jmespath_query";
9
9
  pub const SNAIL_PARTIAL_HELPER: &str = "__snail_partial";
10
10
  pub const SNAIL_CONTAINS_HELPER: &str = "__snail_contains__";
11
11
  pub const SNAIL_CONTAINS_NOT_HELPER: &str = "__snail_contains_not__";
12
+ pub const SNAIL_INCR_ATTR: &str = "__snail_incr_attr";
13
+ pub const SNAIL_INCR_INDEX: &str = "__snail_incr_index";
14
+ pub const SNAIL_AUG_ATTR: &str = "__snail_aug_attr";
15
+ pub const SNAIL_AUG_INDEX: &str = "__snail_aug_index";
12
16
  pub(crate) const SNAIL_LET_VALUE: &str = "__snail_let_value";
13
17
  pub(crate) const SNAIL_LET_OK: &str = "__snail_let_ok";
14
18
  pub(crate) const SNAIL_LET_KEEP: &str = "__snail_let_keep";
15
19
  pub(crate) const SNAIL_COMPARE_LEFT: &str = "__snail_compare_left";
16
20
  pub(crate) const SNAIL_COMPARE_RIGHT: &str = "__snail_compare_right";
21
+ pub(crate) const SNAIL_INCR_TMP: &str = "__snail_incr_tmp";
17
22
 
18
23
  // Awk-related constants (public within crate)
19
24
  pub(crate) const SNAIL_AWK_NR: &str = "$n";