#!/usr/bin/env python3
import sys
sys.path.insert(0, 'src')

from alloy.parser import AlloyParser
from alloy.lexer import AlloyLexer

# Create a fresh parser instance
lexer = AlloyLexer()
parser = AlloyParser(lexer)

# Test the tool call case
test_code = 'result, error = parse_data(input)'

print(f"Testing: {test_code}")

# Override the tuple_assignment method to add debugging
original_tuple_assignment = parser.p_tuple_assignment

def debug_tuple_assignment(self, p):
    print(f"DEBUG: tuple_assignment called with {len(p)} tokens: {[str(x) for x in p]}")
    result = original_tuple_assignment(p)
    print(f"DEBUG: tuple_assignment result: {result}")
    return result

# Monkey patch the method
parser.p_tuple_assignment = debug_tuple_assignment.__get__(parser, AlloyParser)

print("\nParsing:")
try:
    ast = parser.parse(test_code)
    print(f"Final result: {ast}")
except Exception as e:
    print(f"Error: {e}")
    import traceback
    traceback.print_exc()