-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It would be cool if kajiki could generate code using PEP622 pattern matching when running on python3.10+ Benefits Speed Motivation I wanted to do something easy Directive Lookup py:match was used by genshi, but it's free within kajiki py:case is used together with py:switch (and py:else) Directive Proposal py:match (with on attribute) and py:case (with match attribute instead of value) so kajiki have always been ahead of time :D running the switch example I see the code generated is In [5]: print(Template.py_text) class template: @kajiki.expose def __main__(): yield '<div>\n' yield self.__kj__.escape(i) yield local.__kj__.gettext(' is') yield ' ' local.__kj__.push_switch(i % 2) if False: pass elif local.__kj__.case(0): yield local.__kj__.gettext('even') else: yield local.__kj__.gettext('odd') local.__kj__.pop_switch() yield '</div>' template = kajiki.Template(template) I see switches are pushed to a list to allow them to be nested. and case does the equality check But of course due to the concepts behind it being different, the two approaches are incompatible. I'm doing it. I noticed after the dom is parsed with sax, it is reconstructed due to some optimization, i was loosing the attribute tough, so i added support to define tuples of attributes in the directives. I also noticied the flattener does not flatten my deep stuff. But since the backtrace was just crazy, instead of fixing the flattener I made a bad patch for generate_python ok, I got the loose of the attribute was caused because py:case can be used even within other tags. patched. This is a squash of 14 commits: tests and doc added too structural pattern matching added some tests for SPM patched py:case directive used as attribute, added doc for pep622 test fixes skip pep622 tests on python<3.10 one more test black reformatting, flake8 decected F401 i don't like isort follow @jackrosenthal review comment py:match on genshi migration guide rephrasing docs, adding newline to gitignore support for python 3.11.0b3 fixed? docs: Add table with summary of the how XML directives can be used docs: add py:match to directives summary added in PR #71 Closes #76, #74
- Loading branch information
1 parent
48b0dd6
commit d80a6a3
Showing
8 changed files
with
225 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,9 @@ pypyenv3 | |
.mr.developer.cfg | ||
.project | ||
.pydevproject | ||
|
||
|
||
# emacs | ||
\#*\# | ||
.\#* | ||
flycheck_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters