koatl 0.1.36__tar.gz → 0.1.38__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 (131) hide show
  1. {koatl-0.1.36 → koatl-0.1.38}/Cargo.lock +1 -1
  2. {koatl-0.1.36 → koatl-0.1.38}/PKG-INFO +1 -1
  3. {koatl-0.1.36 → koatl-0.1.38}/koatl/Cargo.toml +1 -1
  4. koatl-0.1.38/koatl/python/koatl/prelude/__init__.tl +61 -0
  5. {koatl-0.1.36 → koatl-0.1.38/koatl}/python/koatl/runtime/__init__.py +0 -3
  6. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/runtime/virtual.py +4 -4
  7. koatl-0.1.38/koatl/python/koatl/std/alg/__init__.tl +5 -0
  8. {koatl-0.1.36/koatl/python/koatl/prelude/functional → koatl-0.1.38/koatl/python/koatl/std/alg}/async.tl +1 -1
  9. koatl-0.1.36/koatl/python/koatl/prelude/functional/algebra.tl → koatl-0.1.38/koatl/python/koatl/std/alg/base.tl +2 -0
  10. {koatl-0.1.36/python/koatl/prelude/functional → koatl-0.1.38/koatl/python/koatl/std/alg}/env.tl +1 -1
  11. {koatl-0.1.36/python/koatl/prelude/functional → koatl-0.1.38/koatl/python/koatl/std/alg}/memo.tl +2 -5
  12. {koatl-0.1.36/koatl/python/koatl/prelude/functional → koatl-0.1.38/koatl/python/koatl/std/alg}/result.tl +2 -24
  13. koatl-0.1.38/koatl/python/koatl/std/data/__init__.tl +1 -0
  14. {koatl-0.1.36/python/koatl/prelude/functional → koatl-0.1.38/koatl/python/koatl/std/data}/list.tl +2 -5
  15. koatl-0.1.38/koatl/python/koatl/std/io.tl +3 -0
  16. koatl-0.1.36/python/koatl/prelude/iterable.tl → koatl-0.1.38/koatl/python/koatl/std/iter.tl +4 -4
  17. koatl-0.1.38/koatl/python/koatl/std/lazy_module.tl +33 -0
  18. koatl-0.1.36/koatl/python/koatl/prelude/regex.tl → koatl-0.1.38/koatl/python/koatl/std/re.tl +3 -15
  19. koatl-0.1.36/koatl/python/koatl/runtime/classes.py → koatl-0.1.38/koatl/python/koatl/std/trait.py +1 -1
  20. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/src/ast.rs +7 -8
  21. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/src/lexer.rs +176 -94
  22. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/src/parser.rs +99 -60
  23. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/src/util.rs +5 -33
  24. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/lib.rs +12 -1
  25. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/py/emit.rs +3 -3
  26. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/resolve_scopes.rs +72 -22
  27. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/transform.rs +101 -36
  28. koatl-0.1.38/python/koatl/prelude/__init__.tl +61 -0
  29. {koatl-0.1.36/koatl → koatl-0.1.38}/python/koatl/runtime/__init__.py +0 -3
  30. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/runtime/virtual.py +4 -4
  31. koatl-0.1.38/python/koatl/std/alg/__init__.tl +5 -0
  32. {koatl-0.1.36/python/koatl/prelude/functional → koatl-0.1.38/python/koatl/std/alg}/async.tl +1 -1
  33. koatl-0.1.36/python/koatl/prelude/functional/algebra.tl → koatl-0.1.38/python/koatl/std/alg/base.tl +2 -0
  34. {koatl-0.1.36/koatl/python/koatl/prelude/functional → koatl-0.1.38/python/koatl/std/alg}/env.tl +1 -1
  35. {koatl-0.1.36/koatl/python/koatl/prelude/functional → koatl-0.1.38/python/koatl/std/alg}/memo.tl +2 -5
  36. {koatl-0.1.36/python/koatl/prelude/functional → koatl-0.1.38/python/koatl/std/alg}/result.tl +2 -24
  37. koatl-0.1.38/python/koatl/std/data/__init__.tl +1 -0
  38. {koatl-0.1.36/koatl/python/koatl/prelude/functional → koatl-0.1.38/python/koatl/std/data}/list.tl +2 -5
  39. koatl-0.1.38/python/koatl/std/io.tl +3 -0
  40. koatl-0.1.36/koatl/python/koatl/prelude/iterable.tl → koatl-0.1.38/python/koatl/std/iter.tl +4 -4
  41. koatl-0.1.38/python/koatl/std/lazy_module.tl +33 -0
  42. koatl-0.1.36/python/koatl/prelude/regex.tl → koatl-0.1.38/python/koatl/std/re.tl +3 -15
  43. koatl-0.1.36/python/koatl/runtime/classes.py → koatl-0.1.38/python/koatl/std/trait.py +1 -1
  44. koatl-0.1.36/koatl/python/koatl/prelude/__init__.tl +0 -6
  45. koatl-0.1.36/koatl/python/koatl/prelude/functional/__init__.tl +0 -26
  46. koatl-0.1.36/koatl/python/koatl/prelude/io.tl +0 -5
  47. koatl-0.1.36/python/koatl/prelude/__init__.tl +0 -6
  48. koatl-0.1.36/python/koatl/prelude/functional/__init__.tl +0 -26
  49. koatl-0.1.36/python/koatl/prelude/io.tl +0 -5
  50. {koatl-0.1.36 → koatl-0.1.38}/Cargo.toml +0 -0
  51. {koatl-0.1.36 → koatl-0.1.38}/README.md +0 -0
  52. {koatl-0.1.36 → koatl-0.1.38}/koatl/.github/workflows/CI.yml +0 -0
  53. {koatl-0.1.36 → koatl-0.1.38}/koatl/.gitignore +0 -0
  54. {koatl-0.1.36 → koatl-0.1.38}/koatl/LICENSE +0 -0
  55. {koatl-0.1.36 → koatl-0.1.38}/koatl/README.md +0 -0
  56. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/__init__.py +0 -0
  57. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/__main__.py +0 -0
  58. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/cli.py +0 -0
  59. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/notebook/__init__.py +0 -0
  60. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/notebook/magic.py +0 -0
  61. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/runtime/helpers.py +0 -0
  62. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/runtime/meta_finder.py +0 -0
  63. {koatl-0.1.36 → koatl-0.1.38}/koatl/python/koatl/runtime/record.py +0 -0
  64. {koatl-0.1.36 → koatl-0.1.38}/koatl/requirements.txt +0 -0
  65. {koatl-0.1.36 → koatl-0.1.38}/koatl/src/emit_py.rs +0 -0
  66. {koatl-0.1.36 → koatl-0.1.38}/koatl/src/lib.rs +0 -0
  67. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/containers.tl +0 -0
  68. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/data.txt +0 -0
  69. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/decorators.tl +0 -0
  70. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/destructure-for-and-fn.tl +0 -0
  71. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/destructure.tl +0 -0
  72. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/escape_ident.tl +0 -0
  73. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/fstr.tl +0 -0
  74. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/functions.tl +0 -0
  75. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/generator.tl +0 -0
  76. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/if_expr.tl +0 -0
  77. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/loops.tl +0 -0
  78. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/match.tl +0 -0
  79. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/nary-list.tl +0 -0
  80. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/placeholder.tl +0 -0
  81. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/precedence.tl +0 -0
  82. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/record.tl +0 -0
  83. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/scopes.tl +0 -0
  84. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/semantic_whitespace.tl +0 -0
  85. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/short_circuit.tl +0 -0
  86. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/base/with.tl +0 -0
  87. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/async.tl +0 -0
  88. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/aug_assign.tl +0 -0
  89. {koatl-0.1.36/koatl/tests/e2e/base → koatl-0.1.38/koatl/tests/e2e/prelude}/coal.tl +0 -0
  90. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/env.tl +0 -0
  91. {koatl-0.1.36/koatl/tests/e2e/base → koatl-0.1.38/koatl/tests/e2e/prelude}/imports.tl +0 -0
  92. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/iterables.tl +0 -0
  93. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/list.tl +0 -0
  94. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/memo.tl +0 -0
  95. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/result.tl +0 -0
  96. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/slice.tl +0 -0
  97. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/try.tl +0 -0
  98. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/prelude/virtual.tl +0 -0
  99. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/util/__init__.py +0 -0
  100. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/util/module0.tl +0 -0
  101. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/util/module1.tl +0 -0
  102. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/e2e/util/module2.tl +0 -0
  103. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/arith.tl +0 -0
  104. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/assign.tl +0 -0
  105. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/block-comments.tl +0 -0
  106. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/deco.tl +0 -0
  107. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/func.tl +0 -0
  108. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/parse/matches.tl +0 -0
  109. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/test_e2e.py +0 -0
  110. {koatl-0.1.36 → koatl-0.1.38}/koatl/tests/test_parse.py +0 -0
  111. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/Cargo.toml +0 -0
  112. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/Cargo.toml +0 -0
  113. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/parser/src/lib.rs +0 -0
  114. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/inference.rs +0 -0
  115. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/main.rs +0 -0
  116. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/parse_timer.rs +0 -0
  117. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/parser.rs +0 -0
  118. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/py/ast.rs +0 -0
  119. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/py/mod.rs +0 -0
  120. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/py/util.rs +0 -0
  121. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/types.rs +0 -0
  122. {koatl-0.1.36 → koatl-0.1.38}/koatl-core/src/util.rs +0 -0
  123. {koatl-0.1.36 → koatl-0.1.38}/pyproject.toml +0 -0
  124. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/__init__.py +0 -0
  125. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/__main__.py +0 -0
  126. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/cli.py +0 -0
  127. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/notebook/__init__.py +0 -0
  128. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/notebook/magic.py +0 -0
  129. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/runtime/helpers.py +0 -0
  130. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/runtime/meta_finder.py +0 -0
  131. {koatl-0.1.36 → koatl-0.1.38}/python/koatl/runtime/record.py +0 -0
