validate_smalltalk_method_body
Validate syntax correctness of a Smalltalk method body. Supply the method body content as input to detect syntax errors.
Instructions
Validate a Smalltalk method body for syntax correctness.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method_body_content | Yes | The Smalltalk method body content as a string |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- smalltalk_validator_mcp_server/server.py:57-70 (registration)MCP tool registration with @app.tool decorator, defines the validate_smalltalk_method_body tool entry point.
@app.tool("validate_smalltalk_method_body") def validate_smalltalk_method_body( _: Context, method_body_content: str ) -> dict[str, Any]: """ Validate a Smalltalk method body for syntax correctness. Args: method_body_content: The Smalltalk method body content as a string Returns: Dictionary with validation results including success status and error details """ return validate_smalltalk_method_body_impl(method_body_content) - Core handler implementation validate_smalltalk_method_body_impl that delegates to SmalltalkMethodParser.
def validate_smalltalk_method_body_impl(method_body_content: str) -> dict[str, Any]: """ Validate a Smalltalk method body for syntax correctness. Args: method_body_content: The Smalltalk method body content as a string Returns: Dictionary with validation results including success status and error details """ try: parser = SmalltalkMethodParser() parse_result = parser.parse(method_body_content) result: dict[str, Any] = { "valid": parse_result["valid"], "content_length": len(method_body_content), "parser_type": "smalltalk_method", } if parse_result["errors"]: result["errors"] = parse_result["errors"] return result except Exception as e: return { "valid": False, "error": f"Method validation failed: {str(e)}", "content_length": len(method_body_content), "exception": type(e).__name__, } - SmalltalkMethodParser class that wraps method body in synthetic Tonel and parses with tree-sitter.
class SmalltalkMethodParser: """Validates a standalone Smalltalk method body by wrapping it in synthetic Tonel.""" def __init__(self) -> None: self._parser = _make_parser() def parse(self, method_body_content: str) -> dict[str, Any]: wrapped = _METHOD_PREFIX + method_body_content + "\n]\n" tree = self._parser.parse(wrapped.encode("utf-8")) errors = self._method_body_errors(tree.root_node) return {"valid": len(errors) == 0, "errors": errors} - Synthetic Tonel wrapper prefix used by SmalltalkMethodParser to validate standalone method bodies.
# Synthetic Tonel wrapper for method-body-only validation. # 3 lines of prefix keep column numbers intact for error reporting. _METHOD_PREFIX = "Class { #name : #__Temp__ }\n\n__Temp__ >> __method__ [\n" _METHOD_PREFIX_ROWS = _METHOD_PREFIX.count("\n") # == 3 - Internal helper to collect ERROR/MISSING nodes under a method_body node with row offset adjustment.
def _errors_under(self, node) -> list[dict[str, Any]]: errors: list[dict[str, Any]] = [] if node.type in ("ERROR", "MISSING"): errors.append(_make_error_dict(node, row_offset=_METHOD_PREFIX_ROWS)) for child in node.children: errors.extend(self._errors_under(child)) return errors