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

Accept top level statements #177

Closed
wants to merge 2 commits into from

Conversation

calebdw
Copy link
Collaborator

@calebdw calebdw commented May 30, 2023

Closes #168

Checklist:

  • All tests pass in CI
  • There are sufficient tests for the new fix/feature
  • Grammar rules have not been renamed unless absolutely necessary (x rules renamed)
  • The conflicts section hasn't grown too much (x new conflicts)
  • The parser size hasn't grown too much (master: STATE_COUNT, PR: STATE_COUNT) (check the value of STATE_COUNT in src/parser.c)

Copy link
Contributor

@aryx aryx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests in corpus/ and regenerate the parser.c and other files

grammar.js Outdated
)),
// accept statements at top-level to enable
// parsing of partial code snippets (e.g, in markdown; see #168).
optional(repeat($._statement)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the statement will actually be parsed because of the optional($.text) at the top that may "eat" every tokens.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm...you're right, I tried moving this line to the top of the program but the text still swallows everything up (see failing test)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more complicated than I originally thought....do you have any idea on how to allow top-level statement parsing for injected code snippets while still allowing HTML?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Maybe @maxbrunsfeld knows

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might need to create another parser that only parses PHP, say phpo (for php-only), similar to the markdown and markdown-inline parsers.

@calebdw
Copy link
Collaborator Author

calebdw commented Jun 23, 2023

Closing as accepting top level statements is not possible with this parser in its current state: the text is too hungry.

As mentioned in the above comment, the solution is probably to create two separate parsers in this repo (similar to the markdown parser), one which is php-base or php-only and the other (php) which inject the php-base into the php tag nodes

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

Successfully merging this pull request may close these issues.

Inject PHP code without PHP tags
2 participants