diff --git a/src/errors.rs b/src/errors.rs index 514ad39..579e50f 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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; } diff --git a/src/lexer.rs b/src/lexer.rs index 33131f9..cd82689 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -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, ctx: &Context) { let mut str = String::from(""); @@ -131,7 +137,7 @@ fn read_identifier(splitted: &Vec<&str>, pos: &mut usize, out: &mut Vec) 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 { } 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);