import{a,b as u,c as f}from"./chunk-75QXCHJN.js";import"./chunk-T4KNOXOM.js";import{a as m}from"./chunk-CDENLQJG.js";import{b as p}from"./chunk-23OFDAHQ.js";import"./chunk-64RAZIDH.js";import"./chunk-BKUW36BS.js";import{b as l}from"./chunk-4R6AKNXZ.js";import"./chunk-7BXJKEEM.js";import"./chunk-KKCTMRNV.js";import"./chunk-3JAGLS23.js";import"./chunk-PVZRSI6V.js";import"./chunk-JDVLQXMK.js";import"./chunk-WQ47ED54.js";import"./chunk-AP7GPLJ7.js";import"./chunk-W7QF4GTN.js";import"./chunk-42NANJO2.js";import"./chunk-GYOZBIN2.js";import"./chunk-RLKBNOCG.js";import"./chunk-CR6SF2HR.js";import"./chunk-7AJGXJKH.js";import"./chunk-E5GXGYZM.js";import{b as s}from"./chunk-ZZZJFKF2.js";import{a as t}from"./chunk-YUSHYV7C.js";import"./chunk-C6Q5SG76.js";var v=l().RailroadAbnf.parser.LangiumParser,i=t(e=>{let r=e.alternatives.map(g);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformAlternation"),g=t(e=>{let r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformConcatenation"),b=t(e=>{if(e.includes("*")){let[n,o]=e.split("*"),c=n?parseInt(n,10):0,d=o?parseInt(o,10):1/0;return{min:c,max:d}}let r=parseInt(e,10);return{min:r,max:r}},"parseRepeat"),y=t(e=>{let r=A(e.primary);if(!e.repeat)return r;let{min:n,max:o}=b(e.repeat);return n===0&&o===1?{type:"optional",element:r}:{type:"repetition",element:r,min:n,max:o}},"transformElement"),A=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 i(e.element);case"AbnfOptionalGroup":return{type:"optional",element:i(e.element)};default:throw new Error(`Unsupported ABNF primary node: ${e.$type}`)}},"transformPrimary"),P=t(e=>({name:e.name,definition:i(e.definition)}),"transformRule"),h=t(e=>{m(e,a),e.title&&a.setTitle(e.title),e.rules.map(r=>a.addRule(P(r)))},"populateDb"),R={parse:t(e=>{a.clear(),s.debug("[ABNF Parser] Starting Langium parse");let r=v.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new p(r);let n=r.value;s.debug("[ABNF Parser] Parsed rules:",n.rules.length),h(n),s.debug("[ABNF Parser] Parse complete")},"parse"),parser:{yy:a}},I={parser:R,db:a,renderer:f,styles:u};export{I as diagram};
