Skip to content

Commit

Permalink
♻️ Small code fixes
Browse files Browse the repository at this point in the history
semver: chore
  • Loading branch information
Somfic committed Jan 1, 2025
1 parent 294f482 commit 92cf721
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 44 deletions.
50 changes: 15 additions & 35 deletions src/parser/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ pub struct Type<'de> {

impl<'de> Type<'de> {
pub fn label(&self, text: impl Into<String>) -> Vec<miette::LabeledSpan> {
let mut labels = vec![];

labels.push(miette::LabeledSpan::at(self.span, text.into()));
let labels = vec![miette::LabeledSpan::at(self.span, text.into())];

if let Some(_original_span) = self.original_span {
// labels.push(miette::LabeledSpan::at(
Expand Down Expand Up @@ -154,57 +152,39 @@ impl<'de> TypeValue<'de> {
}

pub fn is_numeric(&self) -> bool {
match self {
TypeValue::Integer | TypeValue::Decimal => true,
_ => false,
}
matches!(self, TypeValue::Integer | TypeValue::Decimal)
}

pub fn is_primitive(&self) -> bool {
match self {
matches!(
self,
TypeValue::Unit
| TypeValue::Boolean
| TypeValue::Integer
| TypeValue::Decimal
| TypeValue::Character
| TypeValue::String => true,
_ => false,
}
| TypeValue::Boolean
| TypeValue::Integer
| TypeValue::Decimal
| TypeValue::Character
| TypeValue::String
)
}

pub fn is_collection(&self) -> bool {
match self {
TypeValue::Collection(_) => true,
_ => false,
}
matches!(self, TypeValue::Collection(_))
}

pub fn is_set(&self) -> bool {
match self {
TypeValue::Set(_) => true,
_ => false,
}
matches!(self, TypeValue::Set(_))
}

pub fn is_symbol(&self) -> bool {
match self {
TypeValue::Symbol(_) => true,
_ => false,
}
matches!(self, TypeValue::Symbol(_))
}

pub fn is_unit(&self) -> bool {
match self {
TypeValue::Unit => true,
_ => false,
}
matches!(self, TypeValue::Unit)
}

pub fn is_boolean(&self) -> bool {
match self {
TypeValue::Boolean => true,
_ => false,
}
matches!(self, TypeValue::Boolean)
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/parser/ast/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ pub enum BinaryOperator {
}
impl BinaryOperator {
pub fn is_comparison(&self) -> bool {
match self {
matches!(
self,
BinaryOperator::Equality
| BinaryOperator::Inequality
| BinaryOperator::LessThan
| BinaryOperator::LessThanOrEqual
| BinaryOperator::GreaterThan
| BinaryOperator::GreaterThanOrEqual => true,
_ => false,
}
| BinaryOperator::Inequality
| BinaryOperator::LessThan
| BinaryOperator::LessThanOrEqual
| BinaryOperator::GreaterThan
| BinaryOperator::GreaterThanOrEqual
)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/parser/typechecker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl<'env, 'ast> Environment<'env, 'ast> {
self.bindings.insert(name, ty);
}

fn get(&self, name: &Cow<'env, str>) -> Option<&Type<'ast>> {
fn get(&self, name: &str) -> Option<&Type<'ast>> {
self.bindings
.get(name)
.or_else(|| self.parent.and_then(|p| p.get(name)))
Expand Down

0 comments on commit 92cf721

Please sign in to comment.