This commit is contained in:
afonya2 2025-06-11 14:20:57 +02:00
parent 74fa0a8523
commit 0e0fee425a
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
2 changed files with 10 additions and 4 deletions

View file

@ -132,14 +132,14 @@ pub fn create_error(message: &str, position: usize, typ: ErrorType, stype: Error
fn get_exact_pos(file: &String, pos: usize) -> (usize, usize) {
let mut line = 1;
let mut column = 1;
let mut column = 0;
for (i, c) in file.char_indices() {
if i == pos {
return (line, column);
}
if c == '\n' {
line += 1;
column = 1;
column = 0;
} else {
column += 1;
}

View file

@ -48,6 +48,12 @@ fn is_sep(char: &str) -> bool {
let check = String::from(char) + next_char;
return chars.contains(&check.as_str());
}*/
fn is_str_start(input: &Vec<&str>, pos: &usize) -> bool {
if *pos + 5 >= input.len() {
return false;
}
return input[*pos-1..*pos+5].join("") == "szaft\"";
}
fn read_string(splitted: &Vec<&str>, pos: &mut usize, out: &mut Vec<Token>, ctx: &Context) {
let mut str = String::from("");
@ -131,7 +137,7 @@ fn read_identifier(splitted: &Vec<&str>, pos: &mut usize, out: &mut Vec<Token>)
while pos < &mut splitted.len() {
let prev_char = splitted[*pos-1];
let char = splitted[*pos];
if is_operator(char) || is_sep(char) || char == "\n" || char == "\r" || (prev_char == " " && is_number(char)) {
if is_operator(char) || is_sep(char) || char == "\n" || char == "\r" || (prev_char == " " && is_number(char)) || is_str_start(splitted, &(*pos+1)) {
break;
}
*pos += 1;
@ -238,7 +244,7 @@ pub fn lex(input: String, ctx: &Context) -> Vec<Token> {
}
pos -= 1;
out.push(Token { typ: TokenType::NUMBER, value: num, pos: start_pos });
} else if splitted.len() >= pos+5 && splitted[(pos-1)..(pos+5)].join("") == "szaft\"" {
} else if is_str_start(&splitted, &pos) {
read_string(&splitted, &mut pos, &mut out, ctx);
} else if splitted.len() >= pos+1 && splitted[(pos-1)..(pos+1)].join("") == "//" {
read_comment(&splitted, &mut pos, false, ctx);