snail-lang 0.6.2__tar.gz → 0.6.3__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 (58) hide show
  1. {snail_lang-0.6.2 → snail_lang-0.6.3}/Cargo.lock +7 -7
  2. {snail_lang-0.6.2 → snail_lang-0.6.3}/PKG-INFO +1 -1
  3. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-ast/Cargo.toml +1 -1
  4. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-core/Cargo.toml +1 -1
  5. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-error/Cargo.toml +1 -1
  6. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/Cargo.toml +1 -1
  7. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/constants.rs +1 -0
  8. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/map.rs +6 -6
  9. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/Cargo.toml +1 -1
  10. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-python/Cargo.toml +1 -1
  11. {snail_lang-0.6.2 → snail_lang-0.6.3}/pyproject.toml +1 -1
  12. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/__init__.py +11 -0
  13. snail_lang-0.6.3/python/snail/runtime/lazy_file.py +41 -0
  14. {snail_lang-0.6.2 → snail_lang-0.6.3}/Cargo.toml +0 -0
  15. {snail_lang-0.6.2 → snail_lang-0.6.3}/LICENSE +0 -0
  16. {snail_lang-0.6.2 → snail_lang-0.6.3}/README.md +0 -0
  17. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-ast/README.md +0 -0
  18. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-ast/src/ast.rs +0 -0
  19. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-ast/src/awk.rs +0 -0
  20. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-ast/src/lib.rs +0 -0
  21. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-core/README.md +0 -0
  22. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-core/src/lib.rs +0 -0
  23. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-error/README.md +0 -0
  24. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-error/src/lib.rs +0 -0
  25. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/README.md +0 -0
  26. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/awk.rs +0 -0
  27. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/expr.rs +0 -0
  28. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/helpers.rs +0 -0
  29. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/lib.rs +0 -0
  30. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/operators.rs +0 -0
  31. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/program.rs +0 -0
  32. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/py_ast.rs +0 -0
  33. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-lower/src/stmt.rs +0 -0
  34. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/README.md +0 -0
  35. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/awk.rs +0 -0
  36. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/expr.rs +0 -0
  37. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/lib.rs +0 -0
  38. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/literal.rs +0 -0
  39. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/snail.pest +0 -0
  40. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/stmt.rs +0 -0
  41. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/string.rs +0 -0
  42. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/src/util.rs +0 -0
  43. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/common.rs +0 -0
  44. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/errors.rs +0 -0
  45. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/parser.rs +0 -0
  46. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/statements.rs +0 -0
  47. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/syntax_expressions.rs +0 -0
  48. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-parser/tests/syntax_strings.rs +0 -0
  49. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-python/build.rs +0 -0
  50. {snail_lang-0.6.2 → snail_lang-0.6.3}/crates/snail-python/src/lib.rs +0 -0
  51. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/__init__.py +0 -0
  52. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/cli.py +0 -0
  53. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/augmented.py +0 -0
  54. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/compact_try.py +0 -0
  55. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/lazy_text.py +0 -0
  56. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/regex.py +0 -0
  57. {snail_lang-0.6.2 → snail_lang-0.6.3}/python/snail/runtime/structured_accessor.py +0 -0
  58. {snail_lang-0.6.2 → snail_lang-0.6.3}/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.2"
488
+ version = "0.6.3"
489
489
 
490
490
  [[package]]
491
491
  name = "snail-core"
492
- version = "0.6.2"
492
+ version = "0.6.3"
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.2"
503
+ version = "0.6.3"
504
504
  dependencies = [
505
505
  "snail-ast",
506
506
  ]
507
507
 
508
508
  [[package]]
509
509
  name = "snail-lower"
510
- version = "0.6.2"
510
+ version = "0.6.3"
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.2"
519
+ version = "0.6.3"
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.2"
529
+ version = "0.6.3"
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.2"
543
+ version = "0.6.3"
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.2
3
+ Version: 0.6.3
4
4
  Requires-Dist: jmespath>=1.0.1
5
5
  Requires-Dist: maturin>=1.5 ; extra == 'dev'
6
6
  Requires-Dist: pytest ; extra == 'dev'
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-ast"
3
- version = "0.6.2"
3
+ version = "0.6.3"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-core"
3
- version = "0.6.2"
3
+ version = "0.6.3"
4
4
  edition.workspace = true
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-error"
3
- version = "0.6.2"
3
+ version = "0.6.3"
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.2"
3
+ version = "0.6.3"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -41,6 +41,7 @@ pub(crate) const SNAIL_MAP_SRC_PYVAR: &str = "__snail_src";
41
41
  pub(crate) const SNAIL_MAP_FD_PYVAR: &str = "__snail_fd";
42
42
  pub(crate) const SNAIL_MAP_TEXT_PYVAR: &str = "__snail_text";
43
43
  pub const SNAIL_LAZY_TEXT_CLASS: &str = "__SnailLazyText";
