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

Allow to customize some behaviors of Lexer, so that Extension instances can know raw block begin and end info. #1963

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frankdu
Copy link

@frankdu frankdu commented Apr 10, 2024

Problem:
Currently, the "data" tokens don't have the information about if the "data" is inside the raw/endraw block, or not. This limit the Extension object's ability to treat the "data" tokens differently. I'm developing a jinja extension which is limited by this.

Feature Request:

Allow Lexer to optionally choose to emit the raw_begin and raw_end tokens, v.s. ignore them (current behaviors)
Allow Environment to switch the lexer provider, so that you can inject your customized Lexer instances. For example, a customized one when an Extension is added, or when it's in testing.

Fixes

  1. Allow token_begin and token_end in stream to enable Extensions to treat "data" tokens differently
  2. Add the lexer_provider attrib to Environment, so to allow provide custom lexer in different use cases (e.g. testing)

Test Plan:

  1. Run pytest

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

…at "data" tokens differently

Add the lexer_provider attrib to Environment to allow provide custom lexer, e.g. for testing.

Test Plan:
- Run `pytest`
Test Plan:
- Run `tox run -e typing`
@frankdu frankdu changed the title Allow to customize some behaviors of Lexer, so that Extension instances get can the raw block begin and end info. Allow to customize some behaviors of Lexer, so that Extension instances can know raw block begin and end info. Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant