Skip to main content

Recipe

Struct Recipe 

Source
pub struct Recipe(/* private fields */);
Expand description

An AST node for $ast

Implementations§

Source§

impl Recipe

Source

pub fn line(&self) -> usize

Get the line number (0-indexed) where this node starts.

Source

pub fn column(&self) -> usize

Get the column number (0-indexed, in bytes) where this node starts.

Source

pub fn line_col(&self) -> (usize, usize)

Get both line and column (0-indexed) where this node starts. Returns (line, column) where column is measured in bytes from the start of the line.

Source§

impl Recipe

Source

pub fn text(&self) -> String

Get the text content of this recipe line (the command to execute)

For single-line recipes, this returns the command text excluding the leading tab and trailing newline.

For multi-line recipes (with backslash continuations), this returns the full text including the internal newlines and continuation-line indentation, but still excluding the leading tab of the first line and the final newline. This preserves the exact content needed for a lossless round-trip.

For comment-only lines, this returns an empty string.

Source

pub fn indent(&self) -> Option<String>

Get the indentation string of this recipe line.

Returns the leading indentation (typically a tab character) of this recipe line, or None if no indent token is present.

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
assert_eq!(recipe.indent(), Some("\t".to_string()));
Source

pub fn comment(&self) -> Option<String>

Get the comment content of this recipe line, if any

Returns the comment text (including the ‘#’ character) if this recipe line contains a comment, or None if there is no comment.

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\t# This is a comment\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert_eq!(recipes[0].comment(), Some("# This is a comment".to_string()));
assert_eq!(recipes[1].comment(), None);
Source

pub fn full(&self) -> String

Get the full content of this recipe line

Returns all content including command text, comments, and internal whitespace, but excluding the leading indent. This is useful for getting the complete content of a recipe line regardless of whether it’s a command, comment, or both.

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\techo hello # inline comment\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
assert_eq!(recipe.full(), "echo hello # inline comment");
Source

pub fn parent(&self) -> Option<Rule>

Get the parent rule containing this recipe

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipe = rule.recipe_nodes().next().unwrap();
let parent = recipe.parent().unwrap();
assert_eq!(parent.targets().collect::<Vec<_>>(), vec!["all"]);
Source

pub fn text_range(&self) -> TextRange

Get the source range of this recipe node.

Source

pub fn is_silent(&self) -> bool

Check if this recipe has the silent prefix (@)

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\t@echo hello\n\techo world\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert!(recipes[0].is_silent());
assert!(!recipes[1].is_silent());
Source

pub fn is_ignore_errors(&self) -> bool

Check if this recipe has the ignore-errors prefix (-)

§Example
use makefile_lossless::Makefile;

let makefile: Makefile = "all:\n\t-echo hello\n\techo world\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let recipes: Vec<_> = rule.recipe_nodes().collect();
assert!(recipes[0].is_ignore_errors());
assert!(!recipes[1].is_ignore_errors());
Source

pub fn set_prefix(&mut self, prefix: &str)

Set the command prefix for this recipe

The prefix can contain @ (silent), - (ignore errors), and/or + (always execute). Pass an empty string to remove all prefixes.

§Example
use makefile_lossless::Makefile;

let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.set_prefix("@");
assert_eq!(recipe.text(), "@echo hello");
assert!(recipe.is_silent());
Source

pub fn replace_text(&mut self, new_text: &str)

Replace the text content of this recipe line

§Example
use makefile_lossless::Makefile;

let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.replace_text("echo world");
assert_eq!(recipe.text(), "echo world");
Source

pub fn insert_before(&self, text: &str)

Insert a new recipe line before this one

§Example
use makefile_lossless::Makefile;

let mut makefile: Makefile = "all:\n\techo world\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.insert_before("echo hello");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]);
Source

pub fn insert_after(&self, text: &str)

Insert a new recipe line after this one

§Example
use makefile_lossless::Makefile;

let mut makefile: Makefile = "all:\n\techo hello\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.insert_after("echo world");
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo hello", "echo world"]);
Source

pub fn remove(&self)

Remove this recipe line from its parent

§Example
use makefile_lossless::Makefile;

let mut makefile: Makefile = "all:\n\techo hello\n\techo world\n".parse().unwrap();
let mut rule = makefile.rules().next().unwrap();
let mut recipe = rule.recipe_nodes().next().unwrap();
recipe.remove();
assert_eq!(rule.recipes().collect::<Vec<_>>(), vec!["echo world"]);

Trait Implementations§

Source§

impl AstNode for Recipe

Source§

type Language = Lang

Source§

fn can_cast(kind: SyntaxKind) -> bool

Source§

fn cast(syntax: SyntaxNode<Lang>) -> Option<Self>

Source§

fn syntax(&self) -> &SyntaxNode<Lang>

Source§

fn clone_for_update(&self) -> Self
where Self: Sized,

Source§

fn clone_subtree(&self) -> Self
where Self: Sized,

Source§

impl Clone for Recipe

Source§

fn clone(&self) -> Recipe

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 Display for Recipe

Source§

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

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

impl Hash for Recipe

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Recipe

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Recipe

Source§

impl StructuralPartialEq for Recipe

Auto Trait Implementations§

§

impl Freeze for Recipe

§

impl !RefUnwindSafe for Recipe

§

impl !Send for Recipe

§

impl !Sync for Recipe

§

impl Unpin for Recipe

§

impl UnsafeUnpin for Recipe

§

impl !UnwindSafe for Recipe

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.