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
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){:symbol, :name},{:ns_symbol, :ctx, :input}Acceptance Criteria
lib/ptc_runner/lisp/core_ast.excreated with CoreAST type specslib/ptc_runner/lisp/analyze.excreated with public API skeletonnil,true,false, integers, floats, strings, keywords{:symbol, name}→{:var, name}{:ns_symbol, :ctx, key}→{:ctx, key}{:ns_symbol, :memory, key}→{:memory, key}{:ok, core_ast}or{:error, error_reason}mix compile --warnings-as-errorspassesImplementation 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 withanalyze/1function (see plan Section 2-3)test/ptc_runner/lisp/analyze_test.exs- Unit testsPatterns to follow:
lib/ptc_runner/lisp/parser.exfor error handling patterns{:ok, result} | {:error, reason}pattern consistentlyEdge cases to consider:
[]→{:vector, []}{}→{:map, []}{:var, name}(treat as regular symbol)Test Plan
Unit tests:
nil,true,false, integers, floats{:string, "hello"}→{:string, "hello"}{:keyword, :name}→{:keyword, :name}{:symbol, :filter}→{:var, :filter}{:ns_symbol, :ctx, :input}→{:ctx, :input}{:ns_symbol, :memory, :results}→{:memory, :results}{:vector, []}→{:vector, []}{:vector, [1, 2]}→{:vector, [1, 2]}{:map, []}→{:map, []}{:map, [{{:keyword, :a}, 1}]}→{:map, [{{:keyword, :a}, 1}]}Integration test (optional):
Out of Scope
let,if,fn,when,cond(subsequent issue)->,->>(subsequent issue)and,or(subsequent issue)where,all-of,any-of,none-of(subsequent issue)call(subsequent issue){:list, [...]}→{:call, ...}(subsequent issue)PtcRunner.Lisp.run/2(Phase 4)Documentation Updates