From cb9b399869250b05ee0e18bc301136cfea743bc2 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Thu, 3 Oct 2024 10:52:44 +0200 Subject: [PATCH] Add support for `%error` hooks Closes #145. --- Cargo.lock | 2 +- corpus/unit.spicy | 7 +++++++ corpus/unit.spicy.expected | 7 +++++++ src/query.scm | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 24660d0..e59e9e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,7 +1104,7 @@ dependencies = [ [[package]] name = "tree-sitter-spicy" version = "0.0.1" -source = "git+https://github.com/bbannier/tree-sitter-spicy#6f5be56dc1f822d034b2320ff9bb1258b8881694" +source = "git+https://github.com/bbannier/tree-sitter-spicy#97a998e5d07a53f5b7f4e05d386ae58676699960" dependencies = [ "cc", "tree-sitter", diff --git a/corpus/unit.spicy b/corpus/unit.spicy index ac0174c..ec384a0 100644 --- a/corpus/unit.spicy +++ b/corpus/unit.spicy @@ -159,3 +159,10 @@ on X::Y::%error {} # Debug hooks. on X::Y::%done %debug {} on X::Y::%error (e: msg )%debug {} + +# Error hooks. +type Test = unit { + b: b"B" %error {} + on b %error {} +}; +on Test::b(msg: string) %error {} diff --git a/corpus/unit.spicy.expected b/corpus/unit.spicy.expected index 1b23615..67907d4 100644 --- a/corpus/unit.spicy.expected +++ b/corpus/unit.spicy.expected @@ -184,3 +184,10 @@ on X::Y::%error {} # Debug hooks. on X::Y::%done %debug {} on X::Y::%error(e: msg) %debug {} + +# Error hooks. +type Test = unit { + b: b"B" %error {} + on b %error {} +}; +on Test::b(msg: string) %error {} diff --git a/src/query.scm b/src/query.scm index 69c6632..b75effb 100644 --- a/src/query.scm +++ b/src/query.scm @@ -193,6 +193,7 @@ "on" "=" (is_debug) + (is_error) (hook_priority) ] @append_space @prepend_space