forked from jmespath/jmespath.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of jep-11, the let function
Proposed in jmespath/jmespath.site#6. I tried to pick an implementation that was as minimally invasive as possible. It works by making three changes. First we need to track scope, and share this information between the interpreter and the function module. They both take a reference to a scope object that allows you to push/pop scopes. The ``let()`` function will push the user provided lexical scope onto the scope chain before evaluating the expref, and pop the scope after evaluating the expref. The second change needed is to change how identifiers are resolved. This corresponds to visiting the ``field`` AST node. As detailed in JEP 11, after failing to resolve the field in the current object, we call back to the scope chain. The third change is to bind the current value (the context) in which an expref is first created. This wasn't needed before because for functions that take an expref, such as ``sort_by``, ``max_by``, and ``min_by``, they evaluate the expref in the context of each list element. However, with ``let()``, we want to evaluate the expref in the context of the current object as specified when the expref was created. This also tracks the current object properly in the case of nested ``let()`` calls.
- Loading branch information
Showing
3 changed files
with
179 additions
and
6 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
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