Skip to content

feat(kdl): rename keywords for clarity (alias, as, var, where) #179

@pesap

Description

@pesap

Summary

Rename four KDL keywords for clarity and consistency, with backwards compatibility via deprecation warnings.

Parent: #176
Blocked by: #178

Keyword Changes

Before After Purpose
map X from="col" alias X column="col" Data column rename
set X alias=g set X as=g Set shorthand
control x lower=0 var x lower=0 Decision variable
filter { cond } where { cond } Set subsetting

Acceptance Criteria

  • Parser accepts alias X column="col"; deprecates map X from="col"
  • Parser accepts set X as=g; deprecates set X alias=g
  • Parser accepts var x lower=0; deprecates control x lower=0
  • Parser accepts where { cond }; deprecates filter { cond }
  • All deprecated forms emit warnings with migration hints (via feat(kdl): add deprecation warning infrastructure #178)
  • AST output is identical for old and new syntax
  • Test: new syntax parses to correct AST
  • Test: old syntax parses to same AST + emits deprecation warning
  • Test: mixed old/new syntax in same file works

Implementation Notes

Location: crates/arco-kdl/src/source/parser.rs

Pattern per keyword:

match child.name().value() {
    "alias" => { /* new syntax */ }
    "map" => {
        context.warn(Deprecation::new("map", "alias", child.span()));
        /* parse as alias */
    }
    // ...
}
  • AFK — straightforward parser additions with clear pattern

TDD Implementation Plan

Prerequisites

RED/GREEN Cycles

Cycle 1: var keyword (simplest, isolated)

RED: Test that var x lower=0 {...} parses to same AST as control

#[test]
fn var_keyword_parses_as_control() {
    let new_syntax = r#"model M { var x lower=0 { index a } minimize O { x[a] } }"#;
    let old_syntax = r#"model M { control x lower=0 { index a } minimize O { x[a] } }"#;
    // Assert both produce identical ControlDecl
}

GREEN: Add "var" => arm in parse_model() (line 85) calling parse_control()

Cycle 2: control deprecation warning

RED: Test that control emits deprecation warning

#[test]
fn control_keyword_emits_deprecation() {
    let text = r#"model M { control x { index a } minimize O { x[a] } }"#;
    // Assert warning contains "control", "var", migration hint
}

GREEN: Add deprecation emission before parse_control() call for "control" arm

Cycle 3: alias keyword (data block)

RED: Test alias X column="col" parses as MapDecl

#[test]
fn alias_keyword_parses_in_data_block() {
    let text = r#"data D source="f.csv" { alias X column="name" }"#;
    // Assert MapDecl with name="X", source="name"
}

GREEN: Add "alias" => arm in parse_data() (line 133) with column property

Cycle 4: map deprecation warning

RED: Test map emits deprecation
GREEN: Add deprecation to "map" arm

Cycle 5: set as= property

RED: Test set X as=g parses with alias "g"

#[test]
fn set_as_property_parses() {
    let text = r#"set X as=g"#;
    // Assert SetDecl has alias = Some("g")
}

GREEN: Add .get("as") fallback in parse_set() (line 255)

Cycle 6: set alias= deprecation

RED: Test alias= emits deprecation
GREEN: Check for alias= property and emit warning

Cycle 7: where keyword (set filter)

RED: Test where { cond } parses as filter

#[test]
fn where_keyword_parses_as_filter() {
    let text = r#"set thermal { in gen; where { type == "thermal" } }"#;
    // Assert filter_expression is set
}

GREEN: Add "where" => arm in:

  • parse_set() (line 233)
  • parser_helpers.rs (lines 54, 94)
  • surface.rs (lines 10, 121)

Cycle 8: filter deprecation

RED: Test filter emits deprecation
GREEN: Add deprecation to all "filter" arms

Cycle 9: Mixed syntax integration

RED: Test file with mix of old/new syntax
GREEN: Should already pass if cycles 1-8 are complete

Files to Modify

  • crates/arco-kdl/src/source/parser.rs
  • crates/arco-kdl/src/source/parser_helpers.rs
  • crates/arco-kdl/src/source/surface.rs

Acceptance Verification

cargo test -p arco-kdl
cargo clippy -p arco-kdl -- -D warnings

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions