Last active
August 29, 2015 13:58
-
-
Save goccy/10094493 to your computer and use it in GitHub Desktop.
Compiler::Parser::(AST|Node)::findの使い方
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Compiler::Lexer; | |
use Compiler::Parser; | |
use Data::Dumper; | |
my $script = do { local $/; <DATA> }; | |
my $tokens = Compiler::Lexer->new('-')->tokenize($script); | |
my $ast = Compiler::Parser->new->parse($tokens); | |
print Dumper +[ | |
map { | |
+{ | |
module_name => $_->data, | |
exported_names => ($_->args) ? [ map { $_->data } @{$_->args->find(node => 'Leaf')} ] : undef | |
}; | |
} @{$ast->find(node => 'Module')} | |
]; | |
=output | |
$VAR1 = [ | |
{ | |
'module_name' => 'A', | |
'exported_names' => undef | |
}, | |
{ | |
'module_name' => 'B', | |
'exported_names' => [ | |
'exportA exportB' | |
] | |
}, | |
{ | |
'module_name' => 'C', | |
'exported_names' => [ | |
'exportA', | |
'exportB' | |
] | |
} | |
]; | |
=cut | |
__DATA__ | |
use A; | |
require B qw/exportA exportB/; | |
use C ('exportA', 'exportB'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment