import{a,b as f,c as u}from"./chunk-LORZLZWG.mjs";import{a as l}from"./chunk-JQRUD6KW.mjs";import{b as p}from"./chunk-DMV4VAQV.mjs";import"./chunk-HNC4WDU7.mjs";import"./chunk-SATU7PGQ.mjs";import"./chunk-224SPVON.mjs";import"./chunk-EQFTRU2I.mjs";import"./chunk-E5QJAATJ.mjs";import{b as m}from"./chunk-66DQ2XMT.mjs";import"./chunk-D6VWDJW2.mjs";import"./chunk-BI6VK774.mjs";import"./chunk-XNMVGMAZ.mjs";import"./chunk-4RFN2BYJ.mjs";import"./chunk-FWYVLQTC.mjs";import"./chunk-RRFMTAIC.mjs";import"./chunk-TZUXEDM2.mjs";import"./chunk-OIYT25JQ.mjs";import"./chunk-NV3KIAZN.mjs";import"./chunk-L5GCOVLC.mjs";import"./chunk-6BELYETK.mjs";import"./chunk-2AEHWXPW.mjs";import{b as i}from"./chunk-LIEV3EAG.mjs";import{a as t}from"./chunk-AQ6EADP3.mjs";var d=m().RailroadAbnf.parser.LangiumParser,s=t(e=>{let r=e.alternatives.map(y);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),y=t(e=>{let r=e.elements.map(R);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),g=t(e=>{if(e.includes("*")){let[n,o]=e.split("*"),b=n?parseInt(n,10):0,c=o?parseInt(o,10):1/0;return{min:b,max:c}}let r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),R=t(e=>{let r=N(e.primary);if(!e.repeat)return r;let{min:n,max:o}=g(e.repeat);return n===0&&o===1?{type:"optional",element:r}:{type:"repetition",element:r,min:n,max:o}},"transformElement"),N=t(e=>{switch(e.$type){case"AbnfStringLiteral":return{type:"terminal",value:e.value};case"AbnfNumVal":return{type:"terminal",value:e.value};case"AbnfRuleName":return{type:"nonterminal",name:e.name};case"AbnfGroup":return s(e.element);case"AbnfOptionalGroup":return{type:"optional",element:s(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=t(e=>({name:e.name,definition:s(e.definition)}),"transformRule"),S=t(e=>{l(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),A={parse:t(e=>{a.clear(),i.debug("[ABNF Parser] Starting Langium parse");let r=d.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new p(r);let n=r.value;i.debug("[ABNF Parser] Parsed rules:",n.rules.length),S(n),i.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}};var C={parser:A,db:a,renderer:u,styles:f};export{C as diagram};
