Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a handy line() method in Pegex::Receiver #36

Open
agentzh opened this issue Mar 29, 2015 · 4 comments
Open

Add a handy line() method in Pegex::Receiver #36

agentzh opened this issue Mar 29, 2015 · 4 comments

Comments

@agentzh
Copy link
Contributor

agentzh commented Mar 29, 2015

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 handy line() 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 in line_column because only the line number is requested.

@agentzh agentzh changed the title Handy line() method in Pegex::Receiver Add a handy line() method in Pegex::Receiver Mar 29, 2015
@ingydotnet
Copy link
Collaborator

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}};
}

@agentzh
Copy link
Contributor Author

agentzh commented Apr 1, 2015

@ingydotnet Not too bad, though a bit ugly, especially as part of the Pegex API. Started missing macros in Perl 5 :)

@ingydotnet
Copy link
Collaborator

@agentzh better ideas welcome. :)

@agentzh
Copy link
Contributor Author

agentzh commented Apr 1, 2015

@ingydotnet Not really if you want the speed :) My original proposal looks cleaner though definitely a little bit slower :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants