-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
semver: chore
- Loading branch information
Showing
16 changed files
with
157 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use miette::SourceSpan; | ||
|
||
pub mod typed; | ||
pub mod untyped; | ||
|
||
pub trait Spannable<'de>: Sized { | ||
type Value; | ||
|
||
fn at(span: miette::SourceSpan, value: Self::Value) -> Self; | ||
|
||
fn at_multiple(spans: Vec<impl Into<miette::SourceSpan>>, value: Self::Value) -> Self { | ||
let spans = spans.into_iter().map(|s| s.into()).collect::<Vec<_>>(); | ||
|
||
let start = spans | ||
.iter() | ||
.min_by_key(|s| s.offset()) | ||
.map(|s| s.offset()) | ||
.unwrap_or(0); | ||
|
||
let end = spans | ||
.iter() | ||
.max_by_key(|s| s.offset() + s.len()) | ||
.map(|s| s.offset() + s.len()) | ||
.unwrap_or(0); | ||
|
||
let span = miette::SourceSpan::new(start.into(), end - start); | ||
|
||
Self::at(span, value) | ||
} | ||
} | ||
|
||
pub trait CombineSpan { | ||
fn combine(spans: Vec<SourceSpan>) -> SourceSpan { | ||
let start = spans | ||
.iter() | ||
.min_by_key(|s| s.offset()) | ||
.map(|s| s.offset()) | ||
.unwrap_or(0); | ||
|
||
let end = spans | ||
.iter() | ||
.max_by_key(|s| s.offset() + s.len()) | ||
.map(|s| s.offset() + s.len()) | ||
.unwrap_or(0); | ||
|
||
SourceSpan::new(start.into(), end - start) | ||
} | ||
} | ||
|
||
impl CombineSpan for SourceSpan {} | ||
|
||
impl<'de> Spannable<'de> for untyped::Expression<'de> { | ||
type Value = untyped::ExpressionValue<'de>; | ||
|
||
fn at(span: miette::SourceSpan, value: Self::Value) -> Self { | ||
Self { value, span } | ||
} | ||
} | ||
|
||
impl<'de> Spannable<'de> for untyped::Statement<'de> { | ||
type Value = untyped::StatementValue<'de>; | ||
|
||
fn at(span: miette::SourceSpan, value: Self::Value) -> Self { | ||
Self { value, span } | ||
} | ||
} | ||
|
||
impl<'de> Spannable<'de> for untyped::Type<'de> { | ||
type Value = untyped::TypeValue<'de>; | ||
|
||
fn at(span: miette::SourceSpan, value: Self::Value) -> Self { | ||
Self { value, span } | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use super::ast::{typed, untyped}; | ||
use miette::Result; | ||
|
||
pub struct TypeChecker<'de> { | ||
symbol: untyped::Symbol<'de>, | ||
} | ||
|
||
impl<'de> TypeChecker<'de> { | ||
pub fn new(symbol: untyped::Symbol<'de>) -> Self { | ||
Self { symbol } | ||
} | ||
|
||
pub fn check(&mut self) -> Result<typed::Symbol<'de>> { | ||
Ok(self.symbol.clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.