MCPcopy Create free account
hub / github.com/pest-parser/pest / check_expr

Function check_expr

meta/src/validator.rs:635–699  ·  view source on GitHub ↗
(
        node: &'a ParserNode<'i>,
        rules: &'a HashMap<String, &ParserNode<'i>>,
        trace: &mut Vec<String>,
    )

Source from the content-addressed store, hash-verified

633
634fn left_recursion<'a, 'i: 'a>(rules: HashMap<String, &'a ParserNode<'i>>) -> Vec<Error<Rule>> {
635 fn check_expr<'a, 'i: 'a>(
636 node: &'a ParserNode<'i>,
637 rules: &'a HashMap<String, &ParserNode<'i>>,
638 trace: &mut Vec<String>,
639 ) -> Option<Error<Rule>> {
640 match node.expr.clone() {
641 ParserExpr::Ident(other) => {
642 if trace[0] == other {
643 trace.push(other);
644 let chain = trace
645 .iter()
646 .map(|ident| ident.as_ref())
647 .collect::<Vec<_>>()
648 .join(" -> ");
649
650 return Some(Error::new_from_span(
651 ErrorVariant::CustomError {
652 message: format!(
653 "rule {} is left-recursive ({}); pest::pratt_parser might be useful \
654 in this case",
655 node.span.as_str(),
656 chain
657 )
658 },
659 node.span
660 ));
661 }
662
663 if !trace.contains(&other) {
664 if let Some(node) = rules.get(&other) {
665 trace.push(other);
666 let result = check_expr(node, rules, trace);
667 trace.pop().unwrap();
668
669 return result;
670 }
671 }
672
673 None
674 }
675 ParserExpr::Seq(ref lhs, ref rhs) => {
676 if is_non_failing(&lhs.expr, rules, &mut vec![trace.last().unwrap().clone()])
677 || is_non_progressing(
678 &lhs.expr,
679 rules,
680 &mut vec![trace.last().unwrap().clone()],
681 )
682 {
683 check_expr(rhs, rules, trace)
684 } else {
685 check_expr(lhs, rules, trace)
686 }
687 }
688 ParserExpr::Choice(ref lhs, ref rhs) => {
689 check_expr(lhs, rules, trace).or_else(|| check_expr(rhs, rules, trace))
690 }
691 ParserExpr::Rep(ref node) => check_expr(node, rules, trace),
692 ParserExpr::RepOnce(ref node) => check_expr(node, rules, trace),

Callers 1

left_recursionFunction · 0.85

Calls 6

is_non_failingFunction · 0.85
is_non_progressingFunction · 0.85
cloneMethod · 0.80
pushMethod · 0.80
popMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…