Add dot-access syntax for maps (u.foo)#8
Conversation
Adds a highest-precedence postfix `.field` operator, parsed via a new parse_postfix layer (mirrored for if-conditions) and evaluated against Value::Map. Also fixes a prerequisite gap where MapLiteral expressions were never evaluated into Value::Map at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Line in the new FieldAccess eval arm exceeded rustfmt's width limit. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@claude Review this PR |
|
Claude finished @aisrael's task in 4m 16s —— View job Code Review: Add dot-access syntax for maps (u.foo)Todo list
SummaryThis is a clean, well-scoped change. The prerequisite bug fix ( Observations (non-blocking)
None of the above are blockers — the implementation is correct, thoroughly tested, and consistent with the codebase's existing conventions. |
…add CHANGELOG - Sort keys before printing Value::Map so Display output is deterministic now that map literals actually evaluate. - Simplify m.get(field.as_str()) to m.get(field) (Borrow coercion). - Add CHANGELOG entry for v0.1.1 covering the MapLiteral fix and dot-access syntax. Addresses github.com//pull/8#issuecomment-4861585295 items 1, 3, 5. Items 2 (number-literal/dot parsing) and 4 (parser duplication) left as-is per the reviewer's own assessment that they're pre-existing / consistent with precedent, not defects introduced by this PR. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Addressed the review feedback in a7d78be:
Left as-is: #2 (number-literal/dot interaction) and #4 (parser duplication) — both were explicitly flagged as pre-existing behavior / consistent with existing precedent rather than defects introduced by this PR, so no change needed there. |
Summary
.fieldoperator sou.fooreads a field out of a map (e.g.u = {foo: "bar"}; u.foo→"bar")Expr::MapLiteralwas never evaluated intoValue::Mapat all — map literals unconditionally raisedInvalidOperandTypeChanges
src/ast/expr.rs: newExpr::FieldAccess(Box<Expr>, String)variant,Displayimpl,field_accessconstructor, and Display testssrc/runtime.rs:MapLiteralnow evaluates toValue::Map; newFieldAccesseval arm (looks up the key onValue::Map,InvalidOperandTypeon non-map bases)src/errors.rs: newRuntimeError::NoSuchField(String)for missing keyssrc/parser/expr.rs: newparse_postfixlayer (plus a mirroredparse_if_condition_postfixforif-conditions) wired in betweenparse_unaryandparse_primary, so.fieldbinds tighter than unary operators (-u.foo==-(u.foo)) and works inifconditions (if u.active ...);.binds tightly with no surrounding whitespace, matching this codebase's existing "tight" unary-operator conventionsrc/eval/mod.rs,tests/features.rs,features/ast/dot_access.feature: new tests covering plain/chained access, missing-field and non-map errors, and parse-level precedence/if-condition behaviorTesting
cargo test— 174 tests passing (unit, integration, and cucumber feature suites)cargo clippy --all-targets— no issuesu = {a: {b: 42}}; u.a.b→42Checklist