feat(gui): Implement @symbol regex parser for on-demand definition lookup

This commit is contained in:
2026-03-07 14:57:52 -05:00
parent 84396dc13a
commit a0a9d00310
4 changed files with 38 additions and 3 deletions

View File

@@ -59,7 +59,7 @@ This file tracks all major tracks for the project. Each track has its own detail
12. [x] **Track: Manual Skeleton Context Injection**
*Link: [./tracks/manual_skeleton_injection_20260306/](./tracks/manual_skeleton_injection_20260306/)*
13. [ ] **Track: On-Demand Definition Lookup**
13. [~] **Track: On-Demand Definition Lookup**
*Link: [./tracks/on_demand_def_lookup_20260306/](./tracks/on_demand_def_lookup_20260306/)*
---

View File

@@ -5,8 +5,8 @@
## Phase 1: Symbol Parsing
Focus: Parse @symbol syntax from user input
- [ ] Task 1.1: Initialize MMA Environment
- [ ] Task 1.2: Implement @symbol regex parser
- [x] Task 1.1: Initialize MMA Environment
- [~] Task 1.2: Implement @symbol regex parser
- WHERE: `src/gui_2.py` in `_send_callback()`
- WHAT: Extract @SymbolName patterns
- HOW:

View File

@@ -2,6 +2,7 @@ import threading
import time
import sys
import os
import re
from typing import Any, List, Dict, Optional, Callable
from pathlib import Path
import json
@@ -38,6 +39,13 @@ def hide_tk_root() -> Tk:
root.wm_attributes("-topmost", True)
return root
def parse_symbols(text: str) -> list[str]:
"""
Finds all occurrences of '@SymbolName' in text and returns SymbolName.
SymbolName can be a function, class, or method (e.g. @MyClass, @my_func, @MyClass.my_method).
"""
return re.findall(r"@([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)", text)
class GenerateRequest(BaseModel):
prompt: str
auto_add_history: bool = True

View File

@@ -0,0 +1,27 @@
import pytest
from src.app_controller import parse_symbols
def test_parse_symbols_basic():
text = "Check @MyClass and @my_func."
symbols = parse_symbols(text)
assert symbols == ["MyClass", "my_func"]
def test_parse_symbols_methods():
text = "Calling @MyClass.my_method and @AnotherClass.method_name."
symbols = parse_symbols(text)
assert symbols == ["MyClass.my_method", "AnotherClass.method_name"]
def test_parse_symbols_no_symbols():
text = "This string has no symbols."
symbols = parse_symbols(text)
assert symbols == []
def test_parse_symbols_mixed():
text = "Mixed text: @Class1, @func_2, and some text @MyClass.method."
symbols = parse_symbols(text)
assert symbols == ["Class1", "func_2", "MyClass.method"]
def test_parse_symbols_edge_cases():
text = "@LeadingSymbol and @SymbolAtEnd"
symbols = parse_symbols(text)
assert symbols == ["LeadingSymbol", "SymbolAtEnd"]