Skip to content

Commit 9ba5960

Browse files
authored
Merge pull request #7 from follen99/light-mode
## DeepBase v1.8.0 — Light Mode & JavaScript Support
2 parents a65751c + e0c98ea commit 9ba5960

16 files changed

Lines changed: 1010 additions & 442 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,6 @@ cython_debug/
170170
marimo/_static/
171171
marimo/_lsp/
172172
__marimo__/
173+
174+
# output llm context
175+
llm_context.md

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77
[project]
88
name = "deepbase"
99
# Increment the version to reflect changes
10-
version = "1.7.0"
10+
version = "1.8.0"
1111
authors = [
1212
{ name="Giuliano Ranauro", email="ranaurogln@email.com" },
1313
]

src/deepbase/main.py

Lines changed: 189 additions & 86 deletions
Large diffs are not rendered by default.

src/deepbase/parsers.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/deepbase/parsers/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# src/deepbase/parsers/__init__.py
2+
from .document import get_document_structure
3+
from .registry import registry
4+
5+
# Espone anche le classi se necessario in futuro
6+
__all__ = ['get_document_structure', 'registry']

src/deepbase/parsers/document.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# src/deepbase/parsers/document.py
2+
import re
3+
import os
4+
from .interface import LanguageParser
5+
6+
class MarkdownParser(LanguageParser):
7+
def parse(self, content: str, file_path: str) -> str:
8+
lines = []
9+
for line in content.splitlines():
10+
if line.strip().startswith("#"):
11+
lines.append(line.strip())
12+
if not lines:
13+
return "(Markdown file with no headers)"
14+
return "\n".join(lines)
15+
16+
class LatexParser(LanguageParser):
17+
def parse(self, content: str, file_path: str) -> str:
18+
keep_patterns = [
19+
r'^\s*\\documentclass',
20+
r'^\s*\\usepackage',
21+
r'^\s*\\input',
22+
r'^\s*\\include',
23+
r'^\s*\\(part|chapter|section|subsection|subsubsection)',
24+
r'^\s*\\begin',
25+
r'^\s*\\end',
26+
r'^\s*\\title',
27+
r'^\s*\\author',
28+
r'^\s*\\date'
29+
]
30+
combined_pattern = re.compile('|'.join(keep_patterns))
31+
lines = []
32+
for line in content.splitlines():
33+
# Rimuovi commenti inline parziali se necessario, qui semplifichiamo
34+
line_clean = line.split('%')[0].rstrip()
35+
if combined_pattern.match(line_clean):
36+
lines.append(line_clean)
37+
if not lines:
38+
return "(LaTeX content empty or purely textual)"
39+
return "\n".join(lines)
40+
41+
# Istanziamo i parser per uso interno
42+
_md_parser = MarkdownParser()
43+
_tex_parser = LatexParser()
44+
45+
def get_document_structure(file_path: str, content: str):
46+
"""
47+
Funzione di compatibilità per main.py.
48+
Restituisce la struttura se è un documento supportato, altrimenti None.
49+
"""
50+
_, ext = os.path.splitext(file_path)
51+
ext = ext.lower()
52+
53+
if ext in ['.md', '.markdown']:
54+
return _md_parser.parse(content, file_path)
55+
elif ext in ['.tex', '.sty', '.cls']:
56+
return _tex_parser.parse(content, file_path)
57+
58+
return None

src/deepbase/parsers/fallback.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# src/deepbase/parsers/fallback.py
2+
from .interface import LanguageParser
3+
4+
class FallbackParser(LanguageParser):
5+
"""
6+
Parser generico per file non supportati specificamente.
7+
Tenta di restituire una versione minimizzata o troncata.
8+
"""
9+
def parse(self, content: str, file_path: str) -> str:
10+
lines = []
11+
# Rimuove righe vuote e commenti base
12+
for line in content.splitlines():
13+
clean = line.strip()
14+
if clean and not clean.startswith("#"):
15+
lines.append(clean)
16+
17+
if not lines:
18+
return "(Empty or comments-only file)"
19+
20+
# Se il file è molto lungo, troncalo per il fallback
21+
if len(lines) > 20:
22+
preview = "\n".join(lines[:20])
23+
return f"{preview}\n... ({len(lines)-20} more lines hidden - Light Mode Fallback)"
24+
25+
return "\n".join(lines)