44
+ pub const SNAIL_LAZY_FILE_CLASS: &str = "__SnailLazyFile";
44
45
 
45
46
  pub(crate) fn injected_py_name(name: &str) -> Option<&'static str> {
46
47
  match name {
@@ -156,7 +156,7 @@ fn lower_map_file_loop(
156
156
  auto_print_last: bool,
157
157
  ) -> Result<PyObject, LowerError> {
158
158
  // for __snail_src in __snail_paths:
159
- // with open(__snail_src, 'r') as __snail_fd:
159
+ // with __SnailLazyFile(__snail_src, 'r') as __snail_fd:
160
160
  // __snail_text = __SnailLazyText(__snail_fd)
161
161
  // # user code
162
162
 
@@ -201,14 +201,14 @@ fn lower_map_file_loop(
201
201
  lower_block_with_auto_print(builder, &program.stmts, auto_print_last, &program.span)?;
202
202
  with_body.extend(user_code);
203
203
 
204
- // open(__snail_src, 'r')
205
- let open_call = builder
204
+ // __SnailLazyFile(__snail_src, 'r')
205
+ let lazy_file_call = builder
206
206
  .call_node(
207
207
  "Call",
208
208
  vec![
209
209
  name_expr(
210
210
  builder,
211
- "open",
211
+ SNAIL_LAZY_FILE_CLASS,
212
212
  span,
213
213
  builder.load_ctx().map_err(py_err_to_lower)?,
214
214
  )?,
@@ -231,12 +231,12 @@ fn lower_map_file_loop(
231
231
  )
232
232
  .map_err(py_err_to_lower)?;
233
233
 
234
- // with open(...) as __snail_fd:
234
+ // with __SnailLazyFile(...) as __snail_fd:
235
235
  let with_item = builder
236
236
  .call_node_no_loc(
237
237
  "withitem",
238
238
  vec![
239
- open_call,
239
+ lazy_file_call,
240
240
  name_expr(
241
241
  builder,
242
242
  SNAIL_MAP_FD_PYVAR,
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-parser"
3
- version = "0.6.2"
3
+ version = "0.6.3"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snail-python"
3
- version = "0.6.2"
3
+ version = "0.6.3"
4
4
  edition.workspace = true
5
5
  build = "build.rs"
6
6
 
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "snail-lang"
7
- version = "0.6.2"
7
+ version = "0.6.3"
8
8
  description = "Snail programming language interpreter"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -42,6 +42,7 @@ _subprocess_status = None
42
42
  _jmespath_query = None
43
43
  _js = None
44
44
  _lazy_text_class = None
45
+ _lazy_file_class = None
45
46
  _incr_attr = None
46
47
  _incr_index = None
47
48
  _aug_attr = None
@@ -120,6 +121,15 @@ def _get_lazy_text_class():
120
121
  return _lazy_text_class
121
122
 
122
123
 
124
+ def _get_lazy_file_class():
125
+ global _lazy_file_class
126
+ if _lazy_file_class is None:
127
+ from .lazy_file import LazyFile
128
+
129
+ _lazy_file_class = LazyFile
130
+ return _lazy_file_class
131
+
132
+
123
133
  def _get_incr_attr():
124
134
  global _incr_attr
125
135
  if _incr_attr is None:
@@ -236,3 +246,4 @@ def install_helpers(globals_dict: dict) -> None:
236
246
  globals_dict["__snail_aug_index"] = _lazy_aug_index
237
247
  globals_dict["js"] = _lazy_js
238
248
  globals_dict["__SnailLazyText"] = _get_lazy_text_class()
249
+ globals_dict["__SnailLazyFile"] = _get_lazy_file_class()
@@ -0,0 +1,41 @@
1
+ """Lazy file opener for map mode."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class LazyFile:
7
+ """Context manager that opens the file on first access."""
8
+
9
+ __slots__ = ("_path", "_mode", "_kwargs", "_fd", "_closed")
10
+
11
+ def __init__(self, path, mode="r", **kwargs):
12
+ self._path = path
13
+ self._mode = mode
14
+ self._kwargs = kwargs
15
+ self._fd = None
16
+ self._closed = False
17
+
18
+ def _ensure_open(self):
19
+ if self._closed:
20
+ raise ValueError("I/O operation on closed file.")
21
+ if self._fd is None:
22
+ self._fd = open(self._path, self._mode, **self._kwargs)
23
+ return self._fd
24
+
25
+ def __enter__(self):
26
+ return self
27
+
28
+ def __exit__(self, exc_type, exc, tb):
29
+ self._closed = True
30
+ if self._fd is not None:
31
+ self._fd.close()
32
+ return False
33
+
34
+ def __getattr__(self, name):
35
+ return getattr(self._ensure_open(), name)
36
+
37
+ def __iter__(self):
38
+ return iter(self._ensure_open())
39
+
40
+ def __next__(self):
41
+ return next(self._ensure_open())
File without changes
File without changes
File without changes