koatl 0.1.16__tar.gz → 0.1.18__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 (112) hide show
  1. {koatl-0.1.16 → koatl-0.1.18}/Cargo.lock +17 -1
  2. {koatl-0.1.16 → koatl-0.1.18}/PKG-INFO +1 -1
  3. {koatl-0.1.16 → koatl-0.1.18}/koatl/Cargo.toml +1 -1
  4. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/result.tl +14 -1
  5. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/runtime/__init__.py +1 -0
  6. {koatl-0.1.16 → koatl-0.1.18}/koatl/src/emit_py.rs +1 -1
  7. {koatl-0.1.16 → koatl-0.1.18}/koatl/src/lib.rs +1 -1
  8. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/match.tl +14 -1
  9. koatl-0.1.18/koatl/tests/parse/assign.tl +1 -0
  10. koatl-0.1.18/koatl/tests/parse/block-comments.tl +1 -0
  11. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/Cargo.toml +1 -0
  12. koatl-0.1.18/koatl-core/parser/src/ast.rs +347 -0
  13. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/parser/src/lexer.rs +105 -89
  14. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/parser/src/parser.rs +251 -258
  15. koatl-0.1.18/koatl-core/parser/src/util.rs +271 -0
  16. koatl-0.1.18/koatl-core/src/inference.rs +298 -0
  17. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/lib.rs +74 -55
  18. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/main.rs +3 -2
  19. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/py/emit.rs +9 -9
  20. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/py/util.rs +4 -0
  21. koatl-0.1.18/koatl-core/src/resolve_scopes.rs +1547 -0
  22. koatl-0.1.18/koatl-core/src/transform.rs +2376 -0
  23. koatl-0.1.18/koatl-core/src/types.rs +8 -0
  24. koatl-0.1.18/koatl-core/src/util.rs +137 -0
  25. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/result.tl +14 -1
  26. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/runtime/__init__.py +1 -0
  27. koatl-0.1.16/koatl/tests/parse/assign.tl +0 -1
  28. koatl-0.1.16/koatl-core/parser/src/ast.rs +0 -246
  29. koatl-0.1.16/koatl-core/parser/src/util.rs +0 -303
  30. koatl-0.1.16/koatl-core/src/linecol.rs +0 -28
  31. koatl-0.1.16/koatl-core/src/transform.rs +0 -3361
  32. {koatl-0.1.16 → koatl-0.1.18}/Cargo.toml +0 -0
  33. {koatl-0.1.16 → koatl-0.1.18}/README.md +0 -0
  34. {koatl-0.1.16 → koatl-0.1.18}/koatl/.github/workflows/CI.yml +0 -0
  35. {koatl-0.1.16 → koatl-0.1.18}/koatl/.gitignore +0 -0
  36. {koatl-0.1.16 → koatl-0.1.18}/koatl/LICENSE +0 -0
  37. {koatl-0.1.16 → koatl-0.1.18}/koatl/README.md +0 -0
  38. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/__init__.py +0 -0
  39. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/__main__.py +0 -0
  40. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/cli.py +0 -0
  41. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/notebook/__init__.py +0 -0
  42. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/notebook/magic.py +0 -0
  43. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/__init__.tl +0 -0
  44. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/__init__.tl +0 -0
  45. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/async.tl +0 -0
  46. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/async_util.py +0 -0
  47. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/monad.tl +0 -0
  48. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/functional/reader.tl +0 -0
  49. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/prelude/iterable.tl +0 -0
  50. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/runtime/helpers.py +0 -0
  51. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/runtime/meta_finder.py +0 -0
  52. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/runtime/record.py +0 -0
  53. {koatl-0.1.16 → koatl-0.1.18}/koatl/python/koatl/runtime/virtual.py +0 -0
  54. {koatl-0.1.16 → koatl-0.1.18}/koatl/requirements.txt +0 -0
  55. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/coal.tl +0 -0
  56. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/containers.tl +0 -0
  57. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/decorators.tl +0 -0
  58. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/destructure-for-and-fn.tl +0 -0
  59. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/destructure.tl +0 -0
  60. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/escape_ident.tl +0 -0
  61. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/fstr.tl +0 -0
  62. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/functions.tl +0 -0
  63. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/generator.tl +0 -0
  64. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/if_expr.tl +0 -0
  65. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/imports.tl +0 -0
  66. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/loops.tl +0 -0
  67. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/nary-list.tl +0 -0
  68. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/placeholder.tl +0 -0
  69. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/precedence.tl +0 -0
  70. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/scopes.tl +0 -0
  71. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/semantic_whitespace.tl +0 -0
  72. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/slice.tl +0 -0
  73. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/base/try.tl +0 -0
  74. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/destructure.tl +0 -0
  75. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/prelude/async.tl +0 -0
  76. {koatl-0.1.16/koatl/tests/e2e/base → koatl-0.1.18/koatl/tests/e2e/prelude}/iterables.tl +0 -0
  77. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/prelude/reader.tl +0 -0
  78. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/prelude/result.tl +0 -0
  79. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/prelude/virtual.tl +0 -0
  80. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/util/__init__.py +0 -0
  81. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/util/module0.tl +0 -0
  82. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/util/module1.tl +0 -0
  83. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/e2e/util/module2.tl +0 -0
  84. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/parse/arith.tl +0 -0
  85. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/parse/deco.tl +0 -0
  86. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/parse/func.tl +0 -0
  87. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/parse/matches.tl +0 -0
  88. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/test_e2e.py +0 -0
  89. {koatl-0.1.16 → koatl-0.1.18}/koatl/tests/test_parse.py +0 -0
  90. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/parser/Cargo.toml +0 -0
  91. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/parser/src/lib.rs +0 -0
  92. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/parser/tests/lexer.rs +0 -0
  93. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/parser.rs +0 -0
  94. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/py/ast.rs +0 -0
  95. {koatl-0.1.16 → koatl-0.1.18}/koatl-core/src/py/mod.rs +0 -0
  96. {koatl-0.1.16 → koatl-0.1.18}/pyproject.toml +0 -0
  97. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/__init__.py +0 -0
  98. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/__main__.py +0 -0
  99. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/cli.py +0 -0
  100. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/notebook/__init__.py +0 -0
  101. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/notebook/magic.py +0 -0
  102. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/__init__.tl +0 -0
  103. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/__init__.tl +0 -0
  104. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/async.tl +0 -0
  105. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/async_util.py +0 -0
  106. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/monad.tl +0 -0
  107. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/functional/reader.tl +0 -0
  108. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/prelude/iterable.tl +0 -0
  109. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/runtime/helpers.py +0 -0
  110. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/runtime/meta_finder.py +0 -0
  111. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/runtime/record.py +0 -0
  112. {koatl-0.1.16 → koatl-0.1.18}/python/koatl/runtime/virtual.py +0 -0
