diff --git a/src/lexer.rs b/src/lexer.rs index f1eb693..a1c3189 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -31,10 +31,20 @@ fn is_operator(char: &str) -> bool { let chars = vec!["+","-","*","/","^","%","|","&","!"]; return chars.contains(&char); } +fn is_mul_operator(char: &str, next_char: &str) -> bool { + let chars = vec!["==","!=","<=",">="]; + let check = String::from(char) + next_char; + return chars.contains(&check.as_str()); +} fn is_sep(char: &str) -> bool { let chars = vec!["(",")","[","]","{","}",",",".","="]; return chars.contains(&char); } +fn is_mul_sep(char: &str, next_char: &str) -> bool { + let chars = vec!["=>"]; + let check = String::from(char) + next_char; + return chars.contains(&check.as_str()); +} fn read_string(splitted: &Vec<&str>, pos: &mut usize, out: &mut Vec) { let mut str = String::from(""); @@ -227,8 +237,12 @@ pub fn lex(input: String) -> Vec { read_comment(&splitted, &mut pos, false); } else if splitted.len() >= pos+1 && splitted[(pos-1)..(pos+1)].join("") == "/*" { read_comment(&splitted, &mut pos, true); + } else if is_mul_operator(char, splitted[pos]) { + out.push(Token { typ: TokenType::OPERATOR, value: String::from(char) + splitted[pos], pos: pos-1 }); } else if is_operator(char) { out.push(Token { typ: TokenType::OPERATOR, value: String::from(char), pos: pos-1 }); + } else if is_mul_sep(char, splitted[pos]) { + out.push(Token { typ: TokenType::SEPARATOR, value: String::from(char) + splitted[pos], pos: pos-1 }); } else if is_sep(char) { out.push(Token { typ: TokenType::SEPARATOR, value: String::from(char), pos: pos-1 }); } else {