@@ -99,7 +99,7 @@ checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
99
99
 
100
100
  [[package]]
101
101
  name = "koatl"
102
- version = "0.1.36"
102
+ version = "0.1.38"
103
103
  dependencies = [
104
104
  "ariadne",
105
105
  "koatl-core",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koatl
3
- Version: 0.1.36
3
+ Version: 0.1.38
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "koatl"
3
- version = "0.1.36"
3
+ version = "0.1.38"
4
4
  edition = "2021"
5
5
 
6
6
  [lib]
@@ -0,0 +1,61 @@
1
+ import koatl.std.iter.Iterable
2
+
3
+ Extension.trait(Iterable)
4
+
5
+ import koatl.std.data.List
6
+
7
+ Extension.property(list, "len")& List.len.fget
8
+
9
+ import koatl.std.alg.*
10
+
11
+ Extension.property(object, "result")& self => Result(self)
12
+
13
+ __tl__.Ok = Ok
14
+ __tl__.Err = Err
15
+ __tl__.Result = Result
16
+
17
+ __tl__.op_coal = (x, f) =>
18
+ if x matches Result():
19
+ return x.coalesce(f)
20
+
21
+ if not koatl.std.alg.result.infer_ok(x):
22
+ return f()
23
+ return x
24
+
25
+ __tl__.op_map = (x, f) =>
26
+ if x matches Result():
27
+ return x.map(f)
28
+
29
+ if koatl.std.alg.result.infer_ok(x):
30
+ return f(x)
31
+ return x
32
+
33
+ __tl__.memo_value = Memo.value
34
+ __tl__.async_memo_value = AsyncMemo.value
35
+
36
+ import koatl.std.re.Pattern
37
+
38
+ Extension.method(str, "match")& (regex, str) => Pattern(regex).match(str)
39
+
40
+ # Note: the below methods have arguments in reverse order to Python's re module.
41
+ Extension.method(str, "matches")& (str, regex) => Pattern(regex).match(str)
42
+ Extension.method(str, "search")& (str, regex) => Pattern(regex).search(str)
43
+
44
+ import koatl.std.lazy_module.LazyModule
45
+
46
+ export import koatl.std.trait.*
47
+ export Result, Ok, Err, Env, Memo, Async, AsyncMemo
48
+ export std = LazyModule("koatl.std")
49
+
50
+ ModuleProxy = class:
51
+ __init__ = (self) =>
52
+ self._modules = {}
53
+
54
+ __getattr__ = (self, attr) =>
55
+ if attr not in self._modules:
56
+ self._modules[attr] = LazyModule(attr)
57
+ return self._modules[attr]
58
+
59
+ __repr__ = self => f"ModuleProxy({self._modules})"
60
+
61
+ export mod = ModuleProxy()
@@ -19,7 +19,6 @@ meta_finder.install_hook()
19
19
  from .virtual import *
20
20
  from .record import *
21
21
  from .helpers import *
22
- from .classes import *
23
22
 
24
23
 
25
24
  def dummy(name):
@@ -52,7 +51,6 @@ __tl__ = SimpleNamespace(
52
51
  **{name: helpers.__dict__[name] for name in helpers.__all__},
53
52
  **{name: record.__dict__[name] for name in record.__all__},
54
53
  **{name: virtual.__dict__[name] for name in virtual.__all__},
55
- **{name: classes.__dict__[name] for name in classes.__all__},
56
54
  )
57
55
 
58
56
 
@@ -61,5 +59,4 @@ __all__ = [
61
59
  *helpers.__all__,
62
60
  *record.__all__,
63
61
  *virtual.__all__,
64
- *classes.__all__,
65
62
  ]
@@ -1,14 +1,14 @@
1
1
  from functools import partial
2
2
  from itertools import count
3
3
  from types import SimpleNamespace
4
- from .._rs import fast_vget, fast_vset, fast_vset_trait
4
+ from koatl._rs import fast_vget, fast_vset, fast_vset_trait
5
5
 
6
6
 
7
7
  def vget(obj, name, ignore_traits=False):
8
8
  try:
9
9
  return getattr(obj, name)
10
- except AttributeError:
11
- pass
10
+ except AttributeError as e:
11
+ orig_err = e
12
12
 
13
13
  # special case for iter - this could be implemented using types and trait vtbls
14
14
  # but this is simpler and probably faster
@@ -38,7 +38,7 @@ def vget(obj, name, ignore_traits=False):
38
38
 
39
39
  return partial(v, obj)
40
40
 
41
- raise AttributeError(f"'{type(obj).__name__}' object has no v-attribute '{name}'")
41
+ raise orig_err
42
42
 
43
43
 
44
44
  def vhas(obj, name, ignore_traits=False):
@@ -0,0 +1,5 @@
1
+ export import .base.*
2
+ export import .async.*
3
+ export import .env.*
4
+ export import .memo.*
5
+ export import .result.*
@@ -1,7 +1,7 @@
1
1
  import functools.wraps
2
2
  import asyncio
3
3
 
4
- import .MonadOnce
4
+ import .base.MonadOnce
5
5
 
6
6
  export Async = class(MonadOnce):
7
7
  __init__ = (self, awaitable) => self.generator = awaitable.__await__()
@@ -1,3 +1,5 @@
1
+ import koatl.std.trait.Trait
2
+
1
3
  export Monad = class(Trait):
2
4
  """
3
5
  Abstract base class for monads.
@@ -1,5 +1,5 @@
1
1
  import functools.wraps
2
- import .MonadOnce
2
+ import .base.MonadOnce
3
3
 
4
4
  export Env = class(MonadOnce):
5
5
  __slots__ = ("f",)
@@ -1,7 +1,7 @@
1
1
  import collections.defaultdict
2
2
  import functools.wraps
3
3
 
4
- import .algebra.(MonadOnce, Identity)
4
+ import .base.(MonadOnce, Identity)
5
5
  import .result.(Result, Ok, Err)
6
6
  import .async.(Async)
7
7
 
@@ -181,7 +181,4 @@ export AsyncMemo = class(MonadOnce):
181
181
 
182
182
  except StopIteration(value=value):
183
183
  return value
184
- )
185
-
186
- __tl__.memo_value = Memo.value
187
- __tl__.async_memo_value = AsyncMemo.value
184
+ )
@@ -1,5 +1,5 @@
1
1
  import functools.wraps
2
- import .algebra.(Identity, MonadOnce)
2
+ import .base.(Identity, MonadOnce)
3
3
 
4
4
  infer_ok = x =>
5
5
  x match:
@@ -158,26 +158,4 @@ export Err = class(Result):
158
158
  if self.value matches BaseException():
159
159
  raise self.value
160
160
  raise ValueError(f"Expected Ok, got {repr(self)}")
161
- coalesce = (self, f) => f()
162
-
163
- Extension.property(object, "result")& self => Result
164
-
165
- __tl__.Ok = Ok
166
- __tl__.Err = Err
167
- __tl__.Result = Result
168
-
169
- __tl__.op_coal = (x, f) =>
170
- if x matches Result():
171
- return x.coalesce(f)
172
-
173
- if not infer_ok(x):
174
- return f()
175
- return x
176
-
177
- __tl__.op_map = (x, f) =>
178
- if x matches Result():
179
- return x.map(f)
180
-
181
- if infer_ok(x):
182
- return f(x)
183
- return x
161
+ coalesce = (self, f) => f()
@@ -0,0 +1 @@
1
+ export import .list.List
@@ -1,6 +1,6 @@
1
1
  import itertools
2
2
 
3
- import .Monad
3
+ import koatl.std.alg.Monad
4
4
 
5
5
  export List = class(Monad):
6
6
  __new__ = (cls, *args, **kwargs) => raise ValueError(
@@ -19,7 +19,4 @@ export List = class(Monad):
19
19
 
20
20
  pure = staticmethod& x => [x]
21
21
 
22
- len = property& self => len(self)
23
-
24
-
25
- Extension.property(list, "len")& List.len.fget
22
+ len = property& self => len(self)
@@ -0,0 +1,3 @@
1
+ export read_file = (filename) =>
2
+ with desc = open(filename, "r"):
3
+ desc.read()
@@ -1,8 +1,10 @@
1
1
  import itertools
2
2
  import builtins
3
- import .functional.(Traversable, Ok, Err, Memo, Async, AsyncMemo, Result)
4
3
 
5
- export Iterable = Extension.trait& class(Traversable, Trait):
4
+ import koatl.std.trait.Trait
5
+ import .alg.(Traversable, Ok, Err, Memo, Async, AsyncMemo, Result)
6
+
7
+ export Iterable = class(Traversable, Trait):
6
8
  iter = Trait.abstract& self => None
7
9
 
8
10
  skip = (self, n) =>
@@ -259,8 +261,6 @@ export Iterable = Extension.trait& class(Traversable, Trait):
259
261
  Record(self.iter)
260
262
 
261
263
  traverse = (self, f=None) =>
262
- import .functional.(Async, Result)
263
-
264
264
  if f === None:
265
265
  f = x => x
266
266
 
@@ -0,0 +1,33 @@
1
+ import importlib
2
+ import collections
3
+
4
+ export LazyModule = class:
5
+ __init__ = (self, name) =>
6
+ self._name = name
7
+ self._module = None
8
+ self._submodules = {}
9
+
10
+ __getattr__ = (self, attr) =>
11
+ try:
12
+ if self._module === None:
13
+ self._module = importlib.import_module(self._name)
14
+
15
+ if hasattr(self._module, "__path__"):
16
+ if attr not in self._submodules:
17
+ self._submodules[attr] =
18
+ if importlib.util.find_spec(f"{self._name}.{attr}", self._module.__path__):
19
+ LazyModule(f"{self._name}.{attr}")
20
+ else:
21
+ None
22
+
23
+ if self._submodules[attr] <=> None:
24
+ return self._submodules[attr]
25
+
26
+ if hasattr(self._module, attr):
27
+ return getattr(self._module, attr)
28
+ except e:
29
+ raise ValueError(str(e))
30
+
31
+ raise AttributeError(f"Module '{self._name}' has no attribute '{attr}'")
32
+
33
+ __repr__ = self => f"LazyModule({self._name})"
@@ -1,8 +1,8 @@
1
1
  import re
2
2
  import collections
3
- import .functional.Result
3
+ import .alg.Result
4
4
 
5
- export Regex = class:
5
+ export Pattern = class:
6
6
  __slots__ = ("pattern",)
7
7
 
8
8
  __init__ = (self, pattern) =>
@@ -45,16 +45,4 @@ export Regex = class:
45
45
 
46
46
  match = property& self => self._match.group(0)
47
47
 
48
- __repr__ = self => f"Match({self._match})"
49
-
50
-
51
- Extension.method(str, "match")& (regex, str) => Regex(regex).match(str)
52
-
53
-
54
- # Note: the below methods have arguments in reverse order to Python's re module.
55
-
56
- Extension.method(str, "matches")& (str, regex) =>
57
- Regex(regex).match(str)
58
-
59
- Extension.method(str, "search")& (str, regex) =>
60
- Regex(regex).search(str)
48
+ __repr__ = self => f"Match({self._match})"
@@ -40,7 +40,7 @@ class MappingMeta(type):
40
40
  return [(k, v) for k, v in inspect.getmembers(self) if not k.startswith("_")]
41
41
 
42
42
 
43
- # A utility base class to inherit from to enable __getitem__ method lookup on types and thus destructuring.
43
+ # A utility base class to inherit from that implements Mapping on the type and thus destructuring.
44
44
  class Class(metaclass=MappingMeta):
45
45
  pass
46
46
 
@@ -97,21 +97,20 @@ pub enum Literal<'a> {
97
97
  pub type SLiteral<'a> = Spanned<Literal<'a>>;
98
98
 
99
99
  #[derive(Debug, Clone)]
100
- pub enum ImportList<'a> {
101
- // ident, alias
102
- Leaves(Vec<(SIdent<'a>, Option<SIdent<'a>>)>),
100
+ pub enum ImportLeaf<'a> {
101
+ Multi(Vec<ImportTree<'a>>),
102
+ Single(SIdent<'a>, Option<SIdent<'a>>),
103
+ This(Option<SIdent<'a>>),
103
104
  Star,
104
105
  }
105
106
 
106
107
  #[derive(Debug, Clone)]
107
- pub struct ImportStmt<'a> {
108
+ pub struct ImportTree<'a> {
108
109
  pub trunk: Vec<SIdent<'a>>,
109
- pub imports: ImportList<'a>,
110
+ pub leaf: Spanned<ImportLeaf<'a>>,
110
111
 
111
112
  // number of dots prepending the trunk
112
113
  pub level: usize,
113
-
114
- pub reexport: bool,
115
114
  }
116
115
 
117
116
  #[derive(Debug, Clone, Copy, PartialEq)]
@@ -133,7 +132,7 @@ pub enum Stmt<'a, TTree: Tree> {
133
132
  Return(TTree::Expr),
134
133
  While(TTree::Expr, TTree::Expr),
135
134
  For(TTree::Pattern, TTree::Expr, TTree::Expr),
136
- Import(ImportStmt<'a>),
135
+ Import(ImportTree<'a>, bool),
137
136
  Try(TTree::Expr, Vec<MatchCase<TTree>>, Option<TTree::Expr>),
138
137
  Raise(Option<TTree::Expr>),
139
138