Unclosed string
This commit is contained in:
parent
ac5bdd7bcb
commit
7fe0a6589e
@ -88,7 +88,6 @@ pub fn tokenize(input: &str) -> Vec<Token> {
|
|||||||
c @ '_' | c if c.is_alphabetic() => handle_alphabetic(c, &mut input),
|
c @ '_' | c if c.is_alphabetic() => handle_alphabetic(c, &mut input),
|
||||||
c => handle_operator(c, &mut input),
|
c => handle_operator(c, &mut input),
|
||||||
};
|
};
|
||||||
|
|
||||||
tokens.push(Token { token_type: cur_tok_type, offset: idx });
|
tokens.push(Token { token_type: cur_tok_type, offset: idx });
|
||||||
}
|
}
|
||||||
tokens
|
tokens
|
||||||
@ -112,21 +111,24 @@ fn handle_digit(c: char, input: &mut CharIter) -> TokenType {
|
|||||||
|
|
||||||
fn handle_quote(input: &mut CharIter) -> TokenType {
|
fn handle_quote(input: &mut CharIter) -> TokenType {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
while let Some(c) = input.next().map(|(_, c)| { c }) {
|
loop {
|
||||||
if c == '"' {
|
match input.next().map(|(_, c)| { c }) {
|
||||||
break;
|
Some('"') => break,
|
||||||
} else if c == '\\' {
|
Some('\\') => {
|
||||||
let next = input.peek().map(|&(_, c)| { c });
|
let next = input.peek().map(|&(_, c)| { c });
|
||||||
if next == Some('n') {
|
if next == Some('n') {
|
||||||
input.next();
|
input.next();
|
||||||
buf.push('\n')
|
buf.push('\n')
|
||||||
} else if next == Some('"') {
|
} else if next == Some('"') {
|
||||||
input.next();
|
input.next();
|
||||||
buf.push('"');
|
buf.push('"');
|
||||||
}
|
} else if next == Some('t') {
|
||||||
//TODO handle more escapes
|
input.next();
|
||||||
} else {
|
buf.push('\t');
|
||||||
buf.push(c);
|
}
|
||||||
|
},
|
||||||
|
Some(c) => buf.push(c),
|
||||||
|
None => return TokenType::Error(format!("Unclosed string")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TokenType::StrLiteral(Rc::new(buf))
|
TokenType::StrLiteral(Rc::new(buf))
|
||||||
|
Loading…
Reference in New Issue
Block a user