#!/usr/bin/env python3

import sys
import os

# Add the src directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'src'))

from alloy import parser

def debug_parser_combined():
    # Test various combinations to isolate the issue
    
    # 1. Simple tool with one statement
    simple_tool = '''
tool process_order takes order returns order_result {
    order_result = order + 0.08
}
result = process_order(100)
'''
    
    print("=== Testing simple tool ===")
    print(repr(simple_tool))
    
    try:
        ast = parser.parse(simple_tool)
        print("AST:", ast)
        print(f"Found {len(ast[1])} statements")
        for i, stmt in enumerate(ast[1]):
            print(f"  Statement {i}: {stmt[0]} - {stmt}")
    except Exception as e:
        print(f"Parser error: {e}")
        
    # 2. Tool with object assignment
    tool_with_object = '''
tool process_order takes order returns order_result {
    order_result = {
        total: order
    }
}
result = process_order(100)
'''
    
    print("\n=== Testing tool with object ===")
    print(repr(tool_with_object))
    
    try:
        ast = parser.parse(tool_with_object)
        print("AST:", ast)
        print(f"Found {len(ast[1])} statements")
        for i, stmt in enumerate(ast[1]):
            print(f"  Statement {i}: {stmt[0]} - {stmt}")
    except Exception as e:
        print(f"Parser error: {e}")
        
    # 3. Tool with multiple statements including object
    full_tool = '''
tool process_order takes order returns order_result {
    tax_amount = order + 0.08
    total = order + tax_amount
    order_result = {
        subtotal: order,
        tax: tax_amount,
        total: total
    }
}
result = process_order(100)
'''
    
    print("\n=== Testing full tool ===")
    print(repr(full_tool))
    
    try:
        ast = parser.parse(full_tool)
        print("AST:", ast)
        print(f"Found {len(ast[1])} statements")
        for i, stmt in enumerate(ast[1]):
            print(f"  Statement {i}: {stmt[0]} - {stmt}")
    except Exception as e:
        print(f"Parser error: {e}")

if __name__ == "__main__":
    debug_parser_combined()