Open agentzh opened 9 years ago
See #42.
I think it might end up like:
my $receiver = Some::AST->new(need_line_number => 1);
…
package Some::AST;
sub got_foo {
my $line = ${$self->{line}};
}
@ingydotnet Not too bad, though a bit ugly, especially as part of the Pegex API. Started missing macros in Perl 5 :)
@agentzh better ideas welcome. :)
@ingydotnet Not really if you want the speed :) My original proposal looks cleaner though definitely a little bit slower :)
Right now, we need
($self->parser->line_column)[0]
to get line numbers in custom receiver class's methods. It'll be great if the Pegex::Receiver class (or anything along the inheritance line) provides a handyline()
method so that each receiver method can just call$self->line
to get the line number. Also this method can avoid the dynamic Perl array creation inline_column
because only the line number is requested.