@@ -99,7 +99,7 @@ checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
99
99
 
100
100
  [[package]]
101
101
  name = "koatl"
102
- version = "0.1.16"
102
+ version = "0.1.18"
103
103
  dependencies = [
104
104
  "ariadne",
105
105
  "koatl-core",
@@ -114,6 +114,7 @@ dependencies = [
114
114
  "ariadne",
115
115
  "once_cell",
116
116
  "parser",
117
+ "slotmap",
117
118
  ]
118
119
 
119
120
  [[package]]
@@ -288,6 +289,15 @@ version = "1.3.0"
288
289
  source = "registry+https://github.com/rust-lang/crates.io-index"
289
290
  checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
290
291
 
292
+ [[package]]
293
+ name = "slotmap"
294
+ version = "1.0.7"
295
+ source = "registry+https://github.com/rust-lang/crates.io-index"
296
+ checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a"
297
+ dependencies = [
298
+ "version_check",
299
+ ]
300
+
291
301
  [[package]]
292
302
  name = "stacker"
293
303
  version = "0.1.21"
@@ -342,6 +352,12 @@ version = "0.2.4"
342
352
  source = "registry+https://github.com/rust-lang/crates.io-index"
343
353
  checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
344
354
 
355
+ [[package]]
356
+ name = "version_check"
357
+ version = "0.9.5"
358
+ source = "registry+https://github.com/rust-lang/crates.io-index"
359
+ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
360
+
345
361
  [[package]]
346
362
  name = "windows-sys"
347
363
  version = "0.59.0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: koatl
3
- Version: 0.1.16
3
+ Version: 0.1.18
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.16"
3
+ version = "0.1.18"
4
4
  edition = "2021"
5
5
 
6
6
  [lib]
@@ -29,6 +29,12 @@ export Result = class(Monad):
29
29
  else:
30
30
  return self
31
31
 
32
+ map_none = (self, f) =>
33
+ if self matches None:
34
+ return f()
35
+ else:
36
+ return self
37
+
32
38
  OkMeta = class(type):
33
39
  __instancecheck__ = (cls, instance) => __tl__.ok(instance)
34
40
 
@@ -42,10 +48,11 @@ export Ok = class(metaclass=OkMeta):
42
48
  # so need to copy the methods over manually from Result
43
49
 
44
50
  # We could just use the object fallback methods, but this avoids
45
- # the manual __tl__.vget
51
+ # the manual __tl__.vget so is slightly faster
46
52
  bind_once = Result.bind_once
47
53
  bind_gen = Result.bind_gen
48
54
  map_err = Result.map_err
55
+ map_none = Result.map_none
49
56
 
50
57
  assert = staticmethod& value =>
51
58
  value match:
@@ -61,6 +68,12 @@ register_global_attr(
61
68
  Result.map_err
62
69
  )
63
70
 
71
+ register_global_attr(
72
+ object,
73
+ "map_none",
74
+ Result.map_none
75
+ )
76
+
64
77
  register_global_attr(
65
78
  object,
66
79
  "bind",
@@ -22,6 +22,7 @@ from .helpers import *
22
22
 
23
23
 
24
24
  __tl__ = SimpleNamespace(
25
+ Exception=Exception,
25
26
  slice=slice,
26
27
  vget=virtual.vget,
27
28
  vhas=virtual.vhas,
@@ -1,4 +1,4 @@
1
- use koatl_core::{linecol::LineColCache, parser::ast::*, py::ast::*};
1
+ use koatl_core::{parser::ast::*, py::ast::*, util::LineColCache};
2
2
 
3
3
  use pyo3::{
4
4
  call::PyCallArgs,
@@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
4
4
  use std::{collections::HashMap, sync::Mutex};
5
5
 
6
6
  use koatl_core::{
7
- format_errs, linecol::LineColCache, transpile_to_py_ast, transpile_to_source, TranspileOptions,
7
+ format_errs, transpile_to_py_ast, transpile_to_source, util::LineColCache, TranspileOptions,
8
8
  };
9
9
  use pyo3::{
10
10
  prelude::*,
@@ -73,4 +73,17 @@ x = 1
73
73
  assert_eq([1, 2, 3] matches [1, 2, 3], True)
74
74
  assert_eq([1, 2, 3] matches [.x, _, 3], True)
75
75
 
76
- assert_eq(try 1 matches 1, True)
76
+ assert_eq(try 1 matches 1, True)
77
+
78
+ f = () =>
79
+ if [1, 2, 3] matches [1, 2, x]:
80
+ assert_eq(x, 3)
81
+ else:
82
+ assert False
83
+
84
+ if [1, 2, 3] matches not [1, 2, x]:
85
+ raise
86
+ else:
87
+ assert_eq(x, 3)
88
+
89
+ f()
@@ -0,0 +1 @@
1
+ let x = 1
@@ -0,0 +1 @@
1
+ a = #- 81937 (*A&F(*& #- asdf -##( *&U*( -# 3
@@ -7,3 +7,4 @@ edition = "2024"
7
7
  ariadne = "0.5.1"
8
8
  parser = { path = "parser" }
9
9
  once_cell = "1.19.0"
10
+ slotmap = "1.0.7"
@@ -0,0 +1,347 @@
1
+ use std::{borrow::Cow, fmt::Display};
2
+
3
+ use chumsky::span::SimpleSpan;
4
+
5
+ pub type Indirect<T> = Box<T>;
6
+
7
+ pub trait FromIndirect<T> {
8
+ fn extract(self) -> T;
9
+ }
10
+
11
+ impl<T: Clone> FromIndirect<T> for Indirect<T> {
12
+ fn extract(self) -> T {
13
+ *self
14
+ }
15
+ }
16
+
17
+ pub trait IntoIndirect<T> {
18
+ fn indirect(self) -> Indirect<T>;
19
+ }
20
+
21
+ impl<T> IntoIndirect<T> for Indirect<T> {
22
+ fn indirect(self) -> Indirect<T> {
23
+ self
24
+ }
25
+ }
26
+
27
+ impl<T> IntoIndirect<T> for T {
28
+ fn indirect(self) -> Indirect<T> {
29
+ Box::new(self)
30
+ }
31
+ }
32
+
33
+ #[derive(Debug, Copy, Clone)]
34
+ pub enum BinaryOp {
35
+ Add,
36
+ Sub,
37
+ Mul,
38
+ Mod,
39
+ MatMul,
40
+ Div,
41
+ Exp,
42
+
43
+ Lt,
44
+ Leq,
45
+ Gt,
46
+ Geq,
47
+ Eq,
48
+ Neq,
49
+ Is,
50
+ Nis,
51
+
52
+ And,
53
+ Or,
54
+
55
+ Coalesce,
56
+ Pipe,
57
+ }
58
+
59
+ #[derive(Debug, Copy, Clone)]
60
+ pub enum UnaryOp {
61
+ Inv,
62
+ Pos,
63
+ Neg,
64
+ Not,
65
+ Bind,
66
+ }
67
+
68
+ #[derive(Debug, Clone, Eq, PartialEq, Hash)]
69
+ pub struct Ident<'a>(pub Cow<'a, str>);
70
+
71
+ impl<'a> Display for Ident<'a> {
72
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73
+ self.0.fmt(f)
74
+ }
75
+ }
76
+
77
+ impl<'a> From<Cow<'a, str>> for Ident<'a> {
78
+ fn from(value: Cow<'a, str>) -> Self {
79
+ Ident(value)
80
+ }
81
+ }
82
+
83
+ pub type SIdent<'a> = Spanned<Ident<'a>>;
84
+
85
+ #[derive(Debug, Clone)]
86
+ pub enum Literal<'a> {
87
+ Num(Cow<'a, str>),
88
+ Str(Cow<'a, str>),
89
+ Bool(bool),
90
+ None,
91
+ }
92
+
93
+ pub type SLiteral<'a> = Spanned<Literal<'a>>;
94
+
95
+ #[derive(Debug, Clone)]
96
+ pub enum ImportList<'a> {
97
+ // ident, alias
98
+ Leaves(Vec<(SIdent<'a>, Option<SIdent<'a>>)>),
99
+ Star,
100
+ }
101
+
102
+ #[derive(Debug, Clone)]
103
+ pub struct ImportStmt<'a> {
104
+ pub trunk: Vec<SIdent<'a>>,
105
+ pub imports: ImportList<'a>,
106
+
107
+ // number of dots prepending the trunk
108
+ pub level: usize,
109
+
110
+ pub reexport: bool,
111
+ }
112
+
113
+ #[derive(Debug, Clone, Copy, PartialEq)]
114
+ pub enum DeclType {
115
+ Export,
116
+ Global,
117
+ Let,
118
+ Const,
119
+ }
120
+
121
+ #[derive(Debug, Clone)]
122
+ pub enum Stmt<'a, TTree: Tree> {
123
+ Module,
124
+ Decl(Vec<SIdent<'a>>, DeclType),
125
+ Assign(TTree::Expr, TTree::Expr, Option<DeclType>),
126
+ Expr(TTree::Expr),
127
+
128
+ Return(TTree::Expr),
129
+ While(TTree::Expr, TTree::Expr),
130
+ For(TTree::Pattern, TTree::Expr, TTree::Expr),
131
+ Import(ImportStmt<'a>),
132
+ Try(TTree::Expr, Vec<MatchCase<TTree>>, Option<TTree::Expr>),
133
+ Assert(TTree::Expr, Option<TTree::Expr>),
134
+ Raise(Option<TTree::Expr>),
135
+
136
+ Break,
137
+ Continue,
138
+ }
139
+
140
+ #[derive(Debug, Clone)]
141
+ pub struct FmtExpr<'a, TTree: Tree> {
142
+ pub expr: TTree::Expr,
143
+ pub fmt: Option<Ident<'a>>,
144
+ }
145
+
146
+ #[derive(Debug, Clone)]
147
+ pub enum ListItem<TTree: Tree> {
148
+ Item(TTree::Expr),
149
+ Spread(TTree::Expr),
150
+ }
151
+
152
+ #[derive(Debug, Clone)]
153
+ pub enum MappingItem<TTree: Tree> {
154
+ Ident(TTree::Expr),
155
+ Item(TTree::Expr, TTree::Expr),
156
+ Spread(TTree::Expr),
157
+ }
158
+
159
+ #[derive(Debug, Clone)]
160
+ pub enum CallItem<'a, TTree: Tree> {
161
+ Arg(TTree::Expr),
162
+ Kwarg(SIdent<'a>, TTree::Expr),
163
+ ArgSpread(TTree::Expr),
164
+ KwargSpread(TTree::Expr),
165
+ }
166
+
167
+ #[derive(Debug, Clone)]
168
+ pub enum ArgDefItem<'a, TTree: Tree> {
169
+ Arg(TTree::Pattern, Option<TTree::Expr>),
170
+ ArgSpread(SIdent<'a>),
171
+ KwargSpread(SIdent<'a>),
172
+ }
173
+
174
+ #[derive(Debug, Clone)]
175
+ pub struct MatchCase<TTree: Tree> {
176
+ pub pattern: Option<TTree::Pattern>,
177
+ pub guard: Option<TTree::Expr>,
178
+ pub body: TTree::Expr,
179
+ }
180
+
181
+ pub trait Tree {
182
+ type Expr;
183
+ type Pattern;
184
+ type Stmt;
185
+ }
186
+
187
+ #[derive(Debug, Clone)]
188
+ pub enum Expr<'a, TTree: Tree> {
189
+ Literal(SLiteral<'a>),
190
+ Ident(SIdent<'a>),
191
+ Tuple(Vec<ListItem<TTree>>),
192
+ List(Vec<ListItem<TTree>>),
193
+ Mapping(Vec<MappingItem<TTree>>),
194
+ Slice(
195
+ Option<TTree::Expr>,
196
+ Option<TTree::Expr>,
197
+ Option<TTree::Expr>,
198
+ ),
199
+
200
+ Unary(UnaryOp, TTree::Expr),
201
+ Binary(BinaryOp, TTree::Expr, TTree::Expr),
202
+
203
+ Await(TTree::Expr),
204
+ Yield(TTree::Expr),
205
+ YieldFrom(TTree::Expr),
206
+
207
+ If(TTree::Expr, TTree::Expr, Option<TTree::Expr>),
208
+ Match(TTree::Expr, Vec<MatchCase<TTree>>),
209
+ Matches(TTree::Expr, TTree::Pattern),
210
+ Class(Vec<CallItem<'a, TTree>>, TTree::Expr),
211
+
212
+ Call(TTree::Expr, Vec<CallItem<'a, TTree>>),
213
+ Subscript(TTree::Expr, Vec<ListItem<TTree>>),
214
+ RawAttribute(TTree::Expr, SIdent<'a>),
215
+ ScopedAttribute(TTree::Expr, TTree::Expr),
216
+ Attribute(TTree::Expr, SIdent<'a>),
217
+
218
+ MappedCall(TTree::Expr, Vec<CallItem<'a, TTree>>),
219
+ MappedSubscript(TTree::Expr, Vec<ListItem<TTree>>),
220
+ MappedRawAttribute(TTree::Expr, SIdent<'a>),
221
+ MappedScopedAttribute(TTree::Expr, TTree::Expr),
222
+ MappedAttribute(TTree::Expr, SIdent<'a>),
223
+
224
+ Checked(TTree::Expr, Option<TTree::Pattern>),
225
+
226
+ Block(Vec<TTree::Stmt>),
227
+
228
+ Fn(Vec<ArgDefItem<'a, TTree>>, TTree::Expr),
229
+ Fstr(Spanned<String>, Vec<(FmtExpr<'a, TTree>, Spanned<String>)>),
230
+
231
+ // these are removed during desugaring
232
+ Decorated(TTree::Expr, TTree::Expr),
233
+ Placeholder,
234
+ }
235
+
236
+ // Patterns
237
+
238
+ #[derive(Debug, Clone)]
239
+ pub enum PatternSequenceItem<'a, TTree: Tree> {
240
+ Item(TTree::Pattern),
241
+ Spread(Option<SIdent<'a>>),
242
+ }
243
+
244
+ #[derive(Debug, Clone)]
245
+ pub enum PatternMappingItem<'a, TTree: Tree> {
246
+ Ident(SIdent<'a>),
247
+ Item(TTree::Expr, TTree::Pattern),
248
+ Spread(Option<SIdent<'a>>),
249
+ }
250
+
251
+ #[derive(Debug, Clone)]
252
+ pub enum PatternClassItem<'a, TTree: Tree> {
253
+ Item(TTree::Pattern),
254
+ Kw(SIdent<'a>, TTree::Pattern),
255
+ }
256
+
257
+ #[derive(Debug, Clone)]
258
+ pub enum Pattern<'a, TTree: Tree> {
259
+ Capture(Option<SIdent<'a>>),
260
+ Value(TTree::Expr),
261
+ As(TTree::Pattern, SIdent<'a>),
262
+ Or(Vec<TTree::Pattern>),
263
+ Literal(SLiteral<'a>),
264
+ Sequence(Vec<PatternSequenceItem<'a, TTree>>),
265
+ Mapping(Vec<PatternMappingItem<'a, TTree>>),
266
+ Class(TTree::Expr, Vec<PatternClassItem<'a, TTree>>),
267
+ }
268
+
269
+ // Spanned types
270
+
271
+ #[derive(Debug, Clone)]
272
+ pub struct STree<'src> {
273
+ phantom: std::marker::PhantomData<&'src ()>,
274
+ }
275
+
276
+ impl<'src> Tree for STree<'src> {
277
+ type Expr = Indirect<SExpr<'src>>;
278
+ type Pattern = Indirect<SPattern<'src>>;
279
+ type Stmt = Indirect<SStmt<'src>>;
280
+ }
281
+
282
+ pub type Span = SimpleSpan<usize, ()>;
283
+
284
+ #[derive(Debug, Clone)]
285
+ pub struct Spanned<T> {
286
+ pub span: Span,
287
+ pub value: T,
288
+ }
289
+
290
+ pub trait Spannable<T> {
291
+ fn spanned(self, span: Span) -> Spanned<T>;
292
+ }
293
+
294
+ impl<T> Spannable<T> for T {
295
+ fn spanned(self, span: Span) -> Spanned<T> {
296
+ Spanned { span, value: self }
297
+ }
298
+ }
299
+
300
+ pub type SPatternInner<'a> = Pattern<'a, STree<'a>>;
301
+
302
+ #[derive(Debug, Clone)]
303
+ pub struct SPattern<'a> {
304
+ pub value: SPatternInner<'a>,
305
+ pub span: Span,
306
+ }
307
+
308
+ impl<'a> SPatternInner<'a> {
309
+ pub fn spanned(self, span: Span) -> SPattern<'a> {
310
+ SPattern { value: self, span }
311
+ }
312
+ }
313
+
314
+ pub type SExprInner<'a> = Expr<'a, STree<'a>>;
315
+
316
+ #[derive(Debug, Clone)]
317
+ pub struct SExpr<'a> {
318
+ pub value: SExprInner<'a>,
319
+ pub span: Span,
320
+ }
321
+
322
+ impl<'a> SExprInner<'a> {
323
+ pub fn spanned(self, span: Span) -> SExpr<'a> {
324
+ SExpr { value: self, span }
325
+ }
326
+ }
327
+
328
+ pub type SStmtInner<'a> = Stmt<'a, STree<'a>>;
329
+
330
+ impl<'a> SStmtInner<'a> {
331
+ pub fn spanned(self, span: Span) -> SStmt<'a> {
332
+ SStmt { value: self, span }
333
+ }
334
+ }
335
+
336
+ #[derive(Debug, Clone)]
337
+ pub struct SStmt<'a> {
338
+ pub value: SStmtInner<'a>,
339
+ pub span: Span,
340
+ }
341
+
342
+ pub type SListItem<'a> = ListItem<STree<'a>>;
343
+ pub type SMappingItem<'a> = MappingItem<STree<'a>>;
344
+ pub type SMatchCase<'a> = MatchCase<STree<'a>>;
345
+ pub type SCallItem<'a> = CallItem<'a, STree<'a>>;
346
+ pub type SArgDefItem<'a> = ArgDefItem<'a, STree<'a>>;
347
+ pub type SFmtExpr<'a> = FmtExpr<'a, STree<'a>>;