Skip to content

Commit

Permalink
RakuAST: add RakuAST::Literal.new
Browse files Browse the repository at this point in the history
This will look at the type of the value passed and create the
appropriate object.  E.g. RakuAST::Literal.new(42) will create
a RakuAST::IntLiteral because 42 is an Int.

This should make manual building of ASTs simpler.
  • Loading branch information
lizmat committed May 27, 2023
1 parent 188fbb6 commit b45b054
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Raku/ast/literals.rakumod
Expand Up @@ -14,6 +14,11 @@ class RakuAST::Literal
$context.ensure-sc($value);
QAST::WVal.new( :$value )
}

method new(Mu $value) {
my $type := $value.HOW.name($value) ~ 'Literal';
RakuAST.WHO{$type}.new($value)
}
}

class RakuAST::IntLiteral
Expand Down

0 comments on commit b45b054

Please sign in to comment.