Passing regular expressions as arguments in Perl 6

The continuation of this question is probably even stranger.

Can I, for example? combine the two regexeswith sub? (Of course, I understand how to do this using regex)

The following code is completely incorrect, but I hope it can explain what I want to do:

my Regex sub s12 ( $c, $v) {
   return / <{$c}> <{$v}> /
}

my regex consonant { <[a .. z] -[aeiou]>  }
my regex vowel { <[aeiou]> }

my regex open_syllable { &s12( &consonant, &vowel ) }

"bac" ~~ m:g/ <open_syllable> /;
say $/; # should be 'ba'
+4
source share
1 answer

, , , . -, , . , , , <$r> , <{my-sub(args)}> - . ( sub - & , Callable, .) :

sub combine(Regex $a, Regex $b --> Regex) {
    / <$a> <$b> /
}

my regex consonant { <[a .. z] -[aeiou]>  }
my regex vowel { <[aeiou]> }

my regex open_syllable { <{combine(&consonant, &vowel)}> }

"bac" ~~ m:g/ <open_syllable> /;
say ~$/; # output: ba
+5

Source: https://habr.com/ru/post/1689070/


All Articles