MCPcopy Create free account
hub / github.com/davidblewett/rure-python / alternation

Method alternation

regex/regex-syntax/src/hir/mod.rs:500–564  ·  view source on GitHub ↗

Returns the alternation of the given expressions. This flattens the alternation as appropriate.

(mut exprs: Vec<Hir>)

Source from the content-addressed store, hash-verified

498 ///
499 /// This flattens the alternation as appropriate.
500 pub fn alternation(mut exprs: Vec<Hir>) -> Hir {
501 match exprs.len() {
502 0 => Hir::empty(),
503 1 => exprs.pop().unwrap(),
504 _ => {
505 let mut info = HirInfo::new();
506 info.set_always_utf8(true);
507 info.set_all_assertions(true);
508 info.set_anchored_start(true);
509 info.set_anchored_end(true);
510 info.set_line_anchored_start(true);
511 info.set_line_anchored_end(true);
512 info.set_any_anchored_start(false);
513 info.set_any_anchored_end(false);
514 info.set_match_empty(false);
515 info.set_literal(false);
516 info.set_alternation_literal(true);
517
518 // Some attributes require analyzing all sub-expressions.
519 for e in &exprs {
520 let x = info.is_always_utf8() && e.is_always_utf8();
521 info.set_always_utf8(x);
522
523 let x = info.is_all_assertions() && e.is_all_assertions();
524 info.set_all_assertions(x);
525
526 let x = info.is_anchored_start() && e.is_anchored_start();
527 info.set_anchored_start(x);
528
529 let x = info.is_anchored_end() && e.is_anchored_end();
530 info.set_anchored_end(x);
531
532 let x = info.is_line_anchored_start()
533 && e.is_line_anchored_start();
534 info.set_line_anchored_start(x);
535
536 let x = info.is_line_anchored_end()
537 && e.is_line_anchored_end();
538 info.set_line_anchored_end(x);
539
540 let x =
541 info.is_any_anchored_start()
542 || e.is_any_anchored_start();
543 info.set_any_anchored_start(x);
544
545 let x =
546 info.is_any_anchored_end()
547 || e.is_any_anchored_end();
548 info.set_any_anchored_end(x);
549
550 let x = info.is_match_empty() || e.is_match_empty();
551 info.set_match_empty(x);
552
553 let x =
554 info.is_alternation_literal()
555 && e.is_literal();
556 info.set_alternation_literal(x);
557 }

Callers

nothing calls this directly

Calls 15

AlternationClass · 0.85
unwrapMethod · 0.80
is_always_utf8Method · 0.80
is_all_assertionsMethod · 0.80
is_anchored_startMethod · 0.80
is_anchored_endMethod · 0.80
is_line_anchored_endMethod · 0.80
is_any_anchored_startMethod · 0.80
is_any_anchored_endMethod · 0.80
is_match_emptyMethod · 0.80

Tested by

no test coverage detected