#!/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():
    # Test the failing code from the test
    test_code = '''
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("Parsing test code:")
    print(repr(test_code))
    print()
    
    try:
        ast = parser.parse(test_code)
        print("AST:", ast)
        
        # Let's examine the structure
        if ast and ast[0] == 'program' and len(ast) > 1:
            statements = ast[1]
            print(f"\nFound {len(statements)} statements:")
            for i, stmt in enumerate(statements):
                print(f"  Statement {i}: {stmt}")
        
    except Exception as e:
        print(f"Parser error: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    debug_parser()