@@ -8,12 +8,10 @@ our proto sub compile (|c) is export(:compile) {
88
99multi sub modifier (' i' ) { RakuAST::Regex::InternalModifier::IgnoreCase. new }
1010
11- sub rule (RakuAST::Name: D : $ name ! , RakuAST::Regex: D : $ body ! , Str : $ leading ) {
11+ sub rule (RakuAST::Name: D : $ name ! , RakuAST::Regex: D : $ body ! ) {
1212 RakuAST::RuleDeclaration. new (
1313 : $ name ,
1414 : $ body ,
15- ). declarator-docs(
16- : $ leading
1715 )
1816}
1917
@@ -28,16 +26,55 @@ sub expression($expression) {
2826 RakuAST::Statement::Expression. new : : $ expression ;
2927}
3028
29+ sub property-decl (Str : D $ prop-name ) {
30+ rule(
31+ name => RakuAST::Name. from-identifier(" decl:sym<$ prop-name >" ),
32+ body => seq (
33+ ' i' . & modifier ,
34+ RakuAST::Regex::CapturingGroup. new (
35+ (
36+ $ prop-name . & lit ,
37+ ). & seq
38+ ). & ws ,
39+ RakuAST::Regex::Quote. new (
40+ RakuAST::QuotedString. new (
41+ segments => (
42+ RakuAST::StrLiteral. new (" :" ),
43+ )
44+ )
45+ ). & ws ,
46+ RakuAST::Regex::Assertion::Named::Args. new (
47+ name => ' val' . & name ,
48+ args => RakuAST::ArgList. new (
49+ RakuAST::QuotedRegex. new (
50+ body => RakuAST::Regex::WithWhitespace. new (
51+ RakuAST::Regex::Assertion::Alias. new (
52+ name => " expr" ,
53+ assertion => (" expr-" ~ $ prop-name ). & assertion (:! capturing),
54+ )
55+ )
56+ ),
57+ RakuAST::Var::Compiler::Routine. new . & postfix (' WHY' . & call ),
58+ ),
59+ : capturing
60+ ). & ws
61+ )
62+ );
63+ }
64+
3165multi sub compile (: @ props ! , : $ default , : $ spec , Str : $ synopsis , Bool : $ inherit = True ) {
3266 die " todo: { @ props } " unless @ props == 1 ;
3367 my $ prop = @ props . head;
3468 my RakuAST::Regex $ body = $ spec . & compile ;
35- $ body = seq [ modifier (' i' ) , ws( $ body ), ] ;
69+ $ body = (' i' . & modifier , $ body . & ws , ) . & seq ;
3670
3771 my Str $ leading = $ _ ~ " \n " with $ synopsis ;
3872
3973 (
40- rule(name => (' expr-' ~ $ prop ). & name , : $ body , : $ leading ). & expression ,
74+ $ prop . & property-decl . declarator-docs(
75+ : $ leading
76+ ),
77+ rule(name => (' expr-' ~ $ prop ). & name , : $ body ). & expression ,
4178 ). & statements ;
4279}
4380
@@ -60,7 +97,7 @@ multi sub quant(Array:D $_ where .elems >= 2) {
6097
6198sub name (Str : D $ id ) is export { RakuAST::Name. from-identifier($ id ) }
6299
63- sub look-ahead (RakuAST::Regex::Assertion $ assertion , Bool : $ negated = False , Bool : $ capturing = False ) is export {
100+ sub look-ahead (RakuAST::Regex::Assertion $ assertion , Bool : $ negated = False ) is export {
64101 RakuAST::Regex::Assertion::Lookahead. new (
65102 : $ assertion , : $ negated
66103 );
@@ -93,7 +130,6 @@ multi sub arg(Int:D $arg) {
93130multi sub ws (RakuAST::Regex $ r ) is export { RakuAST::Regex::WithWhitespace. new ($ r ) }
94131
95132sub lit (Str : D $ s ) is export { RakuAST::Regex::Literal. new ($ s ) }
96- sub lit-ws (Str : D () $ _ ) is export { . & lit . & ws }
97133
98134sub group (RakuAST::Regex $ r ) is export { RakuAST::Regex::Group. new : $ r }
99135
@@ -178,6 +214,8 @@ multi sub compile(:@numbers!) {
178214 _choice @ numbers . map (& lit-ws ), ' number' . & assertion ;
179215}
180216
217+ sub lit-ws (Str : D () $ _ ) is export { . & lit . & ws }
218+
181219multi sub compile (Str : D : $ op ! ) {
182220 my RakuAST::ArgList $ args = ' ,' . & arg ;
183221 ' op' . & assertion (: $ args );
0 commit comments