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,10 +111,10 @@ 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();
|
||||||
@ -123,10 +122,13 @@ fn handle_quote(input: &mut CharIter) -> TokenType {
|
|||||||
} else if next == Some('"') {
|
} else if next == Some('"') {
|
||||||
input.next();
|
input.next();
|
||||||
buf.push('"');
|
buf.push('"');
|
||||||
|
} else if next == Some('t') {
|
||||||
|
input.next();
|
||||||
|
buf.push('\t');
|
||||||
}
|
}
|
||||||
//TODO handle more escapes
|
},
|
||||||
} else {
|
Some(c) => buf.push(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