snail-lang 0.6.0__tar.gz → 0.6.2__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.
- {snail_lang-0.6.0 → snail_lang-0.6.2}/Cargo.lock +7 -7
- {snail_lang-0.6.0 → snail_lang-0.6.2}/PKG-INFO +38 -4
- {snail_lang-0.6.0 → snail_lang-0.6.2}/README.md +37 -3
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-ast/Cargo.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-ast/src/ast.rs +33 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-core/Cargo.toml +1 -1
- snail_lang-0.6.2/crates/snail-core/src/lib.rs +101 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-error/Cargo.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/Cargo.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/constants.rs +5 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/expr.rs +349 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/lib.rs +3 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/map.rs +49 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/operators.rs +29 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/Cargo.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/expr.rs +184 -24
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/lib.rs +160 -20
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/snail.pest +28 -8
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/stmt.rs +4 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/string.rs +42 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/util.rs +3 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/errors.rs +39 -14
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/parser.rs +221 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-python/Cargo.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-python/src/lib.rs +97 -8
- {snail_lang-0.6.0 → snail_lang-0.6.2}/pyproject.toml +1 -1
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/__init__.py +10 -2
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/cli.py +40 -12
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/runtime/__init__.py +60 -0
- snail_lang-0.6.2/python/snail/runtime/augmented.py +49 -0
- snail_lang-0.6.0/crates/snail-core/src/lib.rs +0 -55
- {snail_lang-0.6.0 → snail_lang-0.6.2}/Cargo.toml +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/LICENSE +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-ast/README.md +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-ast/src/awk.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-ast/src/lib.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-core/README.md +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-error/README.md +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-error/src/lib.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/README.md +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/awk.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/helpers.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/program.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/py_ast.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-lower/src/stmt.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/README.md +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/awk.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/src/literal.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/common.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/statements.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/syntax_expressions.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-parser/tests/syntax_strings.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/crates/snail-python/build.rs +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/runtime/compact_try.py +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/runtime/lazy_text.py +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/runtime/regex.py +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/python/snail/runtime/structured_accessor.py +0 -0
- {snail_lang-0.6.0 → snail_lang-0.6.2}/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.
|
|
488
|
+
version = "0.6.2"
|
|
489
489
|
|
|
490
490
|
[[package]]
|
|
491
491
|
name = "snail-core"
|
|
492
|
-
version = "0.6.
|
|
492
|
+
version = "0.6.2"
|
|
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.
|
|
503
|
+
version = "0.6.2"
|
|
504
504
|
dependencies = [
|
|
505
505
|
"snail-ast",
|
|
506
506
|
]
|
|
507
507
|
|
|
508
508
|
[[package]]
|
|
509
509
|
name = "snail-lower"
|
|
510
|
-
version = "0.6.
|
|
510
|
+
version = "0.6.2"
|
|
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.
|
|
519
|
+
version = "0.6.2"
|
|
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.
|
|
529
|
+
version = "0.6.2"
|
|
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.
|
|
543
|
+
version = "0.6.2"
|
|
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.
|
|
3
|
+
Version: 0.6.2
|
|
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
|
|
|
@@ -58,8 +57,10 @@ semicolons are optional. You can separate statements with newlines.
|
|
|
58
57
|
Process files line-by-line with familiar awk semantics:
|
|
59
58
|
|
|
60
59
|
```snail-awk("hello world\nfoo bar\n")
|
|
60
|
+
BEGIN { print("start") }
|
|
61
61
|
/hello/ { print("matched:", $0) }
|
|
62
62
|
{ print($1, "->", $2) }
|
|
63
|
+
END { print("done") }
|
|
63
64
|
```
|
|
64
65
|
|
|
65
66
|
**Built-in variables:**
|
|
@@ -74,11 +75,43 @@ Process files line-by-line with familiar awk semantics:
|
|
|
74
75
|
| `$p` | Current file path |
|
|
75
76
|
| `$m` | Last regex match object |
|
|
76
77
|
|
|
77
|
-
Begin/end blocks
|
|
78
|
+
Begin/end blocks can live in the source file (`BEGIN { ... }` / `END { ... }`) or be supplied
|
|
79
|
+
via CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown. CLI BEGIN blocks run
|
|
80
|
+
before in-file BEGIN blocks; CLI END blocks run after in-file END blocks.
|
|
81
|
+
`BEGIN` and `END` are reserved keywords in all modes.
|
|
82
|
+
BEGIN/END blocks are regular Snail blocks, so awk/map-only `$` variables are not available inside them.
|
|
78
83
|
```bash
|
|
79
84
|
echo -e "5\n4\n3\n2\n1" | snail --awk --begin 'total = 0' --end 'print("Sum:", total)' '/^[0-9]+/ { total = total + int($1) }'
|
|
80
85
|
```
|
|
81
86
|
|
|
87
|
+
### Map Mode
|
|
88
|
+
|
|
89
|
+
Process files one at a time instead of line-by-line:
|
|
90
|
+
|
|
91
|
+
```snail-map
|
|
92
|
+
BEGIN { print("start") }
|
|
93
|
+
print("File:", $src)
|
|
94
|
+
print("Size:", len($text), "bytes")
|
|
95
|
+
END { print("done") }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Built-in variables:**
|
|
99
|
+
|
|
100
|
+
| Variable | Description |
|
|
101
|
+
|----------|-------------|
|
|
102
|
+
| `$src` | Current file path |
|
|
103
|
+
| `$fd` | Open file handle for the current file |
|
|
104
|
+
| `$text` | Lazy text view of the current file contents |
|
|
105
|
+
|
|
106
|
+
Begin/end blocks can live in the source file (`BEGIN { ... }` / `END { ... }`) or be supplied
|
|
107
|
+
via CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown. CLI BEGIN blocks run
|
|
108
|
+
before in-file BEGIN blocks; CLI END blocks run after in-file END blocks.
|
|
109
|
+
BEGIN/END blocks are regular Snail blocks, so awk/map-only `$` variables are not available inside them.
|
|
110
|
+
`BEGIN` and `END` are reserved keywords in all modes.
|
|
111
|
+
```bash
|
|
112
|
+
snail --map --begin "print('start')" --end "print('done')" "print($src)" *.txt
|
|
113
|
+
```
|
|
114
|
+
|
|
82
115
|
### Compact Error Handling
|
|
83
116
|
|
|
84
117
|
The `?` operator makes error handling terse yet expressive:
|
|
@@ -238,6 +271,7 @@ Documentation is WIP
|
|
|
238
271
|
- **[Language Reference](docs/REFERENCE.md)** — Complete syntax and semantics
|
|
239
272
|
- **[examples/all_syntax.snail](examples/all_syntax.snail)** — Every feature in one file
|
|
240
273
|
- **[examples/awk.snail](examples/awk.snail)** — Awk mode examples
|
|
274
|
+
- **[examples/map.snail](examples/map.snail)** — Map mode examples
|
|
241
275
|
|
|
242
276
|
## 🔌 Editor Support
|
|
243
277
|
|
|
@@ -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
|
|
|
@@ -46,8 +45,10 @@ semicolons are optional. You can separate statements with newlines.
|
|
|
46
45
|
Process files line-by-line with familiar awk semantics:
|
|
47
46
|
|
|
48
47
|
```snail-awk("hello world\nfoo bar\n")
|
|
48
|
+
BEGIN { print("start") }
|
|
49
49
|
/hello/ { print("matched:", $0) }
|
|
50
50
|
{ print($1, "->", $2) }
|
|
51
|
+
END { print("done") }
|
|
51
52
|
```
|
|
52
53
|
|
|
53
54
|
**Built-in variables:**
|
|
@@ -62,11 +63,43 @@ Process files line-by-line with familiar awk semantics:
|
|
|
62
63
|
| `$p` | Current file path |
|
|
63
64
|
| `$m` | Last regex match object |
|
|
64
65
|
|
|
65
|
-
Begin/end blocks
|
|
66
|
+
Begin/end blocks can live in the source file (`BEGIN { ... }` / `END { ... }`) or be supplied
|
|
67
|
+
via CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown. CLI BEGIN blocks run
|
|
68
|
+
before in-file BEGIN blocks; CLI END blocks run after in-file END blocks.
|
|
69
|
+
`BEGIN` and `END` are reserved keywords in all modes.
|
|
70
|
+
BEGIN/END blocks are regular Snail blocks, so awk/map-only `$` variables are not available inside them.
|
|
66
71
|
```bash
|
|
67
72
|
echo -e "5\n4\n3\n2\n1" | snail --awk --begin 'total = 0' --end 'print("Sum:", total)' '/^[0-9]+/ { total = total + int($1) }'
|
|
68
73
|
```
|
|
69
74
|
|
|
75
|
+
### Map Mode
|
|
76
|
+
|
|
77
|
+
Process files one at a time instead of line-by-line:
|
|
78
|
+
|
|
79
|
+
```snail-map
|
|
80
|
+
BEGIN { print("start") }
|
|
81
|
+
print("File:", $src)
|
|
82
|
+
print("Size:", len($text), "bytes")
|
|
83
|
+
END { print("done") }
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Built-in variables:**
|
|
87
|
+
|
|
88
|
+
| Variable | Description |
|
|
89
|
+
|----------|-------------|
|
|
90
|
+
| `$src` | Current file path |
|
|
91
|
+
| `$fd` | Open file handle for the current file |
|
|
92
|
+
| `$text` | Lazy text view of the current file contents |
|
|
93
|
+
|
|
94
|
+
Begin/end blocks can live in the source file (`BEGIN { ... }` / `END { ... }`) or be supplied
|
|
95
|
+
via CLI flags (`-b`/`--begin`, `-e`/`--end`) for setup and teardown. CLI BEGIN blocks run
|
|
96
|
+
before in-file BEGIN blocks; CLI END blocks run after in-file END blocks.
|
|
97
|
+
BEGIN/END blocks are regular Snail blocks, so awk/map-only `$` variables are not available inside them.
|
|
98
|
+
`BEGIN` and `END` are reserved keywords in all modes.
|
|
99
|
+
```bash
|
|
100
|
+
snail --map --begin "print('start')" --end "print('done')" "print($src)" *.txt
|
|
101
|
+
```
|
|
102
|
+
|
|
70
103
|
### Compact Error Handling
|
|
71
104
|
|
|
72
105
|
The `?` operator makes error handling terse yet expressive:
|
|
@@ -226,6 +259,7 @@ Documentation is WIP
|
|
|
226
259
|
- **[Language Reference](docs/REFERENCE.md)** — Complete syntax and semantics
|
|
227
260
|
- **[examples/all_syntax.snail](examples/all_syntax.snail)** — Every feature in one file
|
|
228
261
|
- **[examples/awk.snail](examples/awk.snail)** — Awk mode examples
|
|
262
|
+
- **[examples/map.snail](examples/map.snail)** — Map mode examples
|
|
229
263
|
|
|
230
264
|
## 🔌 Editor Support
|
|
231
265
|
|
|
@@ -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,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
use pyo3::prelude::*;
|
|
2
|
+
|
|
3
|
+
// Re-export all workspace crates for unified API
|
|
4
|
+
pub use snail_ast::*;
|
|
5
|
+
pub use snail_error::*;
|
|
6
|
+
pub use snail_lower::*;
|
|
7
|
+
pub use snail_parser::*;
|
|
8
|
+
|
|
9
|
+
/// Compilation API
|
|
10
|
+
pub fn compile_snail_source(
|
|
11
|
+
py: Python<'_>,
|
|
12
|
+
source: &str,
|
|
13
|
+
mode: CompileMode,
|
|
14
|
+
) -> Result<PyObject, SnailError> {
|
|
15
|
+
compile_snail_source_with_auto_print(py, source, mode, false)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
pub fn compile_snail_source_with_auto_print(
|
|
19
|
+
py: Python<'_>,
|
|
20
|
+
source: &str,
|
|
21
|
+
mode: CompileMode,
|
|
22
|
+
auto_print_last: bool,
|
|
23
|
+
) -> Result<PyObject, SnailError> {
|
|
24
|
+
match mode {
|
|
25
|
+
CompileMode::Snail => {
|
|
26
|
+
let program = parse_program(source)?;
|
|
27
|
+
let module = lower_program_with_auto_print(py, &program, auto_print_last)?;
|
|
28
|
+
Ok(module)
|
|
29
|
+
}
|
|
30
|
+
CompileMode::Awk => {
|
|
31
|
+
let program = parse_awk_program(source)?;
|
|
32
|
+
let module = lower_awk_program_with_auto_print(py, &program, auto_print_last)?;
|
|
33
|
+
Ok(module)
|
|
34
|
+
}
|
|
35
|
+
CompileMode::Map => {
|
|
36
|
+
let (program, begin_blocks, end_blocks) = parse_map_program_with_begin_end(source)?;
|
|
37
|
+
let module = lower_map_program_with_begin_end(
|
|
38
|
+
py,
|
|
39
|
+
&program,
|
|
40
|
+
&begin_blocks,
|
|
41
|
+
&end_blocks,
|
|
42
|
+
auto_print_last,
|
|
43
|
+
)?;
|
|
44
|
+
Ok(module)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// Compile an awk program with separate begin and end code blocks.
|
|
50
|
+
/// In-file BEGIN/END blocks are merged with CLI blocks so CLI BEGIN runs first
|
|
51
|
+
/// and CLI END runs last. CLI blocks are parsed as regular Snail programs.
|
|
52
|
+
pub fn compile_awk_source_with_begin_end(
|
|
53
|
+
py: Python<'_>,
|
|
54
|
+
main_source: &str,
|
|
55
|
+
begin_sources: &[&str],
|
|
56
|
+
end_sources: &[&str],
|
|
57
|
+
auto_print_last: bool,
|
|
58
|
+
) -> Result<PyObject, SnailError> {
|
|
59
|
+
let program = parse_awk_program_with_begin_end(main_source, begin_sources, end_sources)?;
|
|
60
|
+
let module = lower_awk_program_with_auto_print(py, &program, auto_print_last)?;
|
|
61
|
+
Ok(module)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Compile a map program with separate begin and end code blocks.
|
|
65
|
+
/// In-file BEGIN/END blocks are merged with CLI blocks so CLI BEGIN runs first
|
|
66
|
+
/// and CLI END runs last. CLI blocks are parsed as regular Snail programs.
|
|
67
|
+
pub fn compile_map_source_with_begin_end(
|
|
68
|
+
py: Python<'_>,
|
|
69
|
+
main_source: &str,
|
|
70
|
+
begin_sources: &[&str],
|
|
71
|
+
end_sources: &[&str],
|
|
72
|
+
auto_print_last: bool,
|
|
73
|
+
) -> Result<PyObject, SnailError> {
|
|
74
|
+
let (program, mut begin_blocks, mut end_blocks) =
|
|
75
|
+
parse_map_program_with_begin_end(main_source)?;
|
|
76
|
+
|
|
77
|
+
let mut cli_begin_blocks = Vec::new();
|
|
78
|
+
for source in begin_sources {
|
|
79
|
+
let begin_program = parse_program(source)?;
|
|
80
|
+
if !begin_program.stmts.is_empty() {
|
|
81
|
+
cli_begin_blocks.push(begin_program.stmts);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
cli_begin_blocks.extend(begin_blocks);
|
|
85
|
+
begin_blocks = cli_begin_blocks;
|
|
86
|
+
|
|
87
|
+
for source in end_sources {
|
|
88
|
+
let end_program = parse_program(source)?;
|
|
89
|
+
if !end_program.stmts.is_empty() {
|
|
90
|
+
end_blocks.push(end_program.stmts);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
let module = lower_map_program_with_begin_end(
|
|
94
|
+
py,
|
|
95
|
+
&program,
|
|
96
|
+
&begin_blocks,
|
|
97
|
+
&end_blocks,
|
|
98
|
+
auto_print_last,
|
|
99
|
+
)?;
|
|
100
|
+
Ok(module)
|
|
101
|
+
}
|
|
@@ -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";
|