Skip to main content

BeginWhile

Struct BeginWhile 

Source
pub struct BeginWhile { /* private fields */ }
Expand description

A region that opens at a begin match and continues, line by line, for as long as a while pattern matches at the start of each following line ("begin"/"while"), as Markdown block quotes and lists do.

Numbered back-references in while stand for the text begin groups captured.

§Examples

use textmate_lang::{BeginWhile, Grammar, Rule};

let quote = BeginWhile::new(r"^\s*(>) ?", r"^\s*(>) ?")
    .scope("markup.quote.demo")
    .begin_capture(1, "punctuation.definition.quote.demo")
    .while_capture(1, "punctuation.definition.quote.demo")
    .pattern(Rule::include_self());
let json = Grammar::new("text.demo").pattern(quote).to_json()?;
assert!(json.contains(r#""while": "^\\s*(>) ?""#));

Implementations§

Source§

impl BeginWhile

Source

pub fn new( begin: impl Into<Cow<'static, str>>, while_: impl Into<Cow<'static, str>>, ) -> BeginWhile

A region opened by begin and continued while while_ matches.

ParameterMeaning
beginThe pattern that opens the region.
while_The pattern each following line must start with; \n back-references name begin groups.
§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^(\\s{4})", "^\\1").scope("markup.raw.block.demo"))
    .to_json()?;
assert!(json.contains(r#""while": "^\\1""#));
Source

pub fn scope(self, scope: impl Into<Cow<'static, str>>) -> BeginWhile

Scopes the whole region ("name"). $n substitutions name begin groups.

§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^>", "^>").scope("markup.quote.demo"))
    .to_json()?;
assert!(json.contains("markup.quote.demo"));
Source

pub fn content_scope(self, scope: impl Into<Cow<'static, str>>) -> BeginWhile

Scopes the region without the begin match ("contentName").

§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^>", "^>").content_scope("markup.quote.content.demo"))
    .to_json()?;
assert!(json.contains(r#""contentName": "markup.quote.content.demo""#));
Source

pub fn capture(self, group: u32, capture: impl Into<Capture>) -> BeginWhile

Sets capture group for both begin and while ("captures").

§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^(>)", "^(>)").capture(1, "punctuation.demo"))
    .to_json()?;
assert!(json.contains(r#""captures": {"#));
Source

pub fn begin_capture( self, group: u32, capture: impl Into<Capture>, ) -> BeginWhile

Sets capture group of begin ("beginCaptures").

§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^(>)", "^>").begin_capture(1, "punctuation.demo"))
    .to_json()?;
assert!(json.contains(r#""beginCaptures": {"#));
Source

pub fn while_capture( self, group: u32, capture: impl Into<Capture>, ) -> BeginWhile

Sets capture group of while ("whileCaptures").

§Examples
use textmate_lang::{BeginWhile, Grammar};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^>", "^(>)").while_capture(1, "punctuation.demo"))
    .to_json()?;
assert!(json.contains(r#""whileCaptures": {"#));
Source

pub fn pattern(self, rule: impl Into<Rule>) -> BeginWhile

Adds a rule that applies inside the region ("patterns").

§Examples
use textmate_lang::{BeginWhile, Grammar, Match};

let json = Grammar::new("text.demo")
    .pattern(BeginWhile::new("^>", "^>").pattern(Match::new(r"\*\*").scope("markup.bold.demo")))
    .to_json()?;
assert!(json.contains("markup.bold.demo"));

Trait Implementations§

Source§

impl Clone for BeginWhile

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BeginWhile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for BeginWhile

Source§

impl From<BeginWhile> for Rule

Source§

fn from(rule: BeginWhile) -> Rule

Converts to this type from the input type.
Source§

impl PartialEq for BeginWhile

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BeginWhile

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.