Merge ba8c6a56cb
into 802bfed173
This commit is contained in:
commit
abae16e353
|
@ -31,7 +31,7 @@ impl Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum BlockKind {
|
pub enum BlockKind {
|
||||||
Paren,
|
Paren,
|
||||||
CurlyBracket,
|
CurlyBracket,
|
||||||
|
@ -101,6 +101,9 @@ pub fn lex_item(
|
||||||
|
|
||||||
let token_start = *curr_offset;
|
let token_start = *curr_offset;
|
||||||
|
|
||||||
|
let mut string_interpolation = false;
|
||||||
|
let mut inter_bracket = false;
|
||||||
|
|
||||||
// This Vec tracks paired delimiters
|
// This Vec tracks paired delimiters
|
||||||
let mut block_level: Vec<BlockKind> = vec![];
|
let mut block_level: Vec<BlockKind> = vec![];
|
||||||
|
|
||||||
|
@ -140,12 +143,18 @@ pub fn lex_item(
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
} else if c == b'(' && string_interpolation {
|
||||||
|
inter_bracket = true;
|
||||||
|
} else if c == b')' && string_interpolation {
|
||||||
|
inter_bracket = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we encountered the closing quote character for the current
|
// If we encountered the closing quote character for the current
|
||||||
// string, we're done with the current string.
|
// string, we're done with the current string.
|
||||||
if c == start {
|
if c == start && (!string_interpolation || !inter_bracket) {
|
||||||
// Also need to check to make sure we aren't escaped
|
// Also need to check to make sure we aren't escaped
|
||||||
quote_start = None;
|
quote_start = None;
|
||||||
|
string_interpolation = false;
|
||||||
}
|
}
|
||||||
} else if c == b'#' {
|
} else if c == b'#' {
|
||||||
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) {
|
||||||
|
@ -164,7 +173,13 @@ pub fn lex_item(
|
||||||
} else if is_special_item(&block_level, c, special_tokens) && token_start == *curr_offset {
|
} else if is_special_item(&block_level, c, special_tokens) && token_start == *curr_offset {
|
||||||
*curr_offset += 1;
|
*curr_offset += 1;
|
||||||
break;
|
break;
|
||||||
} else if c == b'\'' || c == b'"' || c == b'`' {
|
} else if (c == b'\'' || c == b'"' || c == b'`') && quote_start.is_none() {
|
||||||
|
if *curr_offset > 0
|
||||||
|
&& input.get(*curr_offset - 1) == Some(&b'$')
|
||||||
|
&& (c == b'\'' || c == b'"')
|
||||||
|
{
|
||||||
|
string_interpolation = true;
|
||||||
|
}
|
||||||
// We encountered the opening quote of a string literal.
|
// We encountered the opening quote of a string literal.
|
||||||
quote_start = Some(c);
|
quote_start = Some(c);
|
||||||
} else if c == b'[' {
|
} else if c == b'[' {
|
||||||
|
|
|
@ -187,6 +187,13 @@ fn lex_incomplete_quote() {
|
||||||
assert!(matches!(err, ParseError::UnexpectedEof(v, _) if v == "'"));
|
assert!(matches!(err, ParseError::UnexpectedEof(v, _) if v == "'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn lex_odd_string_interpolations() {
|
||||||
|
let file = b"$\"('\"')\"";
|
||||||
|
let output = lex(file, 0, &[], &[], true);
|
||||||
|
assert!(output.1.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lex_comments_no_space() {
|
fn lex_comments_no_space() {
|
||||||
// test for parses that contain tokens that normally introduce comments
|
// test for parses that contain tokens that normally introduce comments
|
||||||
|
|
Loading…
Reference in New Issue
Block a user