Text-Treesitter
view release on metacpan or search on metacpan
examples/highlight.pl view on Meta::CPAN
# TODO: actually implement the priority logic
next if $capturename eq "priority";
my $node = $captures->{$capturename};
my $start = $tree->byte_to_char( $node->start_byte );
my $len = $tree->byte_to_char( $node->end_byte ) - $start;
$str->apply_tag( $start, $len, captures => $capturename ) if $CAPTURES;
my @nameparts = split m/\./, $capturename;
while( @nameparts ) {
if( my $format = $FORMATS{ join ".", @nameparts } ) {
$str->apply_tag( $start, $len, $_, $format->{$_} ) for keys %$format;
next CAPTURE;
}
pop @nameparts;
}
$UNRECOGNISED_CAPTURES{ $capturename }++;
examples/viewtree.pl view on Meta::CPAN
return @ret;
}
if( defined $FILE ) {
my $tree = $ts->parse_file( $FILE );
my $root = $tree->root_node;
# We can't call print_tree_flamegraph on text spanning multiple lines. Also
# the output will be huge and unusable. Split it per line and only output
# the nodes contained entirely within each line.
my @lines = split m/\n/, $root->text;
foreach my $lineidx ( 0 .. $#lines ) {
my $line = $lines[$lineidx];
if( !length $line ) {
print "\n";
next;
}
my @linenodes = extract_nodes_on_line( $lineidx, $root );
lib/Text/Treesitter/Language.pm view on Meta::CPAN
sub CXX_compile
{
return @CXX_compile if @CXX_compile;
require ExtUtils::CppGuess;
$guess //= ExtUtils::CppGuess->new;
my %opts = $guess->module_build_options;
return @CXX_compile = ( $opts{config}{cc},
# $opts{extra_compiler_flags} might begin with a space
split m/ +/, $opts{extra_compiler_flags} =~ s/^ +//r,
);
}
my @CXX_link;
sub CXX_link
{
return @CXX_link if @CXX_link;
require ExtUtils::CppGuess;
$guess //= ExtUtils::CppGuess->new;
my %opts = $guess->module_build_options;
return @CXX_link = ( $opts{config}{cc},
# $opts{extra_linker_flags} might begin with a space
split m/ +/, $opts{extra_linker_flags} =~ s/^ +//r,
);
}
}
sub _compile
{
my ( $source ) = @_;
my $is_cpp = $source =~ m/\.cc$/;
my $output = $source =~ s/\.cc?$/.o/r;
( run in 0.559 second using v1.01-cache-2.11-cpan-5511b514fd6 )