import{a as n,b as p,c as f}from"./chunk-75QXCHJN.js";import"./chunk-T4KNOXOM.js";import{a as i}from"./chunk-CDENLQJG.js";import{b as l}from"./chunk-23OFDAHQ.js";import"./chunk-64RAZIDH.js";import{b as m}from"./chunk-BKUW36BS.js";import"./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 o}from"./chunk-ZZZJFKF2.js";import{a as t}from"./chunk-YUSHYV7C.js";import"./chunk-C6Q5SG76.js";var c=m().RailroadEbnf.parser.LangiumParser,s=t(e=>{let r=e.alternatives.map(E);return r.length===1?r[0]:{type:"choice",alternatives:r}},"transformChoice"),E=t(e=>{let r=e.elements.map(y);return r.length===1?r[0]:{type:"sequence",elements:r}},"transformSequence"),u=t(e=>{switch(e.$type){case"EbnfTerminal":return{type:"terminal",value:e.value};case"EbnfNonTerminal":return{type:"nonterminal",name:e.name};case"EbnfSpecial":return{type:"special",text:e.text};case"EbnfGroup":return s(e.element);case"EbnfOptional":return{type:"optional",element:s(e.element)};case"EbnfRepetition":return{type:"repetition",element:s(e.element),min:0,max:1/0};default:throw new Error(`Unsupported EBNF primary node: ${e.$type}`)}},"transformPrimary"),b=t((e,r)=>{switch(r.$type){case"EbnfOptionalPostfix":return{type:"optional",element:e};case"EbnfZeroOrMorePostfix":return{type:"repetition",element:e,min:0,max:1/0};case"EbnfOneOrMorePostfix":return{type:"repetition",element:e,min:1,max:1/0};case"EbnfExceptionPostfix":return{type:"sequence",elements:[e,{type:"terminal",value:"-"},u(r.except)]};default:throw new Error(`Unsupported EBNF postfix node: ${r.$type}`)}},"transformPostfix"),y=t(e=>e.postfixes.reduce((r,a)=>b(r,a),u(e.base)),"transformTerm"),d=t(e=>({name:e.name,definition:s(e.definition)}),"transformRule"),v=t(e=>{i(e,n),e.title&&n.setTitle(e.title),e.rules.map(r=>n.addRule(d(r)))},"populateDb"),P={parse:t(e=>{n.clear(),o.debug("[EBNF Parser] Starting Langium parse");let r=c.parse(e);if(r.lexerErrors.length>0||r.parserErrors.length>0)throw new l(r);let a=r.value;o.debug("[EBNF Parser] Parsed rules:",a.rules.length),v(a),o.debug("[EBNF Parser] Parse complete")},"parse"),parser:{yy:n}},$={parser:P,db:n,renderer:f,styles:p};export{$ as diagram};
