Permalink
Browse files

[QAST::Block] implement .symbol

  • Loading branch information...
1 parent a6c9a36 commit 9e3e240014f2f6e4ee889274cbcecb354689f83c @masak masak committed May 25, 2012
Showing with 25 additions and 0 deletions.
  1. +9 −0 src/QAST/Block.nqp
  2. +16 −0 t/qast/qast.t
View
@@ -2,6 +2,7 @@ class QAST::Block is QAST::Node {
has str $!blocktype;
has int $!lexical;
has str $!cuid;
+ has %!symbol;
method blocktype(*@value) { $!blocktype := @value[0] if @value; $!blocktype }
method lexical(*@value) { $!lexical := @value[0] if @value; $!lexical }
@@ -24,4 +25,12 @@ class QAST::Block is QAST::Node {
$!cuid := 'cuid_' ~ $cur_cuid ~ '_' ~ $cuid_suffix;
}
}
+
+ method symbol($name, *%attrs) {
+ %!symbol{$name} := %!symbol{$name} // {};
+ for %attrs {
+ %!symbol{$name}{$_.key} := $_.value;
+ }
+ %!symbol{$name}
+ }
}
View
@@ -725,3 +725,19 @@ is_qast(
),
1,
'repeat_until loop works');
+
+{
+ my $block := QAST::Block.new();
+ $block.symbol('rhinoceros', food => 'pizza', mood => 'giddy');
+ my %hash := $block.symbol('rhinoceros');
+ ok(%hash<food> eq 'pizza', 'QAST::Block.symbol getter/setter works I');
+ ok(%hash<mood> eq 'giddy', 'QAST::Block.symbol getter/setter works II');
+}
+
+{
+ my $block := QAST::Block.new();
+ $block.symbol('slug', food => 'cheeseburger');
+ $block.symbol('slug', mood => 'laconic');
+ my %hash := $block.symbol('slug');
+ ok(%hash<food> eq 'cheeseburger', 'QAST::Block.symbol existing attributes don\'t disappear');
+}

0 comments on commit 9e3e240

Please sign in to comment.