-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Pattern-Based Code Fixing System Using Parser Combinator #111
Comments
This was referenced Jan 17, 2025
notJoon
added a commit
that referenced
this issue
Jan 17, 2025
# Description Inital feature for auto-fixer v2. Implements a lexer and parser for processing Comby-style metavarible expressions (e.g., `:[var]` and `:[[function]]`). This package serves as the first parsing phase before main syntax parsing. Key features: - Lexer that tokenizes metavariable patterns and surrounding text - Parser that generates AST with pattern, hole, text, and block nodes - Support for both short (`:[name]`) and long (`:[[name]]`) metavariable hole-expression forms - Proper handling of nested block structures and whitespace This feature will replace the exsting AST-based auto fix functionality. ## Related Issue #111
TODO: Update metavariable parser to use state machine and SIMD after support all expressions. Resolved: #113 |
notJoon
added a commit
that referenced
this issue
Jan 18, 2025
# Description A hole pattern is a special syntax used in pattern matching that acts as a placeholder or "wildcard" in a pattern. Think of it as a variable that can match and capture different parts of code while searching through source code. ```go // Pattern with holes if :[[condition]] { :[[body]] } // Can match code like: if x > 0 { return true } // Or: if isValid(user) { doSomething() } ``` ## Key Changes 1. Added support for typed hole patterns with format `:[[name:type]]` 2. Implemented quantifier support for hole patterns (`*`, `+`, `?`) 3. Enhanced lexer to properly parse and tokenize new pattern syntax 4. Added hole configuration system to manage pattern types and quantifiers 5. Updated parser to handle the new hole types and configurations 6. Added comprehensive test coverage for new features ## New Pattern Syntax | Syntax | Description | Example | Notes | |--------|-------------|---------|-------| | `:[name]` | Basic hole pattern | `:[var]` | Matches any content | | `:[[name]]` | Long-form hole pattern | `:[[expr]]` | Same as basic, but with double brackets | | `:[[name:identifier]]` | Identifier-typed hole | `:[[var:identifier]]` | Matches only valid identifiers | | `:[[name:block]]` | Block-typed hole | `:[[body:block]]` | Matches code blocks | | `:[[name:whitespace]]` | Whitespace-typed hole | `:[[ws:whitespace]]` | Matches whitespace | | `:[[name:expression]]` | Expression-typed hole | `:[[expr:expression]]` | Matches expressions | ### Quantifiers | Quantifier | Description | Example | |------------|-------------|---------| | `*` | Zero or more | `:[[stmt:block]]*` | | `+` | One or more | `:[[expr:expression]]+` | | `?` | Zero or one | `:[[ws:whitespace]]?` | ## Example Usage ```go // Before if :[condition] { :[body] } // After - with types and quantifiers if :[[cond:expression]] { :[[stmt:block]]* } ``` ## Next Steps Future improvements could include: - Implementing actual pattern matching logic for each hole type - Adding pattern validation based on types - Enhancing error reporting for invalid patterns - Adding more specialized hole types for specific use cases ## Related Issue #111
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
The current system modifies code based on the line numbers and offsets. While this approach is simple, but the limitation is definitely bold.
We aim to address these limitations by introducing a Comby-style pattern matching system, by using parser combinator.
Implementation Strategy
Phase 1: Basic Pattern Engine
Phase 2: Advanced Features
Each of these tasks should be migrated incrementally as they proceeds.
Design
1. Pattern Matching Engine
2. New Fixer Interface
3. Pattern Definition Format
Example Usage
Metavariable Syntax
Defines metavariable syntax for Comby-style pattern matching
1. Basic Metavariables
2. Special Metavariables
3. Constraints
4. Example
The text was updated successfully, but these errors were encountered: