Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit b4afa7a

Browse files
author
Jordan Mackie
committed
wip: ditto-type-checker
1 parent 66e3b30 commit b4afa7a

38 files changed

+5236
-4
lines changed

Cargo.lock

Lines changed: 53 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ members = [
1111
"crates/ditto-tree-sitter",
1212
"crates/ditto-highlight",
1313
"crates/ditto-pattern-checker",
14+
"crates/ditto-type-checker",
1415
]

crates/ditto-ast/src/utils.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,38 @@ impl Type {
114114
canonical_value,
115115
source_value: _,
116116
alias_variables: _,
117-
aliased_type: _,
117+
aliased_type,
118118
constructor_kind: _,
119119
} => {
120-
write!(w, "{canonical_value}")
120+
write!(w, "{canonical_value} / ")?;
121+
aliased_type.debug_render_to(w)
121122
}
122123
Self::PrimConstructor(prim) => {
123124
write!(w, "{prim}")
124125
}
126+
127+
Self::Call {
128+
function:
129+
box Self::ConstructorAlias {
130+
canonical_value,
131+
source_value: _,
132+
alias_variables: _,
133+
aliased_type,
134+
constructor_kind: _,
135+
},
136+
arguments,
137+
} => {
138+
write!(w, "{canonical_value}(")?;
139+
let arguments_len = arguments.len();
140+
for (i, arg) in arguments.iter().enumerate() {
141+
arg.debug_render_to(w)?;
142+
if i + 1 != arguments_len {
143+
write!(w, ", ")?;
144+
}
145+
}
146+
write!(w, ") / ")?;
147+
aliased_type.debug_render_to(w)
148+
}
125149
Self::Call {
126150
function,
127151
arguments,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "ditto-type-checker"
3+
version = "0.0.1"
4+
edition = "2021"
5+
license = "BSD-3-Clause"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
ditto-cst = { path = "../ditto-cst" }
12+
ditto-ast = { path = "../ditto-ast" }
13+
ditto-pattern-checker = { path = "../ditto-pattern-checker" }
14+
nonempty = "0.8"
15+
smallvec = "1.0"
16+
smol_str = "0.1"
17+
halfbrown = "0.1"
18+
indexmap = "1.9"
19+
serde = { version = "1.0", features = ["derive"] }
20+
miette = { version = "5.5", features = ["fancy"] }
21+
thiserror = "1.0"
22+
Inflector = "0.11.4"
23+
tracing = "0.1"
24+
tinyset = "0.4"
25+
26+
[dev-dependencies]
27+
datadriven = "0.6"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The ditto type checker
2+
3+
This crate handles type-checking and linting the ditto syntax.
4+
5+
The type-checking algorithm is based on [@david-christiansen](https://github.com/david-christiansen)'s [Bidirectional Typing Rules][bidirectional].
6+
7+
[bidirectional]: https://www.davidchristiansen.dk/tutorials/bidirectional.pdf
8+
[bidirectional impl]: https://github.com/luc-tielen/typesystem

0 commit comments

Comments
 (0)