Skip to content

Commit 2e6c8fd

Browse files
refactoring
1 parent 47893bf commit 2e6c8fd

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

code2logic/analyzer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ProjectAnalyzer:
4848
'.jsx': 'javascript',
4949
'.ts': 'typescript',
5050
'.tsx': 'typescript',
51+
'.sql': 'sql',
5152
'.java': 'java',
5253
'.go': 'go',
5354
'.rs': 'rust',

code2logic/benchmarks/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_single_project(module_info, file_path: Path) -> ProjectInfo:
1616
return ProjectInfo(
1717
name=file_path.name,
1818
root_path=str(file_path.parent),
19-
languages={"python": 1},
19+
languages={getattr(module_info, "language", "python") or "python": 1},
2020
modules=[module_info],
2121
dependency_graph={},
2222
dependency_metrics={},

code2logic/chunked_reproduction.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import re
1515
from dataclasses import dataclass
16-
from typing import List
16+
from typing import List, Optional
1717

1818
from .utils import estimate_tokens
1919

@@ -348,10 +348,13 @@ def merge_chunk_codes(codes: List[str], file_name: str) -> str:
348348
class ChunkedReproducer:
349349
"""Reproduce code from chunked specifications."""
350350

351-
def __init__(self, client, model_name: str = 'default'):
351+
def __init__(self, client, model_name: str = 'default', max_tokens: Optional[int] = None):
352352
self.client = client
353353
self.model_name = model_name
354-
self.max_tokens = get_llm_limit(model_name) // 2 # Leave room for response
354+
if max_tokens is None:
355+
self.max_tokens = get_llm_limit(model_name) // 2 # Leave room for response
356+
else:
357+
self.max_tokens = int(max_tokens)
355358

356359
def reproduce(self, spec: str, fmt: str, file_name: str) -> ChunkedResult:
357360
"""Reproduce code from specification, chunking if needed."""

code2logic/parsers.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ def _parse_python(self, filepath: str, content: str) -> Optional[ModuleInfo]:
14491449
module = node.module or ''
14501450
for alias in node.names:
14511451
if alias.name == '*':
1452+
if module:
1453+
imports.append(f"{module}.*")
14521454
continue
14531455
imports.append(_combine_import_name(module, alias.name))
14541456
elif isinstance(node, ast.ClassDef):
@@ -1814,6 +1816,50 @@ def _parse_js_ts(self, filepath: str, content: str, language: str) -> ModuleInfo
18141816
for m in re.finditer(r"import\s+.*?from\s+['\"]([^'\"]+)['\"]", content):
18151817
imports.append(m.group(1))
18161818

1819+
# Re-export patterns (export * / export {...} from)
1820+
for m in re.finditer(r"export\s+\*\s+from\s+['\"]([^'\"]+)['\"]", content):
1821+
mod = m.group(1)
1822+
imports.append(mod)
1823+
exports.append(f"* from {mod}")
1824+
1825+
for m in re.finditer(r"export\s+\*\s+as\s+(\w+)\s+from\s+['\"]([^'\"]+)['\"]", content):
1826+
name = m.group(1)
1827+
mod = m.group(2)
1828+
imports.append(mod)
1829+
exports.append(f"* as {name} from {mod}")
1830+
exports.append(name)
1831+
1832+
for m in re.finditer(r"export\s+\{([^}]+)\}\s+from\s+['\"]([^'\"]+)['\"]", content):
1833+
items = m.group(1)
1834+
mod = m.group(2)
1835+
imports.append(mod)
1836+
for raw in (items or '').split(','):
1837+
part = raw.strip()
1838+
if not part:
1839+
continue
1840+
if ' as ' in part:
1841+
exported = part.split(' as ', 1)[1].strip()
1842+
else:
1843+
exported = part
1844+
if exported:
1845+
exports.append(exported)
1846+
1847+
# Local export list (export { A, B as C };)
1848+
for m in re.finditer(r"export\s+\{([^}]+)\}\s*;", content):
1849+
if 'from' in m.group(0):
1850+
continue
1851+
items = m.group(1)
1852+
for raw in (items or '').split(','):
1853+
part = raw.strip()
1854+
if not part:
1855+
continue
1856+
if ' as ' in part:
1857+
exported = part.split(' as ', 1)[1].strip()
1858+
else:
1859+
exported = part
1860+
if exported:
1861+
exports.append(exported)
1862+
18171863
# Class patterns
18181864
for m in re.finditer(
18191865
r'(?:export\s+)?(?:abstract\s+)?class\s+(\w+)(?:\s+extends\s+(\w+))?',

0 commit comments

Comments
 (0)