@@ -8,10 +8,67 @@ method actions { ... }
88method defs { ... }
99
1010method build-actions (@ actions-id ) {
11- # stub
11+ my RakuAST::Method @ methods = self ! actions-methods;
12+ my RakuAST::Statement::Expression @ expressions = @ methods . map (& expression );
13+ my RakuAST::Blockoid $ body .= new : @ expressions . & statements ;
1214 my RakuAST::Name $ name .= from-identifier-parts(| @ actions-id );
1315 RakuAST::Class. new (
1416 : $ name ,
1517 : scope<unit >,
18+ : $ body ,
1619 );
1720}
21+
22+ sub build-action (Str $ id ) {
23+ RakuAST::Blockoid. new (
24+ RakuAST::Call::Name::WithoutParentheses. new (
25+ name => RakuAST::Name. from-identifier(" make" ),
26+ args => RakuAST::ArgList. new (
27+ RakuAST::ApplyPostfix. new (
28+ operand => RakuAST::Var::Attribute::Public. new (
29+ name => " \$.build"
30+ ),
31+ postfix => RakuAST::Call::Method. new (
32+ name => RakuAST::Name. from-identifier($ id ),
33+ args => RakuAST::ArgList. new (
34+ RakuAST::Var::Lexical. new (" \$/" )
35+ )
36+ )
37+ )
38+ )
39+ ). & expression . & statements
40+ );
41+ }
42+
43+
44+
45+ method ! actions-methods {
46+ my RakuAST::Method @ methods ;
47+ my % references = $ . actions . rule-refs;
48+
49+ my RakuAST::Signature $ signature .= new (
50+ : parameters( ' $/' . & param )
51+ );
52+
53+ my $ expr-body = ' list' . & build-action ;
54+ my $ rule-body = ' rule' . & build-action ;
55+
56+ for @ . defs -> $ def {
57+ with $ def <props > -> @ props {
58+ for @ props -> $ prop {
59+ my $ expr = ' expr-' ~ $ prop ;
60+ if % references {$ expr }: delete {
61+ my RakuAST::Name $ name = $ expr . & name ;
62+ @ methods . push : RakuAST::Method. new : : $ name , : $ signature , body => $ expr-body ;
63+ }
64+ }
65+ }
66+ else {
67+ my $ rule = $ def <rule >;
68+ my RakuAST::Name $ name = $ rule . & name ;
69+ @ methods . push : RakuAST::Method. new : : $ name , : $ signature , body => $ rule-body ;
70+ }
71+ }
72+
73+ @ methods ;
74+ }
0 commit comments