Extending frame application on already-defined structures and JSON strings#31
Open
luca-anzalone wants to merge 6 commits into
Open
Extending frame application on already-defined structures and JSON strings#31luca-anzalone wants to merge 6 commits into
luca-anzalone wants to merge 6 commits into
Conversation
gabkebula
requested changes
Jul 8, 2026
luca-anzalone
added a commit
that referenced
this pull request
Jul 9, 2026
1233c4b to
ee307ff
Compare
gabkebula
approved these changes
Jul 9, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Frame application (
{Frame} .../... {Frame}) previously only worked on a struct literal written in the same statement — the grammar hard-wiredframe_applyto alist_literal. This meant you could write[[v] = (name:"x", age:27){Person}]but could not apply a frame to a value already held in a variable ([[r] = [my_struct]{Person}]).This PR lets a frame be applied to already-defined operands — variables (including path access like
[x:field]) and strings containing JSON — while preserving the existing prefix/postfix = strict/loose convention and the existing nested-frame semantics.Type of change
Solution
nxs_v2_grammar.lark): thestructurerule now accepts avariableoperand in addition tolist_literal, in both prefix and postfix positions. Operands are inlined (rather than via an intermediateframeablenonterminal) to avoid a reduce/reduce collision withatom; this mirrors the existinglist_literal-with-optional-frame_applypattern, so it stays LALR-safe.node.py):SchemedCollection.valuewidened toCollection | Variable;to_nxs()/__str__()emit aVariableoperand without wrapping parens ([x] {Person}) so round-trips stay exact.Collection.__init__'svaluetype was widened to includeVariableto resolve the type-checker warning at the forwardedsuper().__init__call.runtime.py): addedStruct.from_python(), a recursivedict/list→ nested-Structconverter. Also removed the now-unnecessary_extract_struct"__"-unwrapping workaround fromapply_prefix/apply_postfix.interpreter.py):eval_schemed_collectionnow evaluates a literal viaeval_collectionas before, or resolves a variable viainterpret_expression, then coerces the result to aStruct. A string operand is parsed as JSON, with an LLM-repair fallback for quasi-JSON (e.g. trailing commas); a JSON scalar (non-object/array) raises a runtime error.Strict vs loose stays tied to prefix/postfix:
{Frame} xis strict (all slots required,noneon mismatch),x {Frame}is loose (defaults + coercion). Nested frames validate automatically via the existingapply_prefix/apply_postfixrecursion, for literals, variables, and JSON alike.Testing
pytest)Full suite: 906 passed, 30 skipped. New tests cover: parsing
[x]{Frame}/{Frame}[x]/ path-access operands;to_nxsround-trip for variable operands; runtimeStruct.from_python(dict/list/nested); interpreter eval of frame-on-variable (strict + loose), frame-on-path-access, frame-on-JSON-string, the quasi-JSON LLM-repair path, the scalar-JSON error path, and nested-frame validation on both a variable and a JSON string (Personwith a nestedDateframe).Checklist
devRelease Notes
Frames can now be applied to already-defined structures: variables (including nested-field access) and strings holding JSON. JSON payloads are parsed automatically, with malformed/quasi-JSON repaired via an LLM before application. Nested frames are validated recursively in all cases.
Closes: kebula-it/nemantix-enterprise#30