Skip to content

Add JEP-18 lexical scoping with let expressions - #138

Merged
GrahamCampbell merged 1 commit into
2.10from
jep-18-lexical-scope
Nov 17, 2026
Merged

GrahamCampbell merged 1 commit into
2.10from
jep-18-lexical-scope

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

JEP-18 adds lexical scoping to JMESPath, so that an expression can refer to values outside its current element by binding them to variables with let $name = expression in expression. This implements it in both runtimes. let and in are contextual keywords and stay usable as identifiers, bindings are evaluated before the body and are not visible to each other, inner bindings shadow outer ones, and referencing an undefined variable is an error when it is evaluated rather than when the expression is parsed.

The interpreter evaluates the body of a let expression on a copy of itself that holds the bindings, so evaluating expressions that do not use variables costs nothing extra and expression references keep the variables they were created with. The compiler resolves each variable to a PHP local when it generates code, and passes the visible ones to the interpreter for expression references.

This supersedes #80 and builds on its lexer and parser work. The compliance cases are the ones from the JEP plus further cases for pipes, expression references, a null current node and invalid syntax, all of which run against both runtimes.

Co-authored-by: Harry Vennik <h.vennik@topgeschenken.nl>
@GrahamCampbell
GrahamCampbell marked this pull request as ready for review November 17, 2026 14:49
@GrahamCampbell
GrahamCampbell merged commit 8346b99 into 2.10 Nov 17, 2026
44 checks passed
@GrahamCampbell
GrahamCampbell deleted the jep-18-lexical-scope branch November 17, 2026 14:50
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.

1 participant