Skip to content

Implement ANTLR AST transformation with exact position mapping in links store - #319

Open
konard wants to merge 3 commits into
mainfrom
issue-77-5be16ece
Open

Implement ANTLR AST transformation with exact position mapping in links store#319
konard wants to merge 3 commits into
mainfrom
issue-77-5be16ece

Conversation

@konard

@konard konard commented Sep 13, 2025

Copy link
Copy Markdown
Member

Summary

This PR implements ANTLR-based AST transformation functionality that transforms code into its Abstract Syntax Tree (AST) inside the links store, with each AST node mapped to its exact position in the source code text.

Key Features Implemented

  • Complete Position Mapping: Each AST node includes exact character positions, line numbers, and column positions in the source code
  • Links Store Integration: AST nodes are stored using Platform.Data.Doublets with hierarchical relationships preserved
  • C# Language Support: Basic C# constructs (classes, methods, properties, statements) are recognized and parsed
  • Comprehensive API: Full integration with existing FileStorage class

Files Added/Modified

  • New: csharp/Storage/AST/AstNode.cs - Core AST node representation with position mapping
  • New: csharp/Storage/AST/CSharpAstTransformer.cs - ANTLR-based C# code transformation
  • New: csharp/Storage.Tests/ - Complete test suite with 6 passing tests
  • Modified: csharp/Storage/LocalStorage/FileStorage.cs - Added AST transformation methods
  • Modified: csharp/Storage/Storage.csproj - Added ANTLR4.Runtime.Standard dependency

API Usage

using var storage = new FileStorage("data.db");

// Transform C# code into AST and store in links
var rootNodeLink = storage.TransformCodeToAst(csharpCode);

// Retrieve all AST nodes from links store  
var allNodes = storage.GetAllAstNodes();

// Get detailed position info for any node
var nodeInfo = storage.GetAstNodeInfo(nodeLink);

Links Store Structure

AST nodes are stored as: AST_NODE_MARKER -> (NODE_TYPE -> (TEXT -> POSITION))

  • Position data includes: StartPos, EndPos, StartLine, StartCol, EndLine, EndCol
  • Parent-child relationships preserved through additional links

Test Plan

✅ All 6 tests passing:

  • AST transformation and links store integration
  • Exact position mapping verification
  • Parent-child relationship handling
  • Error handling for invalid inputs
  • Node retrieval and information extraction
dotnet test csharp/Storage.Tests/
# Test Run Successful: 6/6 tests passed

🤖 Generated with Claude Code


Resolves #77

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #77
@konard konard self-assigned this Sep 13, 2025
…ks store

- Add ANTLR4 package dependency to Storage project
- Create AstNode class with complete text position mapping (line, column, character positions)
- Implement CSharpAstTransformer for basic C# language constructs
- Integrate AST storage into FileStorage with links store backend
- Add comprehensive test suite with 6 passing tests
- Include usage examples and documentation
- Map each AST node to exact location in source code text as required by issue #77

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Use Antrl to transform code into its AST inside links store Implement ANTLR AST transformation with exact position mapping in links store Sep 13, 2025
@konard
konard marked this pull request as ready for review September 13, 2025 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Antrl to transform code into its AST inside links store

1 participant