query: Return error on unclosed tree pattern in alternation
Fixes #1436
This commit is contained in:
parent
e78413832b
commit
ddb12dc0c6
2 changed files with 57 additions and 28 deletions
|
|
@ -78,6 +78,7 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
.join("\n")
|
||||
);
|
||||
|
||||
// Empty tree pattern
|
||||
assert_eq!(
|
||||
Query::new(language, r#"((identifier) ()"#)
|
||||
.unwrap_err()
|
||||
|
|
@ -88,6 +89,8 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
]
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// Empty alternation
|
||||
assert_eq!(
|
||||
Query::new(language, r#"((identifier) [])"#)
|
||||
.unwrap_err()
|
||||
|
|
@ -98,6 +101,8 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
]
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// Unclosed sibling expression with predicate
|
||||
assert_eq!(
|
||||
Query::new(language, r#"((identifier) (#a)"#)
|
||||
.unwrap_err()
|
||||
|
|
@ -108,6 +113,8 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
]
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// Unclosed predicate
|
||||
assert_eq!(
|
||||
Query::new(language, r#"((identifier) @x (#eq? @x a"#)
|
||||
.unwrap_err()
|
||||
|
|
@ -144,6 +151,7 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
.join("\n")
|
||||
);
|
||||
|
||||
// Unclosed alternation within a tree
|
||||
// tree-sitter/tree-sitter/issues/968
|
||||
assert_eq!(
|
||||
Query::new(get_language("c"), r#"(parameter_list [ ")" @foo)"#)
|
||||
|
|
@ -155,6 +163,22 @@ fn test_query_errors_on_invalid_syntax() {
|
|||
]
|
||||
.join("\n")
|
||||
);
|
||||
|
||||
// Unclosed tree within an alternation
|
||||
// tree-sitter/tree-sitter/issues/1436
|
||||
assert_eq!(
|
||||
Query::new(
|
||||
get_language("python"),
|
||||
r#"[(unary_operator (_) @operand) (not_operator (_) @operand]"#
|
||||
)
|
||||
.unwrap_err()
|
||||
.message,
|
||||
[
|
||||
r#"[(unary_operator (_) @operand) (not_operator (_) @operand]"#,
|
||||
r#" ^"#
|
||||
]
|
||||
.join("\n")
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue