Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion front/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
colored = "2.0"
colorex = "0.1.1"
46 changes: 23 additions & 23 deletions front/error/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ impl WaveError {

/// Display error in Rust-style format
pub fn display(&self) {
use colored::*;
use colorex::Colorize;

let severity_str = match self.severity {
ErrorSeverity::Error => "error".red().bold(),
ErrorSeverity::Warning => "warning".yellow().bold(),
ErrorSeverity::Note => "note".cyan().bold(),
ErrorSeverity::Help => "help".green().bold(),
ErrorSeverity::Error => "error".color("255,71,71").bold(),
ErrorSeverity::Warning => "warning".color("145,161,2").bold(),
ErrorSeverity::Note => "note".color("0,255,255").bold(),
ErrorSeverity::Help => "help".color("38,139,235").bold(),
};

// Main error message
Expand All @@ -193,61 +193,61 @@ impl WaveError {
// Location
eprintln!(
" {} {}:{}:{}",
"-->".blue().bold(),
"-->".color("38,139,235").bold(),
self.file,
self.line,
self.column
);
eprintln!(" {}", "|".blue().bold());
eprintln!(" {}", "|".color("38,139,235").bold());

// Source code with highlighting
if let Some(source_line) = &self.source {
eprintln!(
"{:>3} {} {}",
self.line.to_string().blue().bold(),
"|".blue().bold(),
self.line.to_string().color("38,139,235").bold(),
"|".color("38,139,235").bold(),
source_line
);

// Arrow pointing to the error
let spaces = " ".repeat(self.column.saturating_sub(1));
let arrow = match self.severity {
ErrorSeverity::Error => "^".red().bold(),
ErrorSeverity::Warning => "^".yellow().bold(),
ErrorSeverity::Note => "^".cyan().bold(),
ErrorSeverity::Help => "^".green().bold(),
ErrorSeverity::Error => "^".color("255,71,71").bold(),
ErrorSeverity::Warning => "^".color("145,161,2").bold(),
ErrorSeverity::Note => "^".color("0,255,255").bold(),
ErrorSeverity::Help => "^".color("38,139,235").bold(),
};

if let Some(label) = &self.label {
eprintln!(
" {} {}{} {}",
"|".blue().bold(),
"|".color("38,139,235").bold(),
spaces,
arrow,
label.dimmed()
label.dim()
);
} else {
eprintln!(" {} {}{}", "|".blue().bold(), spaces, arrow);
eprintln!(" {} {}{}", "|".color("38,139,235").bold(), spaces, arrow);
}
}

eprintln!(" {}", "|".blue().bold());
eprintln!(" {}", "|".color("38,139,235").bold());

// Additional information
if let Some(note) = &self.note {
eprintln!(
" {} {}: {}",
"=".blue().bold(),
"note".cyan().bold(),
"=".color("38,139,235").bold(),
"note".color("0,255,255").bold(),
note
);
}

if let Some(help) = &self.help {
eprintln!(
" {} {}: {}",
"=".blue().bold(),
"help".green().bold(),
"=".color("38,139,235").bold(),
"help".color("38,139,235").bold(),
help
);
}
Expand All @@ -256,8 +256,8 @@ impl WaveError {
for suggestion in &self.suggestions {
eprintln!(
" {} {}: {}",
"=".blue().bold(),
"suggestion".green().bold(),
"=".color("38,139,235").bold(),
"suggestion".color("38,139,235").bold(),
suggestion
);
}
Expand Down
8 changes: 4 additions & 4 deletions front/lexer/src/lexer/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,10 @@ impl<'a> Lexer<'a> {
let value = i64::from_str_radix(&bin_str, 2).unwrap_or(0);

return Token {
token_type: TokenType::Number(value),
token_type: TokenType::IntLiteral(format!("0b{}", bin_str)),
lexeme: format!("0b{}", bin_str),
line: self.line,
}
};
}

if c == '0' && (self.peek() == 'x' || self.peek() == 'X') {
Expand All @@ -362,7 +362,7 @@ impl<'a> Lexer<'a> {
let value = i64::from_str_radix(&hex_str, 16).unwrap_or(0);

return Token {
token_type: TokenType::Number(value),
token_type: TokenType::IntLiteral(format!("0x{}", hex_str)),
lexeme: format!("0x{}", hex_str),
line: self.line,
};
Expand All @@ -387,7 +387,7 @@ impl<'a> Lexer<'a> {
let token_type = if is_float {
num_str.parse::<f64>().map(TokenType::Float).unwrap()
} else {
num_str.parse::<i64>().map(TokenType::Number).unwrap()
TokenType::IntLiteral(num_str.clone())
};

Token {
Expand Down
2 changes: 1 addition & 1 deletion front/lexer/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub enum TokenType {
TypeArray(Box<TokenType>, u32),
Identifier(String),
String(String),
Number(i64),
IntLiteral(String),
Float(f64),
Plus, // +
Increment, // ++
Expand Down
8 changes: 4 additions & 4 deletions front/parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub enum Expression {

#[derive(Debug, Clone)]
pub enum Literal {
Number(i64),
Int(String),
Float(f64),
String(String),
Bool(bool),
Expand Down Expand Up @@ -226,8 +226,8 @@ pub enum StatementNode {
},
AsmBlock {
instructions: Vec<String>,
inputs: Vec<(String, String)>,
outputs: Vec<(String, String)>,
inputs: Vec<(String, Expression)>,
outputs: Vec<(String, Expression)>,
},
Break,
Continue,
Expand Down Expand Up @@ -281,7 +281,7 @@ impl Expression {
.unwrap_or_else(|| panic!("Variable '{}' not found", name))
.ty
.clone(),
Expression::Literal(Literal::Number(_)) => WaveType::Int(32), // 기본 int
Expression::Literal(Literal::Int(_)) => WaveType::Int(32),
Expression::Literal(Literal::Float(_)) => WaveType::Float(32),
Expression::Literal(Literal::String(_)) => WaveType::String,
Expression::MethodCall { .. } => {
Expand Down
Loading