pub struct Capture { /* private fields */ }Expand description
What to do with the text a capture group matched: give it a scope, run patterns over it, or both.
A scope name converts into a Capture directly, so the common case is
.capture(1, "entity.name.function.demo").
§Examples
use textmate_lang::{Capture, Grammar, Match, Rule};
let json = Grammar::new("source.demo")
.pattern(
Match::new(r#"(import)\s+("[^"]*")"#)
.capture(1, "keyword.control.import.demo")
.capture(2, Capture::new().scope("string.quoted.demo").pattern(Rule::include("escapes"))),
)
.repository("escapes", textmate_lang::Match::new(r"\\.").scope("constant.character.escape.demo"))
.to_json()?;
assert!(json.contains(r#""2": {"#));Implementations§
Source§impl Capture
impl Capture
Sourcepub fn new() -> Capture
pub fn new() -> Capture
A capture that does nothing until given a scope or patterns.
§Examples
use textmate_lang::Capture;
let capture = Capture::new().scope("variable.parameter.demo");
assert_eq!(capture, Capture::from("variable.parameter.demo"));Sourcepub fn scope(self, scope: impl Into<Cow<'static, str>>) -> Capture
pub fn scope(self, scope: impl Into<Cow<'static, str>>) -> Capture
Scopes the captured text ("name"). May substitute captured text
with $n, ${n:/downcase}, or ${n:/upcase}.
| Parameter | Meaning |
|---|---|
scope | One scope name, or several separated by single spaces. |
§Examples
use textmate_lang::{Capture, Grammar, Match};
let json = Grammar::new("source.demo")
.pattern(Match::new(r"(\w+)!").capture(1, Capture::new().scope("support.function.$1.demo")))
.to_json()?;
assert!(json.contains("support.function.$1.demo"));Sourcepub fn pattern(self, rule: impl Into<Rule>) -> Capture
pub fn pattern(self, rule: impl Into<Rule>) -> Capture
Adds a rule run over the captured text ("patterns"), to highlight
inside it.
| Parameter | Meaning |
|---|---|
rule | The rule to add. |
§Examples
use textmate_lang::{Capture, Grammar, Match};
let json = Grammar::new("source.demo")
.pattern(
Match::new(r"@(\w+(?:\.\w+)*)")
.capture(1, Capture::new().pattern(Match::new(r"\.").scope("punctuation.separator.demo"))),
)
.to_json()?;
assert!(json.contains("punctuation.separator.demo"));Trait Implementations§
impl Eq for Capture
impl StructuralPartialEq for Capture
Auto Trait Implementations§
impl Freeze for Capture
impl RefUnwindSafe for Capture
impl Send for Capture
impl Sync for Capture
impl Unpin for Capture
impl UnsafeUnpin for Capture
impl UnwindSafe for Capture
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more