Skip to content

Commit

Permalink
tui for errors like rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavier2p committed Sep 26, 2023
1 parent 0a23804 commit 9c97cc2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/helpers/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn error_to_string(error: &Error) -> &'static str {
Error::UnknownToken => "UnknownToken",
Error::UnexpectedToken => "UnexpectedToken",
Error::Critical => "Critical",
Error::TooCharactersOnLine => "TooCharacters",
Error::TooCharactersOnLine => "TooCharactersOnLine",
}
}

Expand Down
14 changes: 9 additions & 5 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ enum InQuote {
}

fn new_line(lines: &mut Vec<Vec<Token>>, tmp_line: &mut Vec<Token>, tmp_word: &mut String) {
new_word(tmp_line, tmp_word);
new_word(tmp_line, tmp_word, false);
if !tmp_line.is_empty() {
lines.push(tmp_line.clone());
}
tmp_line.clear();
}

fn new_word(tmp_line: &mut Vec<Token>, tmp_word: &mut String) {
fn new_word(tmp_line: &mut Vec<Token>, tmp_word: &mut String, is_string: bool) {
if !tmp_word.is_empty() {
tmp_line.push(Token::Other(tmp_word.clone()));
tmp_line.push(if is_string {
Token::String(tmp_word.clone())
} else {
Token::Other(tmp_word.clone())
});
tmp_word.clear();
}
}
Expand Down Expand Up @@ -55,7 +59,7 @@ pub fn tokenizer(file: &File) -> Program {
}
(InQuote::Double, '\"') | (InQuote::Single, '\'') => {
in_quote = InQuote::No;
new_word(&mut tmp_line, &mut tmp_word);
new_word(&mut tmp_line, &mut tmp_word, true);
}
_ => {
tmp_word.push(letter);
Expand All @@ -65,7 +69,7 @@ pub fn tokenizer(file: &File) -> Program {
' ' => {
// add support for commas
if in_quote == InQuote::No {
new_word(&mut tmp_line, &mut tmp_word);
new_word(&mut tmp_line, &mut tmp_word, false);
} else {
tmp_word.push(letter);
}
Expand Down

0 comments on commit 9c97cc2

Please sign in to comment.