Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ cython_debug/
marimo/_static/
marimo/_lsp/
__marimo__/

# output llm context
llm_context.md
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "deepbase"
# Increment the version to reflect changes
version = "1.7.0"
version = "1.8.0"
authors = [
{ name="Giuliano Ranauro", email="ranaurogln@email.com" },
]
Expand Down
275 changes: 189 additions & 86 deletions src/deepbase/main.py

Large diffs are not rendered by default.

85 changes: 0 additions & 85 deletions src/deepbase/parsers.py

This file was deleted.

6 changes: 6 additions & 0 deletions src/deepbase/parsers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# src/deepbase/parsers/__init__.py
from .document import get_document_structure
from .registry import registry

# Espone anche le classi se necessario in futuro
__all__ = ['get_document_structure', 'registry']
58 changes: 58 additions & 0 deletions src/deepbase/parsers/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# src/deepbase/parsers/document.py
import re
import os
from .interface import LanguageParser

class MarkdownParser(LanguageParser):
def parse(self, content: str, file_path: str) -> str:
lines = []
for line in content.splitlines():
if line.strip().startswith("#"):
lines.append(line.strip())
if not lines:
return "(Markdown file with no headers)"
return "\n".join(lines)

class LatexParser(LanguageParser):
def parse(self, content: str, file_path: str) -> str:
keep_patterns = [
r'^\s*\\documentclass',
r'^\s*\\usepackage',
r'^\s*\\input',
r'^\s*\\include',
r'^\s*\\(part|chapter|section|subsection|subsubsection)',
r'^\s*\\begin',
r'^\s*\\end',
r'^\s*\\title',
r'^\s*\\author',
r'^\s*\\date'
]
combined_pattern = re.compile('|'.join(keep_patterns))
lines = []
for line in content.splitlines():
# Rimuovi commenti inline parziali se necessario, qui semplifichiamo
line_clean = line.split('%')[0].rstrip()
if combined_pattern.match(line_clean):
lines.append(line_clean)
if not lines:
return "(LaTeX content empty or purely textual)"
return "\n".join(lines)

# Istanziamo i parser per uso interno
_md_parser = MarkdownParser()
_tex_parser = LatexParser()

def get_document_structure(file_path: str, content: str):
"""
Funzione di compatibilitΓ  per main.py.
Restituisce la struttura se Γ¨ un documento supportato, altrimenti None.
"""
_, ext = os.path.splitext(file_path)
ext = ext.lower()

if ext in ['.md', '.markdown']:
return _md_parser.parse(content, file_path)
elif ext in ['.tex', '.sty', '.cls']:
return _tex_parser.parse(content, file_path)

return None
25 changes: 25 additions & 0 deletions src/deepbase/parsers/fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# src/deepbase/parsers/fallback.py
from .interface import LanguageParser

class FallbackParser(LanguageParser):
"""
Parser generico per file non supportati specificamente.
Tenta di restituire una versione minimizzata o troncata.
"""
def parse(self, content: str, file_path: str) -> str:
lines = []
# Rimuove righe vuote e commenti base
for line in content.splitlines():
clean = line.strip()
if clean and not clean.startswith("#"):
lines.append(clean)

if not lines:
return "(Empty or comments-only file)"

# Se il file Γ¨ molto lungo, troncalo per il fallback
if len(lines) > 20:
preview = "\n".join(lines[:20])
return f"{preview}\n... ({len(lines)-20} more lines hidden - Light Mode Fallback)"

return "\n".join(lines)
14 changes: 14 additions & 0 deletions src/deepbase/parsers/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# src/deepbase/parsers/interface.py
from abc import ABC, abstractmethod

class LanguageParser(ABC):
"""
Interfaccia base per i parser di linguaggio.
"""

@abstractmethod
def parse(self, content: str, file_path: str) -> str:
"""
Parsa il contenuto del file e restituisce una rappresentazione 'light' (firme, struttura).
"""
pass
87 changes: 87 additions & 0 deletions src/deepbase/parsers/javascript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# src/deepbase/parsers/javascript.py
import re
from .interface import LanguageParser

class JavaScriptParser(LanguageParser):
"""
Parser per JavaScript, TypeScript e React Native (.js, .jsx, .ts, .tsx).
Versione 1.1: Logica Regex base + Supporto Export Default.
"""

def parse(self, content: str, file_path: str) -> str:
lines = []

# Regex patterns per catturare le definizioni strutturali (classi, funzioni, var, tipi)
patterns = [
# Class definition
re.compile(r'^\s*(export\s+)?(default\s+)?(abstract\s+)?class\s+([a-zA-Z0-9_]+)(.*)?\{'),

# Function definition standard
re.compile(r'^\s*(export\s+)?(default\s+)?(async\s+)?function\s+([a-zA-Z0-9_]+)\s*\(.*'),

# Arrow Function / Variable Assignments
re.compile(r'^\s*(export\s+)?(const|let|var)\s+([a-zA-Z0-9_]+)\s*=\s*(async\s*)?(\(.*\)|[^=]+)\s*=>.*'),

# TypeScript Interfaces & Types
re.compile(r'^\s*(export\s+)?(interface|type)\s+([a-zA-Z0-9_]+).*'),
]

# --- NEW: Regex specifica per Export Default diretto (V2 Feature) ---
# Cattura: export default router; | export default MyComponent;
# Il (?!...) assicura che non catturi "class" o "function" che sono gestiti meglio dai pattern sopra.
re_export_default = re.compile(r'^\s*export\s+default\s+(?!class|function)([a-zA-Z0-9_]+);?')

# JSDoc pattern
in_comment = False
source_lines = content.splitlines()

for i, line in enumerate(source_lines):
stripped = line.strip()

# Gestione commenti JSDoc
if stripped.startswith("/**"):
in_comment = True
lines.append(stripped)
if stripped.endswith("*/"):
in_comment = False
continue

if in_comment:
lines.append(stripped)
if stripped.endswith("*/"):
in_comment = False
continue

# Ignora commenti single line o righe vuote
if not stripped or stripped.startswith("//"):
continue

# --- NEW: Controllo Export Default ---
# Se è un export default semplice, lo aggiungiamo così com'è (senza { ... })
if re_export_default.match(stripped):
lines.append(stripped)
continue

# Verifica patterns standard
is_match = False
for pattern in patterns:
if pattern.match(stripped):
# Pulizia fine riga: se finisce con '{', lo sostituiamo con '...'
clean_line = stripped
if clean_line.endswith("{"):
clean_line = clean_line[:-1].strip()

# Aggiunge firma + { ... } per indicare struttura compressa
lines.append(f"{clean_line} {{ ... }}")
is_match = True
break

# Fallback per decoratori
if not is_match and stripped.startswith("@"):
if i + 1 < len(source_lines) and "class " in source_lines[i+1]:
lines.append(stripped)

if not lines:
return f"(No exported functions, classes or components found in {file_path})"

return "\n".join(lines)
Loading