4 ms·
I'm not super familiar with Raku, but if RakuAST is what you had in mind it looks a bit different: use experimental :rakuast; my $ast = RakuAST::C
by itishappy 7mo ago
I'm not super familiar with Raku, but if RakuAST is what you had in mind it looks a bit different:
use experimental :rakuast;
my $ast = RakuAST::Call::Name.new(
name => RakuAST::Name.from-identifier("say"),
args => RakuAST::ArgList.new(
RakuAST::StrLiteral.new("Hello world")
)
);
Looks more like "low-level programming an AST" (which I believe other languages offer as well), rather than using a bidirectional transform. I don't know how you'd get Raku code back out, for example.
Edit: I should have looked deeper, `DEPARSE` does exactly this:
https://docs.raku.org/type/RakuAST https://docs.raku.org/type/RakuAST
Neat!
- lizmat 7mo agoIt also goes from source code to AST: $ raku -e 'say Q|say "Hello World!"|.AST' RakuAST::StatementList.new( RakuAST::Statement::Expression.new( expression => RakuAST::Call::Name::WithoutParentheses.new( name => RakuAST::Name.from-identifier("say"), args => RakuAST::ArgList.new( RakuAST::QuotedString.new( segments => ( RakuAST::StrLiteral.new("Hello World!"), ) ) ) ) ) )