Skip to content

[Lisp Analyzer] Create PTC-Lisp CoreAST type definitions and analyze infrastructure #108

@andreasronge

Description

@andreasronge

Summary

Create the foundational infrastructure for the PTC-Lisp analyzer: CoreAST type definitions, public API skeleton, and basic literal/symbol analysis. This establishes the structure for subsequent analyzer development while implementing the simplest transformations first.

Context

Architecture reference: docs/ptc-lisp-analyze-plan.md - Sections 1-3
Dependencies: Parser phase complete (issue #106 closed)
Related issues: None (first Lisp analyzer issue)

Current State

  • lib/ptc_runner/lisp/ contains parser infrastructure (ast.ex, parser.ex, parser_helpers.ex)
  • Parser produces RawAST with tagged tuples like {:symbol, :name}, {:ns_symbol, :ctx, :input}
  • No CoreAST or Analyze module exists
  • The analyze plan specifies the complete CoreAST structure and transformation approach

Acceptance Criteria

  • lib/ptc_runner/lisp/core_ast.ex created with CoreAST type specs
  • lib/ptc_runner/lisp/analyze.ex created with public API skeleton
  • Analyzer handles literals: nil, true, false, integers, floats, strings, keywords
  • Analyzer transforms {:symbol, name}{:var, name}
  • Analyzer transforms {:ns_symbol, :ctx, key}{:ctx, key}
  • Analyzer transforms {:ns_symbol, :memory, key}{:memory, key}
  • Analyzer handles collections: vectors and maps (recursive analysis)
  • Analyzer returns {:ok, core_ast} or {:error, error_reason}
  • Unit tests cover literals, symbols, namespaced symbols, and collections
  • mix compile --warnings-as-errors passes
  • Existing tests pass

Implementation Hints

Files to create:

  • lib/ptc_runner/lisp/core_ast.ex - CoreAST type specs (see plan Section 1)
  • lib/ptc_runner/lisp/analyze.ex - Analyze module with analyze/1 function (see plan Section 2-3)
  • test/ptc_runner/lisp/analyze_test.exs - Unit tests

Patterns to follow:

  • See lib/ptc_runner/lisp/parser.ex for error handling patterns
  • Use tagged tuples for all CoreAST nodes, matching the plan spec
  • Follow {:ok, result} | {:error, reason} pattern consistently

Edge cases to consider:

  • Empty vector []{:vector, []}
  • Empty map {}{:map, []}
  • Nested collections should recursively analyze
  • Unknown namespace symbols (not ctx/memory) → {:var, name} (treat as regular symbol)

Test Plan

Unit tests:

  • Literals pass through: nil, true, false, integers, floats
  • Strings: {:string, "hello"}{:string, "hello"}
  • Keywords: {:keyword, :name}{:keyword, :name}
  • Simple symbols: {:symbol, :filter}{:var, :filter}
  • Namespaced symbols: {:ns_symbol, :ctx, :input}{:ctx, :input}
  • Namespaced symbols: {:ns_symbol, :memory, :results}{:memory, :results}
  • Empty vector: {:vector, []}{:vector, []}
  • Vector with elements: {:vector, [1, 2]}{:vector, [1, 2]}
  • Empty map: {:map, []}{:map, []}
  • Map with entries: {:map, [{{:keyword, :a}, 1}]}{:map, [{{:keyword, :a}, 1}]}
  • Nested collections: vectors in maps, maps in vectors

Integration test (optional):

  • Parse source → analyze → verify CoreAST structure

Out of Scope

  • Special forms: let, if, fn, when, cond (subsequent issue)
  • Threading macros: ->, ->> (subsequent issue)
  • Logic operators: and, or (subsequent issue)
  • Predicate builders: where, all-of, any-of, none-of (subsequent issue)
  • Tool calls: call (subsequent issue)
  • Generic function calls: {:list, [...]}{:call, ...} (subsequent issue)
  • Pattern analysis / destructuring (subsequent issue)
  • Integration with PtcRunner.Lisp.run/2 (Phase 4)

Documentation Updates

  • None required for this issue (internal implementation)
  • Documentation updates for the analyzer will be done in the Integration phase

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase:analyzerPTC-Lisp analyzer implementationptc-lispPTC-Lisp language implementationready-for-implementationIssue is approved and ready to implement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions