// Wrapper for Peggy-generated parser that handles ESM imports correctly
import {
  ProgramNode, DefinitionNode, FieldNode, BehaviorNode, FactNode, ParameterNode,
  EvidenceNode, EvidenceBodyNode, DirectEvidenceNode, PatternMatchNode, 
  DefeasibleLogicNode, FusionNode, PredicateNode, ExpressionNode, WithClauseNode, 
  MeasureNode, MeasureBodyNode, AggregationNode 
} from '../nodes/index.js';

// Make AST nodes globally available to the generated parser
global.ProgramNode = ProgramNode;
global.DefinitionNode = DefinitionNode;
global.FieldNode = FieldNode;
global.BehaviorNode = BehaviorNode;
global.FactNode = FactNode;
global.ParameterNode = ParameterNode;
global.EvidenceNode = EvidenceNode;
global.EvidenceBodyNode = EvidenceBodyNode;
global.DirectEvidenceNode = DirectEvidenceNode;
global.PatternMatchNode = PatternMatchNode;
global.DefeasibleLogicNode = DefeasibleLogicNode;
global.FusionNode = FusionNode;
global.PredicateNode = PredicateNode;
global.ExpressionNode = ExpressionNode;
global.WithClauseNode = WithClauseNode;
global.MeasureNode = MeasureNode;
global.MeasureBodyNode = MeasureBodyNode;
global.AggregationNode = AggregationNode;

// Import the generated parser
import { parse } from './GeneratedParser.js';

// Create a wrapper class that matches the expected interface
export class PeggyDSLParser {
  static parse(text) {
    console.log('PeggyDSLParser: Parsing text:', text.substring(0, 100) + '...');
    try {
      const result = parse(text);
      console.log('PeggyDSLParser: Parse result:', result);
      return result;
    } catch (error) {
      console.error('PeggyDSLParser: Parse error:', error.message);
      throw error;
    }
  }
}
