Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
},
"rust-analyzer.check.command": "clippy"
}
21 changes: 19 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,11 @@ pub fn parse_with_depth<'input>(
let root = parse_binary_op(&mut lexer, &mut pt, &mut arg_scratch, 0, depth)?;

// Make sure we've completely parsed the input
if let Ok(Some(tok)) = lexer.next_token() {
if let Ok(Some(tok)) = lexer.next_token()
// Codebase stops parsing when it hits an unmatch right paren; this would
// normally be a bug, but when it is the last char it's acceptable.
&& !(tok.ty == TokenType::ParenRight && lexer.is_empty())
{
Err(Error::UnexpectedToken(tok))
} else {
Ok((pt, root))
Expand All @@ -399,7 +403,11 @@ pub fn parse_into_tree<'input>(
let root_id = tree.push_expr(root);

// Make sure we've completely parsed the input
if let Ok(Some(tok)) = lexer.next_token() {
if let Ok(Some(tok)) = lexer.next_token()
// Codebase stops parsing when it hits an unmatch right paren; this would
// normally be a bug, but when it is the last char it's acceptable.
&& !(tok.ty == TokenType::ParenRight && lexer.is_empty())
{
Err(Error::UnexpectedToken(tok))
} else {
Ok(root_id)
Expand Down Expand Up @@ -1006,4 +1014,13 @@ mod tests {
"expected MissingCloseParen, got {res:?}"
);
}

#[test]
fn final_trailing_right_paren() {
let (_, _) = parse(r#".t.)"#).expect("a valid parse");
let res = parse(r#".t.))"#);
Comment thread
jwhear marked this conversation as resolved.
let Err(Error::UnexpectedToken(_)) = res else {
panic!("Expected an UnexpectedToken")
};
}
}