Skip to content

Instantly share code, notes, and snippets.

@wayland
Created May 31, 2024 21:54
Show Gist options
  • Save wayland/cdf69e8b52496c5e6b1964397ad72df3 to your computer and use it in GitHub Desktop.
Save wayland/cdf69e8b52496c5e6b1964397ad72df3 to your computer and use it in GitHub Desktop.
#!/usr/bin/raku
use experimental :rakuast;
class A {}
# Signature 1 material
my $signature1 = :(Str, 'John');
my $ast = Q:qq| {$signature1.raku} |.AST;
print "AST: ";
say $ast.statements[0].expression.signature.raku;
my @astparams = |$ast.statements[0].expression.signature.parameters;
say "astparams";
say |@astparams;
# Signature 2 material
my $sig2 = RakuAST::Signature.new(
parameters => (
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("A"),
)
),
# ($ast.statements[0].expression.signature.parameters),
|@astparams
),
);
say "sig2.raku: ";
say $sig2.raku;
# Signature 2 material
my $sig3 = RakuAST::Signature.new(
parameters => (
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("A"),
)
),
# ($ast.statements[0].expression.signature.parameters),
@astparams
),
);
say "sig3.raku: ";
say $sig3.raku;
AST: RakuAST::Signature.new(
parameters => (
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
)
),
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
),
value => "John"
),
)
)
astparams
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
)
)RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
),
value => "John"
)
sig2.raku:
RakuAST::Signature.new(
parameters => (
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("A")
)
),
)
)
sig3.raku:
RakuAST::Signature.new(
parameters => (
RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("A")
)
),
[RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
)
), RakuAST::Parameter.new(
type => RakuAST::Type::Simple.new(
RakuAST::Name.from-identifier("Str")
),
value => "John"
)],
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment