feat(gui): Implement @symbol regex parser for on-demand definition lookup
This commit is contained in:
@@ -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**
|
12. [x] **Track: Manual Skeleton Context Injection**
|
||||||
*Link: [./tracks/manual_skeleton_injection_20260306/](./tracks/manual_skeleton_injection_20260306/)*
|
*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/)*
|
*Link: [./tracks/on_demand_def_lookup_20260306/](./tracks/on_demand_def_lookup_20260306/)*
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
## Phase 1: Symbol Parsing
|
## Phase 1: Symbol Parsing
|
||||||
Focus: Parse @symbol syntax from user input
|
Focus: Parse @symbol syntax from user input
|
||||||
|
|
||||||
- [ ] Task 1.1: Initialize MMA Environment
|
- [x] Task 1.1: Initialize MMA Environment
|
||||||
- [ ] Task 1.2: Implement @symbol regex parser
|
- [~] Task 1.2: Implement @symbol regex parser
|
||||||
- WHERE: `src/gui_2.py` in `_send_callback()`
|
- WHERE: `src/gui_2.py` in `_send_callback()`
|
||||||
- WHAT: Extract @SymbolName patterns
|
- WHAT: Extract @SymbolName patterns
|
||||||
- HOW:
|
- HOW:
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from typing import Any, List, Dict, Optional, Callable
|
from typing import Any, List, Dict, Optional, Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
@@ -38,6 +39,13 @@ def hide_tk_root() -> Tk:
|
|||||||
root.wm_attributes("-topmost", True)
|
root.wm_attributes("-topmost", True)
|
||||||
return root
|
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):
|
class GenerateRequest(BaseModel):
|
||||||
prompt: str
|
prompt: str
|
||||||
auto_add_history: bool = True
|
auto_add_history: bool = True
|
||||||
|
|||||||
27
tests/test_symbol_lookup.py
Normal file
27
tests/test_symbol_lookup.py
Normal 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"]
|
||||||
Reference in New Issue
Block a user