Struct pest_meta::parser::ParserNode
source · pub struct ParserNode<'i> {
pub expr: ParserExpr<'i>,
pub span: Span<'i>,
}
Expand description
The pest grammar node
Fields§
§expr: ParserExpr<'i>
The node’s expression
span: Span<'i>
The node’s span
Implementations§
source§impl<'i> ParserNode<'i>
impl<'i> ParserNode<'i>
sourcepub fn filter_map_top_down<F, T>(self, f: F) -> Vec<T>where
F: FnMut(ParserNode<'i>) -> Option<T>,
pub fn filter_map_top_down<F, T>(self, f: F) -> Vec<T>where
F: FnMut(ParserNode<'i>) -> Option<T>,
will remove nodes that do not match f
Examples found in repository?
src/validator.rs (lines 307-336)
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
fn validate_repetition<'a, 'i: 'a>(rules: &'a [ParserRule<'i>]) -> Vec<Error<Rule>> {
let mut result = vec![];
let map = to_hash_map(rules);
for rule in rules {
let mut errors = rule.node
.clone()
.filter_map_top_down(|node| match node.expr {
ParserExpr::Rep(ref other)
| ParserExpr::RepOnce(ref other)
| ParserExpr::RepMin(ref other, _) => {
if is_non_failing(&other.expr, &map, &mut vec![]) {
Some(Error::new_from_span(
ErrorVariant::CustomError {
message:
"expression inside repetition cannot fail and will repeat \
infinitely"
.to_owned()
},
node.span
))
} else if is_non_progressing(&other.expr, &map, &mut vec![]) {
Some(Error::new_from_span(
ErrorVariant::CustomError {
message:
"expression inside repetition is non-progressing and will repeat \
infinitely"
.to_owned(),
},
node.span
))
} else {
None
}
}
_ => None
});
result.append(&mut errors);
}
result
}
fn validate_choices<'a, 'i: 'a>(rules: &'a [ParserRule<'i>]) -> Vec<Error<Rule>> {
let mut result = vec![];
let map = to_hash_map(rules);
for rule in rules {
let mut errors = rule
.node
.clone()
.filter_map_top_down(|node| match node.expr {
ParserExpr::Choice(ref lhs, _) => {
let node = match lhs.expr {
ParserExpr::Choice(_, ref rhs) => rhs,
_ => lhs,
};
if is_non_failing(&node.expr, &map, &mut vec![]) {
Some(Error::new_from_span(
ErrorVariant::CustomError {
message:
"expression cannot fail; following choices cannot be reached"
.to_owned(),
},
node.span,
))
} else {
None
}
}
_ => None,
});
result.append(&mut errors);
}
result
}
Trait Implementations§
source§impl<'i> Clone for ParserNode<'i>
impl<'i> Clone for ParserNode<'i>
source§fn clone(&self) -> ParserNode<'i>
fn clone(&self) -> ParserNode<'i>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'i> Debug for ParserNode<'i>
impl<'i> Debug for ParserNode<'i>
source§impl<'i> PartialEq<ParserNode<'i>> for ParserNode<'i>
impl<'i> PartialEq<ParserNode<'i>> for ParserNode<'i>
source§fn eq(&self, other: &ParserNode<'i>) -> bool
fn eq(&self, other: &ParserNode<'i>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.