Chasten: AST Pattern Detection Tool

August 2023 - May 2024

Project Overview

Chasten is a Python-based static analysis tool that uses XPath expressions to detect Abstract Syntax Tree (AST) patterns in code. This innovative approach enables custom linting rules without requiring complex frameworks or relying on imprecise regex pattern matching.

Key Features

  • AST-based code analysis for accurate pattern recognition
  • XPath query system for precise pattern specification
  • Integration with Large Language Models for natural language-to-XPath conversion
  • Custom rule creation without complex framework knowledge
  • More accurate than regex-based pattern matching
  • Extensible architecture for supporting multiple programming languages

Technical Implementation

Chasten works by parsing source code into an Abstract Syntax Tree (AST), converting the tree into an XML representation, and then applying XPath queries to find specific patterns. This approach offers several advantages:

  • Structural Analysis: By working with the AST, Chasten understands the structure of the code rather than just its text representation
  • Precision: XPath queries can target specific code constructs with higher accuracy than text-based searches
  • Flexibility: New patterns can be defined without modifying the core tool
  • Language Independence: The approach can be adapted to any programming language with an available AST parser

The LLM integration component allows users to describe the pattern they want to find in natural language. The system then converts this description into an appropriate XPath query, making the tool accessible to users without XPath expertise.

Applications

Chasten has several practical applications in software development:

  • Custom code quality enforcement in development teams
  • Educational tools for teaching programming patterns and anti-patterns
  • Code refactoring assistance
  • Security vulnerability detection
  • Code style consistency enforcement