1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Decoration types for the syntax driver layer.
//!
//! This module provides types for declarative decoration rules that map
//! tree-sitter capture names to semantic categories. Language modules
//! provide these rules as data; the driver applies them mechanically.
//!
//! # Design
//!
//! ```text
//! Lang module (policy) → DecorationRule[] → TreeSitterDriver (mechanism)
//! ↓
//! DecorationCapture[] ← runs query
//! ↓
//! apply_rules() → Vec<Annotation>
//! ```
//!
//! No tree-sitter types appear here — this crate is parser-agnostic.
use Arc;
use crate::;
/// A declarative rule mapping a query capture name to a semantic category.
///
/// Language modules provide these to describe how tree-sitter captures
/// should be annotated. The driver applies them — no callbacks needed.
///
/// # Example
///
/// ```
/// use reovim_driver_syntax::{DecorationRule, HighlightCategory};
///
/// let rule = DecorationRule {
/// capture_name: "heading.1.marker".into(),
/// category: HighlightCategory::new("markup.heading.1"),
/// };
/// assert_eq!(rule.capture_name.as_ref(), "heading.1.marker");
/// ```
/// A raw capture from a decoration query (before rule application).
///
/// This is the intermediate representation between the query engine and
/// the final [`Annotation`]. Generic — no tree-sitter types.
///
/// # Example
///
/// ```
/// use reovim_driver_syntax::DecorationCapture;
///
/// let cap = DecorationCapture {
/// name: "heading.1.marker".into(),
/// start_byte: 0,
/// end_byte: 2,
/// };
/// assert_eq!(cap.name.as_ref(), "heading.1.marker");
/// assert_eq!(cap.byte_range(), 0..2);
/// ```
/// Apply decoration rules to raw captures, producing annotations.
///
/// For each capture, finds the first rule whose `capture_name` matches
/// the capture's `name`, and produces an [`Annotation`] with the rule's
/// category. Captures with no matching rule are skipped.
///
/// # Example
///
/// ```
/// use reovim_driver_syntax::{
/// DecorationCapture, DecorationRule, HighlightCategory,
/// decoration::apply_rules,
/// };
///
/// let rules = vec![
/// DecorationRule {
/// capture_name: "code_block".into(),
/// category: HighlightCategory::new("markup.raw.block"),
/// },
/// ];
///
/// let captures = vec![
/// DecorationCapture { name: "code_block".into(), start_byte: 10, end_byte: 50 },
/// DecorationCapture { name: "unknown".into(), start_byte: 60, end_byte: 70 },
/// ];
///
/// let annotations = apply_rules(&captures, &rules);
/// assert_eq!(annotations.len(), 1);
/// assert_eq!(annotations[0].start_byte, 10);
/// ```