(input: &str)
| 536 | } |
| 537 | |
| 538 | fn rule(input: &str) -> IResult<&str, Rule> { |
| 539 | println!("Starting to parse rule {}", input); |
| 540 | |
| 541 | let (input, name) = ws(identifier)(input)?; |
| 542 | println!("Parsed rule name: {}", name); |
| 543 | let (input, _) = ws(tag("as"))(input)?; |
| 544 | println!("Parsed 'as'"); |
| 545 | let (input, _) = ws(tag("match"))(input)?; |
| 546 | println!("Parsed 'match'"); |
| 547 | |
| 548 | // Define a parser for either patterns or conditions |
| 549 | let pattern_or_condition = alt(( |
| 550 | map(entity_pattern, |p| (p, None::<String>)), |
| 551 | map(relationship_pattern, |p| (p, None::<String>)), |
| 552 | map(condition, |c| (Pattern::Condition(c.clone()), Some(c))), |
| 553 | )); |
| 554 | |
| 555 | // Parse a list of patterns and/or conditions |
| 556 | let (input, patterns_and_conditions) = |
| 557 | separated_list0(ws(char(',')), pattern_or_condition)(input)?; |
| 558 | |
| 559 | // Separate patterns and conditions from the combined list |
| 560 | let mut patterns = Vec::new(); |
| 561 | let mut conditions = Vec::new(); |
| 562 | |
| 563 | for (pattern, condition) in patterns_and_conditions { |
| 564 | if let Some(cond) = condition { |
| 565 | conditions.push(cond); |
| 566 | } else { |
| 567 | patterns.push(pattern); |
| 568 | } |
| 569 | } |
| 570 | println!("Parsed patterns: {:?}", patterns); |
| 571 | |
| 572 | let (input, _) = ws(tag("infer"))(input)?; |
| 573 | println!("Parsed 'infer'"); |
| 574 | let (input, inference_type) = inference_type(input)?; |
| 575 | println!("Parsed inference type: {:?}", inference_type); |
| 576 | let (input, inferences) = separated_list1( |
| 577 | ws(char(',')), |
| 578 | alt(( |
| 579 | entity_inference, |
| 580 | relationship_inference, |
| 581 | extend_entity_inference, |
| 582 | )), |
| 583 | )(input)?; |
| 584 | println!("Parsed inferences: {:?}", inferences); |
| 585 | let (input, _) = ws(char(';'))(input)?; |
| 586 | println!("Parsed semicolon"); |
| 587 | |
| 588 | println!("Constructing Rule struct"); |
| 589 | let rule = Rule { |
| 590 | name: name.to_string(), |
| 591 | patterns, |
| 592 | compute_clauses: None, |
| 593 | inference_type, |
| 594 | inferences, |
| 595 | }; |
nothing calls this directly
no test coverage detected