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
3 changes: 3 additions & 0 deletions crates/plotnik-lib/src/diagnostics/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum DiagnosticKind {
UndefinedReference,
MixedAltBranches,
RecursionNoEscape,
DirectRecursion,
FieldSequenceValue,

// Link pass - grammar validation
Expand Down Expand Up @@ -162,6 +163,7 @@ impl DiagnosticKind {
Self::UndefinedReference => "undefined reference",
Self::MixedAltBranches => "cannot mix labeled and unlabeled branches",
Self::RecursionNoEscape => "infinite recursion detected",
Self::DirectRecursion => "direct recursion: query will stuck without matching anything",
Self::FieldSequenceValue => "field must match exactly one node",

// Link pass - grammar validation
Expand Down Expand Up @@ -200,6 +202,7 @@ impl DiagnosticKind {

// Recursion with cycle path
Self::RecursionNoEscape => "infinite recursion: {}".to_string(),
Self::DirectRecursion => "direct recursion: {}".to_string(),

// Alternation mixing
Self::MixedAltBranches => "cannot mix labeled and unlabeled branches: {}".to_string(),
Expand Down
27 changes: 26 additions & 1 deletion crates/plotnik-lib/src/query/link_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,13 @@ fn ref_followed_recursive_with_invalid_type() {
| ---- field `name` on `function_declaration`
|
help: valid types for `name`: `identifier`

error: direct recursion: cycle `Foo` → `Foo` will stuck without matching anything
|
1 | Foo = [(number) (Foo)]
| ^^^
| |
| `Foo` references itself
");
}

Expand All @@ -941,7 +948,15 @@ fn ref_followed_recursive_valid() {
let mut query = Query::try_from(input).unwrap();
query.link(&plotnik_langs::javascript());

assert!(query.is_valid());
assert!(!query.is_valid());
insta::assert_snapshot!(query.dump_diagnostics(), @r"
error: direct recursion: cycle `Foo` → `Foo` will stuck without matching anything
|
1 | Foo = [(identifier) (Foo)]
| ^^^
| |
| `Foo` references itself
");
}

#[test]
Expand Down Expand Up @@ -975,6 +990,16 @@ fn ref_followed_mutual_recursion() {
| ---- field `name` on `function_declaration`
|
help: valid types for `name`: `identifier`

error: direct recursion: cycle `Bar` → `Foo` → `Bar` will stuck without matching anything
|
1 | Foo = [(number) (Bar)]
| --- `Foo` references `Bar` (completing cycle)
2 | Bar = [(string) (Foo)]
| --- ^^^
| | |
| | `Bar` references `Foo`
| `Bar` is defined here
");
}

Expand Down
Loading