Skip to content

Commit

Permalink
🚧 WIP
Browse files Browse the repository at this point in the history
semver: chore
  • Loading branch information
Somfic committed Oct 30, 2024
1 parent 8f2aa93 commit 290acf3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ impl<'de> Iterator for Lexer<'de> {
"dec" => Ok((TokenKind::DecimalType, TokenValue::None)),
"str" => Ok((TokenKind::StringType, TokenValue::None)),
"char" => Ok((TokenKind::CharacterType, TokenValue::None)),
"()" => Ok((TokenKind::UnitType, TokenValue::None)),
ident => Ok((
TokenKind::Identifier,
TokenValue::Identifier(ident.to_string().into()),
Expand Down
3 changes: 0 additions & 3 deletions src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ pub enum TokenKind {
StringType,
/// The character type; `char`.
CharacterType,
/// The unit type; `()`.
UnitType,
}

impl Display for TokenKind {
Expand Down Expand Up @@ -239,7 +237,6 @@ impl Display for TokenKind {
TokenKind::DecimalType => write!(f, "a decimal type"),
TokenKind::StringType => write!(f, "a string type"),
TokenKind::CharacterType => write!(f, "a character type"),
TokenKind::UnitType => write!(f, "a unit type"),
}
}
}
39 changes: 25 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
use lexer::{Lexer, TokenKind};
use owo_colors::{Style, Styled};
use parser::Parser;
use passer::Passer;
use std::vec;

pub mod lexer;
pub mod parser;
pub mod passer;

fn main() {
let input = "
fn main() {
fib(9999);
}
fn fib(n ~ int) ~ int {
return if n < 2;
fib(n - 1) + fib(n - 20)
}
";

miette::set_hook(Box::new(|_| {
Box::new(
miette::MietteHandlerOpts::new()
Expand All @@ -30,6 +21,17 @@ fn main() {
}))
.unwrap();

let input = "
fn main() {
fib(9999);
}
fn fib(n ~ int) ~ int {
return n if n < 2;
fib(n - 1) + fib(n - 20)
}
";

let mut parser = Parser::new(input);
let symbol = match parser.parse() {
Ok(symbol) => symbol,
Expand All @@ -39,7 +41,15 @@ fn main() {
}
};

println!("{:?}", symbol);
let typing_pass = passer::typing::TypingPasser::pass(&symbol).unwrap();

for note in typing_pass.non_critical {
println!("{:?}", note.with_source_code(input.to_string()));
}

for note in typing_pass.critical {
println!("{:?}", note.with_source_code(input.to_string()));
}
}

struct SomHighlighter {}
Expand Down Expand Up @@ -80,8 +90,9 @@ impl miette::highlighters::HighlighterState for SomHighlighterState {
| TokenKind::DecimalType
| TokenKind::BooleanType
| TokenKind::StringType
| TokenKind::CharacterType
| TokenKind::UnitType => Style::new().fg_rgb::<86, 156, 214>().italic(),
| TokenKind::CharacterType => {
Style::new().fg_rgb::<86, 156, 214>().italic()
}
TokenKind::Equal
| TokenKind::LessThan
| TokenKind::GreaterThan
Expand Down
2 changes: 1 addition & 1 deletion src/parser/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Default for Lookup<'_> {
.add_statement_handler(TokenKind::Function, statement::function_)
.add_statement_handler(TokenKind::Trait, statement::trait_)
.add_type_handler(TokenKind::Identifier, typing::identifier)
.add_type_handler(TokenKind::UnitType, typing::unit)
.add_type_handler(TokenKind::ParenOpen, typing::unit)
.add_type_handler(TokenKind::CharacterType, typing::character)
.add_type_handler(TokenKind::BooleanType, typing::boolean)
.add_type_handler(TokenKind::IntegerType, typing::integer)
Expand Down
6 changes: 5 additions & 1 deletion src/parser/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ pub fn parse<'de>(parser: &mut Parser<'de>, binding_power: BindingPower) -> Resu
pub fn unit<'de>(parser: &mut Parser<'de>) -> Result<Type<'de>> {
parser
.lexer
.expect(TokenKind::UnitType, "expected an unit type")?;
.expect(TokenKind::ParenOpen, "expected an opening parenthesis")?;

parser
.lexer
.expect(TokenKind::ParenClose, "expected a closing parenthesis")?;

Ok(Type::Unit)
}
Expand Down
13 changes: 13 additions & 0 deletions src/passer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::parser::ast::Symbol;
use miette::{Report, Result};

pub mod typing;

pub trait Passer {
fn pass(ast: &Symbol<'_>) -> Result<PasserResult>;
}

pub struct PasserResult {
pub non_critical: Vec<Report>,
pub critical: Vec<Report>,
}
23 changes: 23 additions & 0 deletions src/passer/typing/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use super::{Passer, PasserResult};
use crate::parser::ast::Symbol;
use miette::{Result, Severity};

pub struct TypingPasser;

impl Passer for TypingPasser {
fn pass(ast: &Symbol<'_>) -> Result<PasserResult> {
let mut critical = vec![];
let mut non_critical = vec![];

non_critical.push(miette::miette! {
severity = Severity::Warning,
labels = vec![miette::LabeledSpan::at(100, "uwu")],
"Typing is not yet implemented"
});

Ok(PasserResult {
critical,
non_critical,
})
}
}

0 comments on commit 290acf3

Please sign in to comment.