Skip to content

Mapping language: Parser (AST construction) #16

@alvinreal

Description

@alvinreal

Description

Parse token stream into an AST representing mapping operations.

AST Nodes (v0.2.0 subset)

enum Statement {
    Rename { from: Path, to: Path },
    Select { paths: Vec<Path> },
    Drop { paths: Vec<Path> },
    Set { path: Path, expr: Expr },
    Default { path: Path, expr: Expr },
    Cast { path: Path, target_type: Type },
}

enum Expr {
    Literal(Value),
    Path(Path),
    FunctionCall { name: String, args: Vec<Expr> },
    BinaryOp { left: Box<Expr>, op: Op, right: Box<Expr> },
    UnaryOp { op: Op, expr: Box<Expr> },
}

TDD Tests

  • rename: rename .a -> .b → Rename node
  • select: select .a, .b, .c → Select with 3 paths
  • drop: drop .x → Drop with 1 path
  • set with literal: set .x = 42 → Set with Literal expr
  • set with path: set .x = .y → Set with Path expr
  • set with function: set .x = lower(.y) → Set with FunctionCall
  • set with binary op: set .x = .a + .b → Set with BinaryOp
  • default: default .x = "hello" → Default node
  • cast: cast .x as int → Cast node for each type
  • multi-statement: multiple lines parse as Vec
  • comments ignored: parser skips comment tokens
  • Error: missing arrow in rename: clear error
  • Error: missing = in set: clear error
  • Error: unknown keyword: clear error with suggestion

Part of #2

Metadata

Metadata

Assignees

No one assigned

    Labels

    mappingMapping languagetestingTesting infrastructurev0.2.0Milestone: v0.2.0 Mapping Language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions