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

Commit

Permalink
wip: ditto-type-checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie committed Mar 14, 2023
1 parent 66e3b30 commit b4afa7a
Show file tree
Hide file tree
Showing 38 changed files with 5,236 additions and 4 deletions.
55 changes: 53 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ members = [
"crates/ditto-tree-sitter",
"crates/ditto-highlight",
"crates/ditto-pattern-checker",
"crates/ditto-type-checker",
]
28 changes: 26 additions & 2 deletions crates/ditto-ast/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,38 @@ impl Type {
canonical_value,
source_value: _,
alias_variables: _,
aliased_type: _,
aliased_type,
constructor_kind: _,
} => {
write!(w, "{canonical_value}")
write!(w, "{canonical_value} / ")?;
aliased_type.debug_render_to(w)
}
Self::PrimConstructor(prim) => {
write!(w, "{prim}")
}

Self::Call {
function:
box Self::ConstructorAlias {
canonical_value,
source_value: _,
alias_variables: _,
aliased_type,
constructor_kind: _,
},
arguments,
} => {
write!(w, "{canonical_value}(")?;
let arguments_len = arguments.len();
for (i, arg) in arguments.iter().enumerate() {
arg.debug_render_to(w)?;
if i + 1 != arguments_len {
write!(w, ", ")?;
}
}
write!(w, ") / ")?;
aliased_type.debug_render_to(w)
}
Self::Call {
function,
arguments,
Expand Down
27 changes: 27 additions & 0 deletions crates/ditto-type-checker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "ditto-type-checker"
version = "0.0.1"
edition = "2021"
license = "BSD-3-Clause"

[lib]
doctest = false

[dependencies]
ditto-cst = { path = "../ditto-cst" }
ditto-ast = { path = "../ditto-ast" }
ditto-pattern-checker = { path = "../ditto-pattern-checker" }
nonempty = "0.8"
smallvec = "1.0"
smol_str = "0.1"
halfbrown = "0.1"
indexmap = "1.9"
serde = { version = "1.0", features = ["derive"] }
miette = { version = "5.5", features = ["fancy"] }
thiserror = "1.0"
Inflector = "0.11.4"
tracing = "0.1"
tinyset = "0.4"

[dev-dependencies]
datadriven = "0.6"
8 changes: 8 additions & 0 deletions crates/ditto-type-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The ditto type checker

This crate handles type-checking and linting the ditto syntax.

The type-checking algorithm is based on [@david-christiansen](https://github.com/david-christiansen)'s [Bidirectional Typing Rules][bidirectional].

[bidirectional]: https://www.davidchristiansen.dk/tutorials/bidirectional.pdf
[bidirectional impl]: https://github.com/luc-tielen/typesystem
Loading

0 comments on commit b4afa7a

Please sign in to comment.