Trait sljs::SourceNode
source · [−]pub trait SourceNode: Sized {
fn to_error(&self) -> JSON;
fn get_location(&self) -> Option<Location>;
fn get_literal(&self, property: &str) -> ParseResult<Literal>;
fn get_bool(&self, property: &str) -> ParseResult<bool>;
fn get_str(&self, property: &str) -> ParseResult<JSString>;
fn map_node<T, F>(&self, property: &str, action: F) -> ParseResult<T>
where
F: FnMut(&Self) -> ParseResult<T>;
fn map_array<T, F>(&self, property: &str, func: F) -> ParseResult<Vec<T>>
where
F: FnMut(&Self) -> ParseResult<T>;
fn expect_str(&self, property: &str, value: &'static str) -> ParseResult<()> { ... }
fn map_opt_node<T, F>(
&self,
property: &str,
action: F
) -> ParseResult<Option<T>>
where
F: FnMut(&Self) -> ParseResult<T>,
{ ... }
}
Expand description
SourceNode
is how ParseFrom::parse_from
sees AST nodes.
Required Methods
fn get_location(&self) -> Option<Location>
fn get_location(&self) -> Option<Location>
Try to get source mapping for self
.
fn get_literal(&self, property: &str) -> ParseResult<Literal>
fn get_literal(&self, property: &str) -> ParseResult<Literal>
Use the node as a literal.
fn get_bool(&self, property: &str) -> ParseResult<bool>
fn get_bool(&self, property: &str) -> ParseResult<bool>
Get the boolean value of a child node with name property
.
It’s a ParseError if it does not exist or does not have a boolean meaning.
fn get_str(&self, property: &str) -> ParseResult<JSString>
fn get_str(&self, property: &str) -> ParseResult<JSString>
Get the string value of a child node with name property
.
It’s a ParseError if it does not exist or does not have a string meaning.
fn map_node<T, F>(&self, property: &str, action: F) -> ParseResult<T> where
F: FnMut(&Self) -> ParseResult<T>,
fn map_node<T, F>(&self, property: &str, action: F) -> ParseResult<T> where
F: FnMut(&Self) -> ParseResult<T>,
Get a child node with this name; if it does not exist, return None.
Then transform it through action
, propagating its Result out.
A child node exis
fn map_array<T, F>(&self, property: &str, func: F) -> ParseResult<Vec<T>> where
F: FnMut(&Self) -> ParseResult<T>,
fn map_array<T, F>(&self, property: &str, func: F) -> ParseResult<Vec<T>> where
F: FnMut(&Self) -> ParseResult<T>,
Map the array of children of a child node with name property
.
It’s a ParseError if it does not exist or does not have an array meaning.
Provided Methods
fn expect_str(&self, property: &str, value: &'static str) -> ParseResult<()>
fn expect_str(&self, property: &str, value: &'static str) -> ParseResult<()>
Check that the value of property
is a string equal to value
.
Depends on SourceNode::get_str
.