Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Develop #6

Merged
merged 2 commits into from
Dec 21, 2024
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
148 changes: 83 additions & 65 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,70 @@ impl<'a> Lexer<'a> {

let c = self.advance();
match c {
'i' | 'u' => {
let type_prefix = c;
let start = self.current - 1;

// Collect all numeric characters
let mut number_str = String::new();
while !self.is_at_end() && self.peek().is_numeric() {
number_str.push(self.advance());
}

if !number_str.is_empty() {
let type_str = format!("{}{}", type_prefix, number_str);

// Handle integer types (i and u prefixes)
if type_prefix == 'i' || type_prefix == 'u' {
match type_str.as_str() {
// Signed integer types (i)
"isz" => return self.create_int_token(IntegerType::ISZ, type_str),
"i4" => return self.create_int_token(IntegerType::I4, type_str),
"i8" => return self.create_int_token(IntegerType::I8, type_str),
"i16" => return self.create_int_token(IntegerType::I16, type_str),
"i32" => return self.create_int_token(IntegerType::I32, type_str),
"i64" => return self.create_int_token(IntegerType::I64, type_str),
"i128" => return self.create_int_token(IntegerType::I128, type_str),
"i256" => return self.create_int_token(IntegerType::I256, type_str),
"i512" => return self.create_int_token(IntegerType::I512, type_str),
"i1024" => return self.create_int_token(IntegerType::I1024, type_str),
"i2048" => return self.create_int_token(IntegerType::I2048, type_str),
"i4096" => return self.create_int_token(IntegerType::I4096, type_str),
"i8192" => return self.create_int_token(IntegerType::I8192, type_str),
"i16384" => return self.create_int_token(IntegerType::I16384, type_str),
"i32768" => return self.create_int_token(IntegerType::I32768, type_str),

// Unsigned integer types (u)
"usz" => return self.create_int_token(IntegerType::USZ, type_str),
"u4" => return self.create_int_token(IntegerType::U4, type_str),
"u8" => return self.create_int_token(IntegerType::U8, type_str),
"u16" => return self.create_int_token(IntegerType::U16, type_str),
"u32" => return self.create_int_token(IntegerType::U32, type_str),
"u64" => return self.create_int_token(IntegerType::U64, type_str),
"u128" => return self.create_int_token(IntegerType::U128, type_str),
"u256" => return self.create_int_token(IntegerType::U256, type_str),
"u512" => return self.create_int_token(IntegerType::U512, type_str),
"u1024" => return self.create_int_token(IntegerType::U1024, type_str),
"u2048" => return self.create_int_token(IntegerType::U2048, type_str),
"u4096" => return self.create_int_token(IntegerType::U4096, type_str),
"u8192" => return self.create_int_token(IntegerType::U8192, type_str),
"u16384" => return self.create_int_token(IntegerType::U16384, type_str),
"u32768" => return self.create_int_token(IntegerType::U32768, type_str),

_ => {
self.current = start;
let identifier = self.identifier();
return self.create_identifier_token(identifier);
}
}
}
}

// If we get here, treat as identifier
self.current = start;
let identifier = self.identifier();
return self.create_identifier_token(identifier);
},
'+' => {
if self.match_next('+') {
Token {
Expand Down Expand Up @@ -616,7 +680,7 @@ impl<'a> Lexer<'a> {
line: self.line,
};
},
'i' | 'u' | 'f' => {
'f' => {
let type_prefix = c;
let start = self.current - 1;

Expand All @@ -629,70 +693,24 @@ impl<'a> Lexer<'a> {
if !number_str.is_empty() {
let type_str = format!("{}{}", type_prefix, number_str);

// Handle integer types (i and u prefixes)
if type_prefix == 'i' || type_prefix == 'u' {
match type_str.as_str() {
// Signed integer types
"isz" => return self.create_int_token(IntegerType::ISZ, type_str),
"i4" => return self.create_int_token(IntegerType::I4, type_str),
"i8" => return self.create_int_token(IntegerType::I8, type_str),
"i16" => return self.create_int_token(IntegerType::I16, type_str),
"i32" => return self.create_int_token(IntegerType::I32, type_str),
"i64" => return self.create_int_token(IntegerType::I64, type_str),
"i128" => return self.create_int_token(IntegerType::I128, type_str),
"i256" => return self.create_int_token(IntegerType::I256, type_str),
"i512" => return self.create_int_token(IntegerType::I512, type_str),
"i1024" => return self.create_int_token(IntegerType::I1024, type_str),
"i2048" => return self.create_int_token(IntegerType::I2048, type_str),
"i4096" => return self.create_int_token(IntegerType::I4096, type_str),
"i8192" => return self.create_int_token(IntegerType::I8192, type_str),
"i16384" => return self.create_int_token(IntegerType::I16384, type_str),
"i32768" => return self.create_int_token(IntegerType::I32768, type_str),

// Unsigned integer types
"usz" => return self.create_int_token(IntegerType::USZ, type_str),
"u4" => return self.create_int_token(IntegerType::U4, type_str),
"u8" => return self.create_int_token(IntegerType::U8, type_str),
"u16" => return self.create_int_token(IntegerType::U16, type_str),
"u32" => return self.create_int_token(IntegerType::U32, type_str),
"u64" => return self.create_int_token(IntegerType::U64, type_str),
"u128" => return self.create_int_token(IntegerType::U128, type_str),
"u256" => return self.create_int_token(IntegerType::U256, type_str),
"u512" => return self.create_int_token(IntegerType::U512, type_str),
"u1024" => return self.create_int_token(IntegerType::U1024, type_str),
"u2048" => return self.create_int_token(IntegerType::U2048, type_str),
"u4096" => return self.create_int_token(IntegerType::U4096, type_str),
"u8192" => return self.create_int_token(IntegerType::U8192, type_str),
"u16384" => return self.create_int_token(IntegerType::U16384, type_str),
"u32768" => return self.create_int_token(IntegerType::U32768, type_str),

_ => {
self.current = start;
let identifier = self.identifier();
return self.create_identifier_token(identifier);
}
}
}
// Handle float types
else if type_prefix == 'f' {
match type_str.as_str() {
"f32" => return self.create_float_token(FloatType::F32, type_str),
"f64" => return self.create_float_token(FloatType::F64, type_str),
"f128" => return self.create_float_token(FloatType::F128, type_str),
"f256" => return self.create_float_token(FloatType::F256, type_str),
"f512" => return self.create_float_token(FloatType::F512, type_str),
"f1024" => return self.create_float_token(FloatType::F1024, type_str),
"f2048" => return self.create_float_token(FloatType::F2048, type_str),
"f4096" => return self.create_float_token(FloatType::F4096, type_str),
"f8192" => return self.create_float_token(FloatType::F8192, type_str),
"f16384" => return self.create_float_token(FloatType::F16384, type_str),
"f32768" => return self.create_float_token(FloatType::F32768, type_str),

_ => {
self.current = start;
let identifier = self.identifier();
return self.create_identifier_token(identifier);
}
// Handle float types (f prefix)
match type_str.as_str() {
"f32" => return self.create_float_token(FloatType::F32, type_str),
"f64" => return self.create_float_token(FloatType::F64, type_str),
"f128" => return self.create_float_token(FloatType::F128, type_str),
"f256" => return self.create_float_token(FloatType::F256, type_str),
"f512" => return self.create_float_token(FloatType::F512, type_str),
"f1024" => return self.create_float_token(FloatType::F1024, type_str),
"f2048" => return self.create_float_token(FloatType::F2048, type_str),
"f4096" => return self.create_float_token(FloatType::F4096, type_str),
"f8192" => return self.create_float_token(FloatType::F8192, type_str),
"f16384" => return self.create_float_token(FloatType::F16384, type_str),
"f32768" => return self.create_float_token(FloatType::F32768, type_str),

_ => {
self.current = start;
let identifier = self.identifier();
return self.create_identifier_token(identifier);
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion test.wave
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fun main() {
var a: i32 = 10;
println("Hello World {}", a);
println("Hello World {}");
if (a == 10) {
println("fjf");
} else if (a > 10) {
Expand All @@ -9,4 +9,8 @@ fun main() {
println("ewe");
}

for (var i :i32; i <= 10; i++) {
println("{}", i);
}

}
Loading