src/deepbase/parsers/interface.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# src/deepbase/parsers/interface.py
2+
from abc import ABC, abstractmethod
3+
4+
class LanguageParser(ABC):
5+
"""
6+
Interfaccia base per i parser di linguaggio.
7+
"""
8+
9+
@abstractmethod
10+
def parse(self, content: str, file_path: str) -> str:
11+
"""
12+
Parsa il contenuto del file e restituisce una rappresentazione 'light' (firme, struttura).
13+
"""
14+
pass

src/deepbase/parsers/javascript.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# src/deepbase/parsers/javascript.py
2+
import re
3+
from .interface import LanguageParser
4+
5+
class JavaScriptParser(LanguageParser):
6+
"""
7+
Parser per JavaScript, TypeScript e React Native (.js, .jsx, .ts, .tsx).
8+
Versione 1.1: Logica Regex base + Supporto Export Default.
9+
"""
10+
11+
def parse(self, content: str, file_path: str) -> str:
12+
lines = []
13+
14+
# Regex patterns per catturare le definizioni strutturali (classi, funzioni, var, tipi)
15+
patterns = [
16+
# Class definition
17+
re.compile(r'^\s*(export\s+)?(default\s+)?(abstract\s+)?class\s+([a-zA-Z0-9_]+)(.*)?\{'),
18+
19+
# Function definition standard
20+
re.compile(r'^\s*(export\s+)?(default\s+)?(async\s+)?function\s+([a-zA-Z0-9_]+)\s*\(.*'),
21+
22+
# Arrow Function / Variable Assignments
23+
re.compile(r'^\s*(export\s+)?(const|let|var)\s+([a-zA-Z0-9_]+)\s*=\s*(async\s*)?(\(.*\)|[^=]+)\s*=>.*'),
24+
25+
# TypeScript Interfaces & Types
26+
re.compile(r'^\s*(export\s+)?(interface|type)\s+([a-zA-Z0-9_]+).*'),
27+
]
28+
29+
# --- NEW: Regex specifica per Export Default diretto (V2 Feature) ---
30+
# Cattura: export default router; | export default MyComponent;
31+
# Il (?!...) assicura che non catturi "class" o "function" che sono gestiti meglio dai pattern sopra.
32+
re_export_default = re.compile(r'^\s*export\s+default\s+(?!class|function)([a-zA-Z0-9_]+);?')
33+
34+
# JSDoc pattern
35+
in_comment = False
36+
source_lines = content.splitlines()
37+
38+
for i, line in enumerate(source_lines):
39+
stripped = line.strip()
40+
41+
# Gestione commenti JSDoc
42+
if stripped.startswith("/**"):
43+
in_comment = True
44+
lines.append(stripped)
45+
if stripped.endswith("*/"):
46+
in_comment = False
47+
continue
48+
49+
if in_comment:
50+
lines.append(stripped)
51+
if stripped.endswith("*/"):
52+
in_comment = False
53+
continue
54+
55+
# Ignora commenti single line o righe vuote
56+
if not stripped or stripped.startswith("//"):
57+
continue
58+
59+
# --- NEW: Controllo Export Default ---
60+
# Se è un export default semplice, lo aggiungiamo così com'è (senza { ... })
61+
if re_export_default.match(stripped):
62+
lines.append(stripped)
63+
continue
64+
65+
# Verifica patterns standard
66+
is_match = False
67+
for pattern in patterns:
68+
if pattern.match(stripped):
69+
# Pulizia fine riga: se finisce con '{', lo sostituiamo con '...'
70+
clean_line = stripped
71+
if clean_line.endswith("{"):
72+
clean_line = clean_line[:-1].strip()
73+
74+
# Aggiunge firma + { ... } per indicare struttura compressa
75+
lines.append(f"{clean_line} {{ ... }}")
76+
is_match = True
77+
break
78+
79+
# Fallback per decoratori
80+
if not is_match and stripped.startswith("@"):
81+
if i + 1 < len(source_lines) and "class " in source_lines[i+1]:
82+
lines.append(stripped)
83+
84+
if not lines:
85+
return f"(No exported functions, classes or components found in {file_path})"
86+
87+
return "\n".join(lines)

0 commit comments

Comments
 (0)