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

Extending PPI #270

Open
jackdeguest opened this issue Mar 12, 2022 · 2 comments
Open

Extending PPI #270

jackdeguest opened this issue Mar 12, 2022 · 2 comments

Comments

@jackdeguest
Copy link

jackdeguest commented Mar 12, 2022

Is there a possibility to extend PPI recognised grammar. I know there is PPI::Transform and I looked at it, but it seems more of a post-processing api.
What I have in mind is a way to have something like:

async sub hello
{
    print( "Hello world\n" );
}

be recognised as a PPI::Statement::Sub object and not as a PPI::Statement object.

@zmughal
Copy link

zmughal commented Apr 22, 2022

At least for that specific case (specialised syntax for sub-like blocks), I believe it would be a case of augmenting the lexer. In the past I have added keywords defined by Function::Parameters (e.g., method) by adding to the %PPI::Lexer::STATEMENT_CLASSES hash.

If you are willing to use PPR + Babble instead, it is pretty easy to extend the grammar by using pieces of the existing grammar. I have an example of this in this PR that adds a class keyword in the tests.


I can imagine a plugin that takes

async sub { ... }

and turns it into

sub :async { ... }

then processes it with the PPI interface and then transforms back into

async sub { ... }

@zmughal
Copy link

zmughal commented Apr 22, 2022

See also #213.

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