import{En as e,On as t}from"./index-D6r_eLun.js";import{t as n,u as r}from"./mermaid-parser.core-BItfoGLM.js";import{n as i,r as a,t as o}from"./chunk-MOJQB5TN-DYfRxFD_.js";import{t as s}from"./chunk-JWPE2WC7-BBxS46F4.js";var c=r().RailroadPeg.parser.LangiumParser,l=t(e=>{let t=e.alternatives.map(u);return t.length===1?t[0]:{type:`choice`,alternatives:t}},`transformOrderedChoice`),u=t(e=>{let t=e.elements.map(d);return t.length===1?t[0]:{type:`sequence`,elements:t}},`transformSequence`),d=t(e=>{let t=p(e.suffix);return e.operator?{type:`special`,text:e.operator===`&`?`&${f(t)}`:`!${f(t)}`}:t},`transformPrefix`),f=t(e=>{switch(e.type){case`terminal`:return`"${e.value}"`;case`nonterminal`:return e.name;case`special`:return e.text;default:return`(...)`}},`nodeToLabel`),p=t(e=>{let t=m(e.primary);if(!e.operator)return t;switch(e.operator){case`?`:return{type:`optional`,element:t};case`*`:return{type:`repetition`,element:t,min:0,max:1/0};case`+`:return{type:`repetition`,element:t,min:1,max:1/0};default:throw Error(`Unsupported PEG suffix operator: ${e.operator}`)}},`transformSuffix`),m=t(e=>{switch(e.$type){case`PegLiteral`:return{type:`terminal`,value:e.value};case`PegIdentifier`:return{type:`nonterminal`,name:e.name};case`PegGroup`:return l(e.element);case`PegAny`:return{type:`special`,text:e.dot};default:throw Error(`Unsupported PEG primary node: ${e.$type}`)}},`transformPrimary`),h=t(e=>({name:e.name,definition:l(e.definition)}),`transformRule`),g=t(e=>{s(e,o),e.title&&o.setTitle(e.title),e.rules.map(e=>o.addRule(h(e)))},`populateDb`),_={parser:{parse:t(t=>{o.clear(),e.debug(`[PEG Parser] Starting Langium parse`);let r=c.parse(t);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new n(r);let i=r.value;e.debug(`[PEG Parser] Parsed rules:`,i.rules.length),g(i),e.debug(`[PEG Parser] Parse complete`)},`parse`),parser:{yy:o}},db:o,renderer:a,styles:i};export{_ as diagram};