Skip to content

Commit

Permalink
Merge pull request #162 from Glyphack/init-type-checker
Browse files Browse the repository at this point in the history
Create type checker structs
  • Loading branch information
Glyphack authored Aug 29, 2023
2 parents 11b54eb + 7f8ef87 commit e508bbc
Show file tree
Hide file tree
Showing 24 changed files with 1,316 additions and 249 deletions.
6 changes: 3 additions & 3 deletions parser/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Lexer {
}
}
3 => {
if curr == str_finisher.chars().nth(0).unwrap()
if curr == str_finisher.chars().next().unwrap()
&& self.peek() == Some(str_finisher.chars().nth(1).unwrap())
&& self.double_peek() == Some(str_finisher.chars().nth(2).unwrap())
{
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Lexer {
}
}
3 => {
if peeked_char == str_finisher.chars().nth(0).unwrap()
if peeked_char == str_finisher.chars().next().unwrap()
&& self.double_peek() == Some(str_finisher.chars().nth(1).unwrap())
&& self.triple_peek() == Some(str_finisher.chars().nth(2).unwrap())
{
Expand All @@ -160,7 +160,7 @@ impl Lexer {
return Ok(indent_kind);
}
}
if self.fstring_stack.len() > 0 {
if !self.fstring_stack.is_empty() {
if let Some(kind) = self.next_fstring_token() {
return Ok(kind);
}
Expand Down
26 changes: 24 additions & 2 deletions parser/src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ trait GetNode {
impl From<Node> for SourceSpan {
fn from(val: Node) -> Self {
Self::new(
SourceOffset::from(val.start as usize),
SourceOffset::from(val.len() as usize),
SourceOffset::from(val.start),
SourceOffset::from(val.len()),
)
}
}
Expand Down Expand Up @@ -395,6 +395,28 @@ pub enum BinaryOperator {
FloorDiv,
}

impl std::fmt::Display for BinaryOperator {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let op_str = match self {
BinaryOperator::Add => "+",
BinaryOperator::Sub => "-",
BinaryOperator::Mult => "*",
BinaryOperator::MatMult => "@",
BinaryOperator::Div => "/",
BinaryOperator::Mod => "%",
BinaryOperator::Pow => "**",
BinaryOperator::LShift => "<<",
BinaryOperator::RShift => ">>",
BinaryOperator::BitOr => "|",
BinaryOperator::BitXor => "^",
BinaryOperator::BitAnd => "&",
BinaryOperator::FloorDiv => "//",
};

write!(f, "{}", op_str)
}
}

// https://docs.python.org/3/library/ast.html#ast.NamedExpr
#[derive(Debug, Clone)]
pub struct NamedExpression {
Expand Down
2 changes: 1 addition & 1 deletion parser/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{parser::ast::Node, token::Kind};
use crate::{parser::ast::Node};
use miette::{self, Diagnostic};
use thiserror::{self, Error};

Expand Down
2 changes: 1 addition & 1 deletion parser/src/parser/operator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::parser::ast::{BinaryOperator, BooleanOperator, UnaryOperator};
use crate::parser::ast::{BooleanOperator, UnaryOperator};
use crate::token::Kind;

pub fn is_bool_op(kind: &Kind) -> bool {
Expand Down
Loading

0 comments on commit e508bbc

Please sign in to comment.