@@ -20,8 +20,17 @@ sub rule(RakuAST::Name:D :$name!, RakuAST::Regex:D :$body!) {
2020 )
2121}
2222
23- sub property-decl (Str : D $ prop-name ) {
23+ sub property-decl (Str : D $ prop-name , : $ quant ) {
2424 my RakuAST::Name $ name = " decl:sym<$ prop-name >" . & name ;
25+ my RakuAST::Regex $ regex-body = RakuAST::Regex::Assertion::Alias. new (
26+ name => " expr" ,
27+ assertion => (" expr-" ~ $ prop-name ). & assertion (:! capturing),
28+ );
29+ if $ quant ~~ Array : D {
30+ my RakuAST::Regex::Quantifier $ quantifier = quant($ quant );
31+ $ regex-body = RakuAST::Regex::QuantifiedAtom. new : : atom($ regex-body ), : $ quantifier ;
32+ }
33+
2534 rule(
2635 : $ name ,
2736 body => seq (
@@ -40,10 +49,7 @@ sub property-decl(Str:D $prop-name) {
4049 name => ' val' . & name ,
4150 args => RakuAST::ArgList. new (
4251 RakuAST::QuotedRegex. new (
43- body => RakuAST::Regex::Assertion::Alias. new (
44- name => " expr" ,
45- assertion => (" expr-" ~ $ prop-name ). & assertion (:! capturing),
46- ). & ws ,
52+ body => $ regex-body . & ws ,
4753 ),
4854 RakuAST::Var::Compiler::Routine. new . & postfix (' WHY' . & call ),
4955 ),
@@ -53,7 +59,11 @@ sub property-decl(Str:D $prop-name) {
5359 );
5460}
5561
56- multi sub compile (: @ props ! , : $ default , : $ spec ! , Str : $ synopsis ! , Bool : $ inherit = True ) {
62+ multi sub compile (: @ props ! , : $ default , Pair : $ spec ! is copy , Str : $ synopsis ! , Bool : $ inherit = True ) {
63+ my $ quant ;
64+ if $ spec . key eq ' occurs' && $ spec . value . head ~~ [1 ,4 ] {
65+ ($ quant , $ spec ) = $ spec . value . List ;
66+ }
5767 my RakuAST::Regex $ body = $ spec . & compile ;
5868 $ body = (' i' . & modifier , $ body . & ws , ). & seq ;
5969
@@ -64,10 +74,10 @@ multi sub compile(:@props!, :$default, :$spec!, Str :$synopsis!, Bool :$inherit
6474
6575 for @ props -> $ prop {
6676 @ exprs . append : (
67- $ prop . & property-decl . declarator-docs(
77+ $ prop . & property-decl ( : $ quant ) . declarator-docs(
6878 : $ leading
6979 ). & expression ,
70- rule(name => (' expr-' ~ $ prop ). & name , : $ body ). & expression ,
80+ rule(name => (' expr-' ~ $ prop ). & name , : $ body ). & expression ,
7181 )
7282 }
7383 @ exprs ;
@@ -274,6 +284,7 @@ multi sub compile(:@combo!, Bool :$required) {
274284 RakuAST::Regex::QuantifiedAtom. new : : $ atom , : $ quantifier ;
275285}
276286
287+
277288multi sub compile ($ arg ) { compile | $ arg }
278289
279290method build-grammar (@ grammar-id ) {
0 commit comments