pub struct BeginEnd { /* private fields */ }Expand description
A region from a begin match to an end match ("begin"/"end").
Between the two, the region’s own patterns apply
instead of the surrounding ones. Numbered back-references in end
(\1) stand for the text the begin groups captured, which is how a
heredoc or a raw string ends with its opening delimiter.
§Examples
use textmate_lang::{BeginEnd, Grammar, Match};
let string = BeginEnd::new("\"", "\"")
.scope("string.quoted.double.demo")
.begin_capture(0, "punctuation.definition.string.begin.demo")
.end_capture(0, "punctuation.definition.string.end.demo")
.pattern(Match::new(r"\\.").scope("constant.character.escape.demo"));
let raw = BeginEnd::new(r#"r(#*)""#, r#""\1"#).scope("string.quoted.raw.demo");
let json = Grammar::new("source.demo").pattern(string).pattern(raw).to_json()?;
assert!(json.contains(r#""end": "\"\\1""#));Implementations§
Source§impl BeginEnd
impl BeginEnd
Sourcepub fn new(
begin: impl Into<Cow<'static, str>>,
end: impl Into<Cow<'static, str>>,
) -> BeginEnd
pub fn new( begin: impl Into<Cow<'static, str>>, end: impl Into<Cow<'static, str>>, ) -> BeginEnd
A region from a match of begin to the next match of end.
| Parameter | Meaning |
|---|---|
begin | The pattern that opens the region. |
end | The pattern that closes it; \n back-references name begin groups. |
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new(r"/\*", r"\*/").scope("comment.block.demo"))
.to_json()?;
assert!(json.contains(r#""begin": "/\\*""#));Sourcepub fn scope(self, scope: impl Into<Cow<'static, str>>) -> BeginEnd
pub fn scope(self, scope: impl Into<Cow<'static, str>>) -> BeginEnd
Scopes the whole region, delimiters included ("name"). $n
substitutions name begin groups.
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new(r"\(", r"\)").scope("meta.parens.demo"))
.to_json()?;
assert!(json.contains("meta.parens.demo"));Sourcepub fn content_scope(self, scope: impl Into<Cow<'static, str>>) -> BeginEnd
pub fn content_scope(self, scope: impl Into<Cow<'static, str>>) -> BeginEnd
Scopes the text between the delimiters only ("contentName"). $n
substitutions name begin groups.
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new("```(\\w+)", "```").content_scope("meta.embedded.block.$1"))
.to_json()?;
assert!(json.contains(r#""contentName": "meta.embedded.block.$1""#));Sourcepub fn capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
pub fn capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
Sets capture group for both begin and end ("captures").
Ignored for a side that has its own captures; the group must exist in
each pattern it applies to.
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new(r"\[", r"\]").capture(0, "punctuation.brackets.demo"))
.to_json()?;
assert!(json.contains(r#""captures": {"#));Sourcepub fn begin_capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
pub fn begin_capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
Sets capture group of begin ("beginCaptures").
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new(r"(<)(\w+)", "/>").begin_capture(2, "entity.name.tag.demo"))
.to_json()?;
assert!(json.contains(r#""beginCaptures": {"#));Sourcepub fn end_capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
pub fn end_capture(self, group: u32, capture: impl Into<Capture>) -> BeginEnd
Sets capture group of end ("endCaptures").
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new("<<", "(>>)").end_capture(1, "punctuation.demo"))
.to_json()?;
assert!(json.contains(r#""endCaptures": {"#));Sourcepub fn pattern(self, rule: impl Into<Rule>) -> BeginEnd
pub fn pattern(self, rule: impl Into<Rule>) -> BeginEnd
Adds a rule that applies inside the region ("patterns").
§Examples
use textmate_lang::{BeginEnd, Grammar, Rule};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new(r"\{", r"\}").pattern(Rule::include_self()))
.to_json()?;
assert!(json.contains(r#""patterns": ["#));Sourcepub fn apply_end_pattern_last(self, last: bool) -> BeginEnd
pub fn apply_end_pattern_last(self, last: bool) -> BeginEnd
Whether end is tried after the region’s patterns rather than before
("applyEndPatternLast": 1), so a pattern that matches at the same
position as end wins.
§Examples
use textmate_lang::{BeginEnd, Grammar};
let json = Grammar::new("source.demo")
.pattern(BeginEnd::new("<", ">").apply_end_pattern_last(true))
.to_json()?;
assert!(json.contains(r#""applyEndPatternLast": 1"#));