Enum wood::Wood[][src]

pub enum Wood {
    Branchv(Branch),
    Leafv(Leaf),
}

Variants

Branchv(Branch)
Leafv(Leaf)

Implementations

impl Wood[src]

pub fn leaf(v: String) -> Wood[src]

pub fn branch(v: Vec<Wood>) -> Wood[src]

pub fn is_leaf(&self) -> bool[src]

pub fn is_branch(&self) -> bool[src]

pub fn line(&self) -> isize[src]

pub fn col(&self) -> isize[src]

pub fn line_and_col(&self) -> (isize, isize)[src]

pub fn initial_str(&self) -> &str[src]

Seeks the earliest string in the tree by looking at the first element of each branch recursively until it hits a leaf. (If it runs into an empty list, returns the empty string. I recommend this whenever you want to use the first string as a discriminator, or whenever you want to get leaf str contents in general. This abstracts over similar structures in a way that I consider generally desirable. I would go as far as to say that the more obvious, less abstract way of getting initial string should be Considered Harmful. A few motivating examples: If you wanted to add a feature to a programming language that allows you to add a special tag to an invocation, you want to put the tag inside the invocation’s ast node but you don’t want it to be confused for a parameter, this pattern enables: ((f tag(special_invoke_inline)) a b) If the syntax of a sexp language had more structure to it than usual: ((if condition) then…) would still get easily picked up as an ‘if’ node. Annotations are a good example, more generally, if you’re refactoring and you decide you want to add an extra field to what was previously a leaf, this pattern enables you to make that change, confident that your code will still read its string content in the same way (list key:value “some prose”) -> (list key:value (“some prose” modifier:italicise))

pub fn to_string(&self) -> String[src]

pub fn strip_comments_escape(
    &mut self,
    comment_str: &str,
    comment_escape_str: &str
)
[src]

pub fn strip_comments(&mut self, comment_str: &str)[src]

Strips any branches with first element of comment_str. If you need to produce a leaf that is equivalent to comment_str. If you need the wood to contain a leaf that is the comment_str, you can escape it with a backslash. This is actually a highly flawed way of providing commenting, because this will also strip out any serialization of a list of strings where the first element happens to equal the comment_str. That’s a really subtle error, that violates a lot of expectations. You could get around it by escaping your wood so that any strs that resemble comment tags wont read that way, but it’s a bit awkward and sometimes wont really work.

pub fn contents(&self) -> Iter<'_, Self>[src]

if Leaf, returns a slice iter containing just this, else Branch, iterates over branch contents

pub fn head(&self) -> Result<&Wood, Box<WoodError>>[src]

returns the first wood, or if it’s a leaf, itself

pub fn second(&self) -> Result<&Wood, Box<WoodError>>[src]

returns the second wood within this one, if it is a list wood, if there is a second wood

pub fn tail<'b>(&'b self) -> Iter<'b, Self>[src]

if Leaf, returns an empty slice iter, if Branch, returns contents after the first element

pub fn seek<'a, 'b>(&'a self, key: &'b str) -> Option<&'a Wood>[src]

self.contents().find(|el| el.initial_str() == key)

pub fn find<'a, 'b>(&'a self, key: &'b str) -> Result<&'a Wood, Box<WoodError>>[src]

returns the first child term with initial_str == key, or if none is found, an error

Trait Implementations

impl Clone for Wood[src]

impl Debug for Wood[src]

impl Eq for Wood[src]

impl PartialEq<Wood> for Wood[src]

Line numbers aren’t checked in equality comparisons

impl StructuralEq for Wood[src]

Auto Trait Implementations

impl RefUnwindSafe for Wood

impl Send for Wood

impl Sync for Wood

impl Unpin for Wood

impl UnwindSafe for Wood

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.