zexus 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +2513 -0
- package/bin/zexus +2 -0
- package/bin/zpics +2 -0
- package/bin/zpm +2 -0
- package/bin/zx +2 -0
- package/bin/zx-deploy +2 -0
- package/bin/zx-dev +2 -0
- package/bin/zx-run +2 -0
- package/package.json +66 -0
- package/scripts/README.md +24 -0
- package/scripts/postinstall.js +44 -0
- package/shared_config.json +24 -0
- package/src/README.md +1525 -0
- package/src/tests/run_zexus_tests.py +117 -0
- package/src/tests/test_all_phases.zx +346 -0
- package/src/tests/test_blockchain_features.zx +306 -0
- package/src/tests/test_complexity_features.zx +321 -0
- package/src/tests/test_core_integration.py +185 -0
- package/src/tests/test_phase10_ecosystem.zx +177 -0
- package/src/tests/test_phase1_modifiers.zx +87 -0
- package/src/tests/test_phase2_plugins.zx +80 -0
- package/src/tests/test_phase3_security.zx +97 -0
- package/src/tests/test_phase4_vfs.zx +116 -0
- package/src/tests/test_phase5_types.zx +117 -0
- package/src/tests/test_phase6_metaprogramming.zx +125 -0
- package/src/tests/test_phase7_optimization.zx +132 -0
- package/src/tests/test_phase9_advanced_types.zx +157 -0
- package/src/tests/test_security_features.py +419 -0
- package/src/tests/test_security_features.zx +276 -0
- package/src/tests/test_simple_zx.zx +1 -0
- package/src/tests/test_verification_simple.zx +69 -0
- package/src/zexus/__init__.py +28 -0
- package/src/zexus/__main__.py +5 -0
- package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/ecosystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/hybrid_orchestrator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/virtual_filesystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
- package/src/zexus/advanced_types.py +401 -0
- package/src/zexus/blockchain/__init__.py +40 -0
- package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/crypto.py +463 -0
- package/src/zexus/blockchain/ledger.py +255 -0
- package/src/zexus/blockchain/transaction.py +267 -0
- package/src/zexus/builtin_modules.py +284 -0
- package/src/zexus/builtin_plugins.py +317 -0
- package/src/zexus/capability_system.py +372 -0
- package/src/zexus/cli/__init__.py +2 -0
- package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +707 -0
- package/src/zexus/cli/zpm.py +203 -0
- package/src/zexus/compare_interpreter_compiler.py +146 -0
- package/src/zexus/compiler/__init__.py +169 -0
- package/src/zexus/compiler/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/compiler/bytecode.py +266 -0
- package/src/zexus/compiler/compat_runtime.py +277 -0
- package/src/zexus/compiler/lexer.py +257 -0
- package/src/zexus/compiler/parser.py +779 -0
- package/src/zexus/compiler/semantic.py +118 -0
- package/src/zexus/compiler/zexus_ast.py +454 -0
- package/src/zexus/complexity_system.py +575 -0
- package/src/zexus/concurrency_system.py +493 -0
- package/src/zexus/config.py +201 -0
- package/src/zexus/crypto_bridge.py +19 -0
- package/src/zexus/dependency_injection.py +423 -0
- package/src/zexus/ecosystem.py +434 -0
- package/src/zexus/environment.py +101 -0
- package/src/zexus/environment_manager.py +119 -0
- package/src/zexus/error_reporter.py +314 -0
- package/src/zexus/evaluator/__init__.py +12 -0
- package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/integration.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/bytecode_compiler.py +700 -0
- package/src/zexus/evaluator/core.py +891 -0
- package/src/zexus/evaluator/expressions.py +827 -0
- package/src/zexus/evaluator/functions.py +3989 -0
- package/src/zexus/evaluator/integration.py +396 -0
- package/src/zexus/evaluator/statements.py +4303 -0
- package/src/zexus/evaluator/utils.py +126 -0
- package/src/zexus/evaluator_original.py +2041 -0
- package/src/zexus/external_bridge.py +16 -0
- package/src/zexus/find_affected_imports.sh +155 -0
- package/src/zexus/hybrid_orchestrator.py +152 -0
- package/src/zexus/input_validation.py +259 -0
- package/src/zexus/lexer.py +571 -0
- package/src/zexus/logging.py +89 -0
- package/src/zexus/lsp/__init__.py +9 -0
- package/src/zexus/lsp/completion_provider.py +207 -0
- package/src/zexus/lsp/definition_provider.py +22 -0
- package/src/zexus/lsp/hover_provider.py +71 -0
- package/src/zexus/lsp/server.py +269 -0
- package/src/zexus/lsp/symbol_provider.py +31 -0
- package/src/zexus/metaprogramming.py +321 -0
- package/src/zexus/module_cache.py +89 -0
- package/src/zexus/module_manager.py +107 -0
- package/src/zexus/object.py +973 -0
- package/src/zexus/optimization.py +424 -0
- package/src/zexus/parser/__init__.py +31 -0
- package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
- package/src/zexus/parser/integration.py +86 -0
- package/src/zexus/parser/parser.py +3977 -0
- package/src/zexus/parser/strategy_context.py +7254 -0
- package/src/zexus/parser/strategy_structural.py +1033 -0
- package/src/zexus/persistence.py +391 -0
- package/src/zexus/plugin_system.py +290 -0
- package/src/zexus/policy_engine.py +365 -0
- package/src/zexus/profiler/__init__.py +5 -0
- package/src/zexus/profiler/profiler.py +233 -0
- package/src/zexus/purity_system.py +398 -0
- package/src/zexus/runtime/__init__.py +20 -0
- package/src/zexus/runtime/async_runtime.py +324 -0
- package/src/zexus/search_old_imports.sh +65 -0
- package/src/zexus/security.py +1407 -0
- package/src/zexus/stack_trace.py +233 -0
- package/src/zexus/stdlib/__init__.py +27 -0
- package/src/zexus/stdlib/blockchain.py +341 -0
- package/src/zexus/stdlib/compression.py +167 -0
- package/src/zexus/stdlib/crypto.py +124 -0
- package/src/zexus/stdlib/datetime.py +163 -0
- package/src/zexus/stdlib/db_mongo.py +199 -0
- package/src/zexus/stdlib/db_mysql.py +162 -0
- package/src/zexus/stdlib/db_postgres.py +163 -0
- package/src/zexus/stdlib/db_sqlite.py +133 -0
- package/src/zexus/stdlib/encoding.py +230 -0
- package/src/zexus/stdlib/fs.py +195 -0
- package/src/zexus/stdlib/http.py +219 -0
- package/src/zexus/stdlib/http_server.py +248 -0
- package/src/zexus/stdlib/json_module.py +61 -0
- package/src/zexus/stdlib/math.py +360 -0
- package/src/zexus/stdlib/os_module.py +265 -0
- package/src/zexus/stdlib/regex.py +148 -0
- package/src/zexus/stdlib/sockets.py +253 -0
- package/src/zexus/stdlib/test_framework.zx +208 -0
- package/src/zexus/stdlib/test_runner.zx +119 -0
- package/src/zexus/stdlib_integration.py +341 -0
- package/src/zexus/strategy_recovery.py +256 -0
- package/src/zexus/syntax_validator.py +356 -0
- package/src/zexus/testing/zpics.py +407 -0
- package/src/zexus/testing/zpics_runtime.py +369 -0
- package/src/zexus/type_system.py +374 -0
- package/src/zexus/validation_system.py +569 -0
- package/src/zexus/virtual_filesystem.py +355 -0
- package/src/zexus/vm/__init__.py +8 -0
- package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/async_optimizer.py +420 -0
- package/src/zexus/vm/bytecode.py +428 -0
- package/src/zexus/vm/bytecode_converter.py +297 -0
- package/src/zexus/vm/cache.py +532 -0
- package/src/zexus/vm/jit.py +720 -0
- package/src/zexus/vm/memory_manager.py +520 -0
- package/src/zexus/vm/memory_pool.py +511 -0
- package/src/zexus/vm/optimizer.py +478 -0
- package/src/zexus/vm/parallel_vm.py +899 -0
- package/src/zexus/vm/peephole_optimizer.py +452 -0
- package/src/zexus/vm/profiler.py +527 -0
- package/src/zexus/vm/register_allocator.py +462 -0
- package/src/zexus/vm/register_vm.py +520 -0
- package/src/zexus/vm/ssa_converter.py +757 -0
- package/src/zexus/vm/vm.py +1392 -0
- package/src/zexus/zexus_ast.py +1782 -0
- package/src/zexus/zexus_token.py +253 -0
- package/src/zexus/zpm/__init__.py +15 -0
- package/src/zexus/zpm/installer.py +116 -0
- package/src/zexus/zpm/package_manager.py +208 -0
- package/src/zexus/zpm/publisher.py +98 -0
- package/src/zexus/zpm/registry.py +110 -0
- package/src/zexus.egg-info/PKG-INFO +2235 -0
- package/src/zexus.egg-info/SOURCES.txt +876 -0
- package/src/zexus.egg-info/dependency_links.txt +1 -0
- package/src/zexus.egg-info/entry_points.txt +3 -0
- package/src/zexus.egg-info/not-zip-safe +1 -0
- package/src/zexus.egg-info/requires.txt +14 -0
- package/src/zexus.egg-info/top_level.txt +2 -0
- package/zexus.json +14 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Zexus Error Reporting System
|
|
3
|
+
|
|
4
|
+
Provides clear, beginner-friendly error messages that distinguish between
|
|
5
|
+
user code errors and interpreter bugs.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
from typing import Optional, List, Dict, Any
|
|
10
|
+
from enum import Enum
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ErrorCategory(Enum):
|
|
14
|
+
"""Categories of errors in Zexus"""
|
|
15
|
+
USER_CODE = "user_code" # Error in user's Zexus code
|
|
16
|
+
INTERPRETER = "interpreter" # Bug in the Zexus interpreter
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ErrorSeverity(Enum):
|
|
20
|
+
"""Severity levels for errors"""
|
|
21
|
+
ERROR = "error"
|
|
22
|
+
WARNING = "warning"
|
|
23
|
+
INFO = "info"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ZexusError(Exception):
|
|
27
|
+
"""Base class for all Zexus errors"""
|
|
28
|
+
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
message: str,
|
|
32
|
+
category: ErrorCategory = ErrorCategory.USER_CODE,
|
|
33
|
+
severity: ErrorSeverity = ErrorSeverity.ERROR,
|
|
34
|
+
filename: Optional[str] = None,
|
|
35
|
+
line: Optional[int] = None,
|
|
36
|
+
column: Optional[int] = None,
|
|
37
|
+
source_line: Optional[str] = None,
|
|
38
|
+
suggestion: Optional[str] = None,
|
|
39
|
+
error_code: Optional[str] = None,
|
|
40
|
+
):
|
|
41
|
+
super().__init__(message)
|
|
42
|
+
self.message = message
|
|
43
|
+
self.category = category
|
|
44
|
+
self.severity = severity
|
|
45
|
+
self.filename = filename or "<stdin>"
|
|
46
|
+
self.line = line
|
|
47
|
+
self.column = column
|
|
48
|
+
self.source_line = source_line
|
|
49
|
+
self.suggestion = suggestion
|
|
50
|
+
self.error_code = error_code
|
|
51
|
+
|
|
52
|
+
def format_error(self) -> str:
|
|
53
|
+
"""Format the error message for display"""
|
|
54
|
+
parts = []
|
|
55
|
+
|
|
56
|
+
# Header with error type and location
|
|
57
|
+
location = f"{self.filename}"
|
|
58
|
+
if self.line is not None:
|
|
59
|
+
location += f":{self.line}"
|
|
60
|
+
if self.column is not None:
|
|
61
|
+
location += f":{self.column}"
|
|
62
|
+
|
|
63
|
+
# Color codes (ANSI)
|
|
64
|
+
RED = "\033[91m"
|
|
65
|
+
YELLOW = "\033[93m"
|
|
66
|
+
BLUE = "\033[94m"
|
|
67
|
+
CYAN = "\033[96m"
|
|
68
|
+
BOLD = "\033[1m"
|
|
69
|
+
RESET = "\033[0m"
|
|
70
|
+
|
|
71
|
+
# Disable colors if not in terminal
|
|
72
|
+
if not sys.stderr.isatty():
|
|
73
|
+
RED = YELLOW = BLUE = CYAN = BOLD = RESET = ""
|
|
74
|
+
|
|
75
|
+
if self.severity == ErrorSeverity.ERROR:
|
|
76
|
+
severity_color = RED
|
|
77
|
+
severity_text = "ERROR"
|
|
78
|
+
elif self.severity == ErrorSeverity.WARNING:
|
|
79
|
+
severity_color = YELLOW
|
|
80
|
+
severity_text = "WARNING"
|
|
81
|
+
else:
|
|
82
|
+
severity_color = BLUE
|
|
83
|
+
severity_text = "INFO"
|
|
84
|
+
|
|
85
|
+
# Error header
|
|
86
|
+
error_type = self.__class__.__name__
|
|
87
|
+
if self.error_code:
|
|
88
|
+
error_type = f"{error_type}[{self.error_code}]"
|
|
89
|
+
|
|
90
|
+
parts.append(f"{BOLD}{severity_color}{severity_text}{RESET}: {BOLD}{error_type}{RESET}")
|
|
91
|
+
parts.append(f" {CYAN}→{RESET} {location}")
|
|
92
|
+
parts.append("")
|
|
93
|
+
|
|
94
|
+
# Show source code with pointer
|
|
95
|
+
if self.source_line is not None and self.line is not None:
|
|
96
|
+
line_num_width = len(str(self.line))
|
|
97
|
+
line_num = f"{self.line}".rjust(line_num_width)
|
|
98
|
+
|
|
99
|
+
parts.append(f" {BLUE}{line_num} |{RESET} {self.source_line}")
|
|
100
|
+
|
|
101
|
+
# Add pointer to the error location
|
|
102
|
+
if self.column is not None:
|
|
103
|
+
pointer_padding = " " * (line_num_width + 3 + self.column)
|
|
104
|
+
parts.append(f" {pointer_padding}{RED}^{RESET}")
|
|
105
|
+
|
|
106
|
+
parts.append("")
|
|
107
|
+
|
|
108
|
+
# Error message
|
|
109
|
+
parts.append(f" {self.message}")
|
|
110
|
+
|
|
111
|
+
# Suggestion
|
|
112
|
+
if self.suggestion:
|
|
113
|
+
parts.append("")
|
|
114
|
+
parts.append(f" {YELLOW}💡 Suggestion:{RESET} {self.suggestion}")
|
|
115
|
+
|
|
116
|
+
# Internal error note
|
|
117
|
+
if self.category == ErrorCategory.INTERPRETER:
|
|
118
|
+
parts.append("")
|
|
119
|
+
parts.append(f" {RED}⚠️ This is an internal interpreter error.{RESET}")
|
|
120
|
+
parts.append(f" {RED} Please report this bug to the Zexus developers.{RESET}")
|
|
121
|
+
|
|
122
|
+
parts.append("")
|
|
123
|
+
return "\n".join(parts)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class SyntaxError(ZexusError):
|
|
127
|
+
"""Syntax errors in Zexus code"""
|
|
128
|
+
def __init__(self, message: str, **kwargs):
|
|
129
|
+
super().__init__(message, error_code="SYNTAX", **kwargs)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class NameError(ZexusError):
|
|
133
|
+
"""Name/identifier not found errors"""
|
|
134
|
+
def __init__(self, message: str, **kwargs):
|
|
135
|
+
super().__init__(message, error_code="NAME", **kwargs)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class TypeError(ZexusError):
|
|
139
|
+
"""Type-related errors"""
|
|
140
|
+
def __init__(self, message: str, **kwargs):
|
|
141
|
+
super().__init__(message, error_code="TYPE", **kwargs)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class ValueError(ZexusError):
|
|
145
|
+
"""Value-related errors"""
|
|
146
|
+
def __init__(self, message: str, **kwargs):
|
|
147
|
+
super().__init__(message, error_code="VALUE", **kwargs)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class AttributeError(ZexusError):
|
|
151
|
+
"""Attribute access errors"""
|
|
152
|
+
def __init__(self, message: str, **kwargs):
|
|
153
|
+
super().__init__(message, error_code="ATTR", **kwargs)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class IndexError(ZexusError):
|
|
157
|
+
"""Index out of bounds errors"""
|
|
158
|
+
def __init__(self, message: str, **kwargs):
|
|
159
|
+
super().__init__(message, error_code="INDEX", **kwargs)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class PatternMatchError(ZexusError):
|
|
163
|
+
"""Pattern matching errors"""
|
|
164
|
+
def __init__(self, message: str, **kwargs):
|
|
165
|
+
super().__init__(message, error_code="PATTERN", **kwargs)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class ImportError(ZexusError):
|
|
169
|
+
"""Module import errors"""
|
|
170
|
+
def __init__(self, message: str, **kwargs):
|
|
171
|
+
super().__init__(message, error_code="IMPORT", **kwargs)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class InterpreterError(ZexusError):
|
|
175
|
+
"""Internal interpreter errors (bugs in Zexus itself)"""
|
|
176
|
+
def __init__(self, message: str, **kwargs):
|
|
177
|
+
kwargs['category'] = ErrorCategory.INTERPRETER
|
|
178
|
+
super().__init__(
|
|
179
|
+
f"Internal error: {message}",
|
|
180
|
+
error_code="INTERNAL",
|
|
181
|
+
**kwargs
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class ErrorReporter:
|
|
186
|
+
"""
|
|
187
|
+
Centralized error reporting for the Zexus interpreter.
|
|
188
|
+
Tracks source code context for better error messages.
|
|
189
|
+
"""
|
|
190
|
+
|
|
191
|
+
def __init__(self):
|
|
192
|
+
self.source_lines: Dict[str, List[str]] = {}
|
|
193
|
+
self.current_file: Optional[str] = None
|
|
194
|
+
|
|
195
|
+
def register_source(self, filename: str, source: str):
|
|
196
|
+
"""Register source code for a file"""
|
|
197
|
+
self.source_lines[filename] = source.splitlines()
|
|
198
|
+
self.current_file = filename
|
|
199
|
+
|
|
200
|
+
def get_source_line(self, filename: Optional[str], line: int) -> Optional[str]:
|
|
201
|
+
"""Get a specific line from the source code"""
|
|
202
|
+
if filename is None:
|
|
203
|
+
filename = self.current_file
|
|
204
|
+
|
|
205
|
+
if filename and filename in self.source_lines:
|
|
206
|
+
lines = self.source_lines[filename]
|
|
207
|
+
if 0 < line <= len(lines):
|
|
208
|
+
return lines[line - 1]
|
|
209
|
+
|
|
210
|
+
return None
|
|
211
|
+
|
|
212
|
+
def report_error(
|
|
213
|
+
self,
|
|
214
|
+
error_class,
|
|
215
|
+
message: str,
|
|
216
|
+
line: Optional[int] = None,
|
|
217
|
+
column: Optional[int] = None,
|
|
218
|
+
filename: Optional[str] = None,
|
|
219
|
+
suggestion: Optional[str] = None,
|
|
220
|
+
**kwargs
|
|
221
|
+
) -> ZexusError:
|
|
222
|
+
"""
|
|
223
|
+
Create and return a properly formatted error.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
error_class: The error class to instantiate
|
|
227
|
+
message: Error message
|
|
228
|
+
line: Line number where error occurred
|
|
229
|
+
column: Column number where error occurred
|
|
230
|
+
filename: Filename (defaults to current file)
|
|
231
|
+
suggestion: Helpful suggestion for fixing the error
|
|
232
|
+
**kwargs: Additional arguments for the error class
|
|
233
|
+
|
|
234
|
+
Returns:
|
|
235
|
+
ZexusError instance ready to be raised
|
|
236
|
+
"""
|
|
237
|
+
if filename is None:
|
|
238
|
+
filename = self.current_file
|
|
239
|
+
|
|
240
|
+
source_line = None
|
|
241
|
+
if line is not None:
|
|
242
|
+
source_line = self.get_source_line(filename, line)
|
|
243
|
+
|
|
244
|
+
return error_class(
|
|
245
|
+
message=message,
|
|
246
|
+
filename=filename,
|
|
247
|
+
line=line,
|
|
248
|
+
column=column,
|
|
249
|
+
source_line=source_line,
|
|
250
|
+
suggestion=suggestion,
|
|
251
|
+
**kwargs
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
def create_suggestion(self, error_type: str, context: Dict[str, Any]) -> Optional[str]:
|
|
255
|
+
"""
|
|
256
|
+
Generate helpful suggestions based on error type and context.
|
|
257
|
+
|
|
258
|
+
Args:
|
|
259
|
+
error_type: Type of error (e.g., "undefined_variable", "type_mismatch")
|
|
260
|
+
context: Additional context for generating suggestions
|
|
261
|
+
|
|
262
|
+
Returns:
|
|
263
|
+
Helpful suggestion string or None
|
|
264
|
+
"""
|
|
265
|
+
suggestions = {
|
|
266
|
+
"undefined_variable": lambda ctx: (
|
|
267
|
+
f"Did you mean '{ctx.get('similar')}'?" if ctx.get('similar')
|
|
268
|
+
else "Make sure the variable is declared before using it."
|
|
269
|
+
),
|
|
270
|
+
"type_mismatch": lambda ctx: (
|
|
271
|
+
f"Expected {ctx.get('expected')}, got {ctx.get('actual')}. "
|
|
272
|
+
f"Try converting the value or checking your types."
|
|
273
|
+
),
|
|
274
|
+
"missing_semicolon": lambda ctx: (
|
|
275
|
+
"Zexus statements don't require semicolons. Remove the semicolon."
|
|
276
|
+
),
|
|
277
|
+
"wrong_indentation": lambda ctx: (
|
|
278
|
+
"Zexus uses curly braces {{ }} for blocks, not indentation. "
|
|
279
|
+
"Make sure your braces are balanced."
|
|
280
|
+
),
|
|
281
|
+
"pattern_no_match": lambda ctx: (
|
|
282
|
+
"Add a wildcard pattern '_' as the last case to handle all values, "
|
|
283
|
+
"or ensure your patterns cover all possible cases."
|
|
284
|
+
),
|
|
285
|
+
"generic_type_args": lambda ctx: (
|
|
286
|
+
f"This generic type requires {ctx.get('expected')} type argument(s). "
|
|
287
|
+
f"Use: {ctx.get('example')}"
|
|
288
|
+
),
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
suggestion_fn = suggestions.get(error_type)
|
|
292
|
+
if suggestion_fn:
|
|
293
|
+
return suggestion_fn(context)
|
|
294
|
+
|
|
295
|
+
return None
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
# Global error reporter instance
|
|
299
|
+
_error_reporter = ErrorReporter()
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def get_error_reporter() -> ErrorReporter:
|
|
303
|
+
"""Get the global error reporter instance"""
|
|
304
|
+
return _error_reporter
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def format_error(error: ZexusError) -> str:
|
|
308
|
+
"""Format a ZexusError for display"""
|
|
309
|
+
return error.format_error()
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def print_error(error: ZexusError):
|
|
313
|
+
"""Print a formatted error to stderr"""
|
|
314
|
+
print(error.format_error(), file=sys.stderr)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# src/zexus/evaluator/__init__.py
|
|
2
|
+
from typing import Any, Dict
|
|
3
|
+
|
|
4
|
+
from .core import Evaluator, evaluate
|
|
5
|
+
from .utils import EVAL_SUMMARY
|
|
6
|
+
|
|
7
|
+
# Module-level builtins registry. Tests and other code may inject into this
|
|
8
|
+
# dict (e.g. `from zexus.evaluator import builtins as evaluator_builtins`).
|
|
9
|
+
# At runtime, `evaluate()` will copy these into each Evaluator instance.
|
|
10
|
+
builtins: Dict[str, Any] = {}
|
|
11
|
+
|
|
12
|
+
__all__ = ['Evaluator', 'evaluate', 'EVAL_SUMMARY', 'builtins']
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|