Skip to content
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

feat(fixer_v2): Hole Pattern Syntax for Pattern Matching #113

Merged
merged 4 commits into from
Jan 18, 2025
Merged

Conversation

notJoon
Copy link
Contributor

@notJoon notJoon commented Jan 17, 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.

// 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

// 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

@notJoon notJoon added the T-fixer Type: Auto fix label Jan 17, 2025
@notJoon notJoon merged commit c4f86e3 into main Jan 18, 2025
5 checks passed
@notJoon notJoon deleted the hole-expr branch January 18, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-fixer Type: Auto fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant