"use strict";var X=Object.defineProperty;var M=(n,t,e)=>t in n?X(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var r=(n,t,e)=>M(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("antlr4");function v(n){return n.symbol.tokenIndex!==-1?n.getText():""}function A(n){return n?(n.exception,n.getText()):""}function B(n,t){let e="";try{e=t(n)}catch{e=n.getText()}return e===""&&(e=n.getText()),e}function z(n){return v(n.OPEN())+A(n.name())+n.attr_list().map(A).join("")+(n.tag_body()?A(n.tag_body()):"}")}function N(n){return{error:{value:n}}}function O(n){var h;const t=n.text(),e=n.include_block(),i=n.tag_block();if(t)return{text:t.getText()};if(e)return{include:{value:e.INCLUDE_TEXT_list().map(T=>T.getText()).join("")}};if(i){const E=B(i,z);try{const T=i.name().getText();if(T==="")return N(E);const u=i.tag_body(),I=((h=u==null?void 0:u.SEPARATOR())==null?void 0:h.getText())??"",H=G((u==null?void 0:u.body())??null),F=i.attr_list().filter(o=>!o.exception).map(o=>{var _;const k=o.NAME().getText(),g=(_=o.attr_text())==null?void 0:_.getText();return{name:k,value:g??"",empty:!g}});return{tag:{name:T,body:H,attrList:F,separator:I}}}catch{return N(E)}}return N(n.getText())}function G(n){const t=[];for(const e of(n==null?void 0:n.block_list())??[])t.push(O(e));return{blocks:t}}function f(n){const t=[];for(const e of n.file_block_list()){const i=e.block(),h=e.CLOSE();i?t.push(O(i)):h&&t.push({text:h.getText()})}return{blocks:t}}const l=class l extends a.Lexer{constructor(t){super(t),this._interp=new a.LexerATNSimulator(this,l._ATN,l.DecisionsToDFA,new a.PredictionContextCache)}get grammarFileName(){return"bookbox_lexer.g4"}get literalNames(){return l.literalNames}get symbolicNames(){return l.symbolicNames}get ruleNames(){return l.ruleNames}get serializedATN(){return l._serializedATN}get channelNames(){return l.channelNames}get modeNames(){return l.modeNames}static get _ATN(){return l.__ATN||(l.__ATN=new a.ATNDeserializer().deserialize(l._serializedATN)),l.__ATN}};r(l,"ESC",1),r(l,"INCLUDE_OPEN",2),r(l,"OPEN",3),r(l,"CLOSE",4),r(l,"TEXT",5),r(l,"SYSTEM_FLAG",6),r(l,"NAME",7),r(l,"DOT",8),r(l,"COLON",9),r(l,"ATTR_OPEN",10),r(l,"SEPARATOR",11),r(l,"SELF_CLOSE",12),r(l,"UNKNOWN",13),r(l,"ATTR_ESC",14),r(l,"ATTR_CLOSE",15),r(l,"ATTR_TEXT",16),r(l,"INCLUDE_CLOSE",17),r(l,"INCLUDE_TEXT",18),r(l,"EOF",a.Token.EOF),r(l,"BLOCK",1),r(l,"ATTR",2),r(l,"INCLUDE",3),r(l,"channelNames",["DEFAULT_TOKEN_CHANNEL","HIDDEN"]),r(l,"literalNames",[null,null,"'{{'",null,null,null,"'#'",null,"'.'","':'",null,null,null,null,null,null,null,"'}}'"]),r(l,"symbolicNames",[null,"ESC","INCLUDE_OPEN","OPEN","CLOSE","TEXT","SYSTEM_FLAG","NAME","DOT","COLON","ATTR_OPEN","SEPARATOR","SELF_CLOSE","UNKNOWN","ATTR_ESC","ATTR_CLOSE","ATTR_TEXT","INCLUDE_CLOSE","INCLUDE_TEXT"]),r(l,"modeNames",["DEFAULT_MODE","BLOCK","ATTR","INCLUDE"]),r(l,"ruleNames",["ESC","INCLUDE_OPEN","OPEN","CLOSE","TEXT","SYSTEM_FLAG","NAME","DOT","COLON","ATTR_OPEN","SEPARATOR","SELF_CLOSE","UNKNOWN","ATTR_ESC","ATTR_CLOSE","ATTR_TEXT","INCLUDE_CLOSE","INCLUDE_TEXT"]),r(l,"_serializedATN",[4,0,18,99,6,-1,6,-1,6,-1,6,-1,2,0,7,0,2,1,7,1,2,2,7,2,2,3,7,3,2,4,7,4,2,5,7,5,2,6,7,6,2,7,7,7,2,8,7,8,2,9,7,9,2,10,7,10,2,11,7,11,2,12,7,12,2,13,7,13,2,14,7,14,2,15,7,15,2,16,7,16,2,17,7,17,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,2,1,2,1,3,1,3,1,4,1,4,1,5,1,5,1,6,4,6,60,8,6,11,6,12,6,61,1,7,1,7,1,8,1,8,1,9,1,9,1,9,1,9,1,10,1,10,1,10,1,10,1,11,1,11,1,11,1,11,1,12,1,12,1,12,1,12,1,13,1,13,1,13,1,14,1,14,1,14,1,14,1,15,1,15,1,16,1,16,1,16,1,16,1,16,1,17,1,17,0,0,18,4,1,6,2,8,3,10,4,12,5,14,6,16,7,18,8,20,9,22,10,24,11,26,12,28,13,30,14,32,15,34,16,36,17,38,18,4,0,1,2,3,2,1,0,97,122,3,0,9,10,13,13,32,32,96,0,4,1,0,0,0,0,6,1,0,0,0,0,8,1,0,0,0,0,10,1,0,0,0,0,12,1,0,0,0,1,14,1,0,0,0,1,16,1,0,0,0,1,18,1,0,0,0,1,20,1,0,0,0,1,22,1,0,0,0,1,24,1,0,0,0,1,26,1,0,0,0,1,28,1,0,0,0,2,30,1,0,0,0,2,32,1,0,0,0,2,34,1,0,0,0,3,36,1,0,0,0,3,38,1,0,0,0,4,40,1,0,0,0,6,43,1,0,0,0,8,48,1,0,0,0,10,52,1,0,0,0,12,54,1,0,0,0,14,56,1,0,0,0,16,59,1,0,0,0,18,63,1,0,0,0,20,65,1,0,0,0,22,67,1,0,0,0,24,71,1,0,0,0,26,75,1,0,0,0,28,79,1,0,0,0,30,83,1,0,0,0,32,86,1,0,0,0,34,90,1,0,0,0,36,92,1,0,0,0,38,97,1,0,0,0,40,41,5,92,0,0,41,42,9,0,0,0,42,5,1,0,0,0,43,44,5,123,0,0,44,45,5,123,0,0,45,46,1,0,0,0,46,47,6,1,0,0,47,7,1,0,0,0,48,49,5,123,0,0,49,50,1,0,0,0,50,51,6,2,1,0,51,9,1,0,0,0,52,53,5,125,0,0,53,11,1,0,0,0,54,55,9,0,0,0,55,13,1,0,0,0,56,57,5,35,0,0,57,15,1,0,0,0,58,60,7,0,0,0,59,58,1,0,0,0,60,61,1,0,0,0,61,59,1,0,0,0,61,62,1,0,0,0,62,17,1,0,0,0,63,64,5,46,0,0,64,19,1,0,0,0,65,66,5,58,0,0,66,21,1,0,0,0,67,68,5,123,0,0,68,69,1,0,0,0,69,70,6,9,2,0,70,23,1,0,0,0,71,72,7,1,0,0,72,73,1,0,0,0,73,74,6,10,3,0,74,25,1,0,0,0,75,76,5,125,0,0,76,77,1,0,0,0,77,78,6,11,3,0,78,27,1,0,0,0,79,80,9,0,0,0,80,81,1,0,0,0,81,82,6,12,3,0,82,29,1,0,0,0,83,84,5,92,0,0,84,85,9,0,0,0,85,31,1,0,0,0,86,87,5,125,0,0,87,88,1,0,0,0,88,89,6,14,3,0,89,33,1,0,0,0,90,91,9,0,0,0,91,35,1,0,0,0,92,93,5,125,0,0,93,94,5,125,0,0,94,95,1,0,0,0,95,96,6,16,4,0,96,37,1,0,0,0,97,98,9,0,0,0,98,39,1,0,0,0,5,0,1,2,3,61,5,2,3,0,5,1,0,5,2,0,4,0,0,2,0,0]),r(l,"__ATN"),r(l,"DecisionsToDFA",l._ATN.decisionToState.map((t,e)=>new a.DFA(t,e)));let R=l;const s=class s extends a.Parser{get grammarFileName(){return"bookbox_parser.g4"}get literalNames(){return s.literalNames}get symbolicNames(){return s.symbolicNames}get ruleNames(){return s.ruleNames}get serializedATN(){return s._serializedATN}createFailedPredicateException(t,e){return new a.FailedPredicateException(this,t,e)}constructor(t){super(t),this._interp=new a.ParserATNSimulator(this,s._ATN,s.DecisionsToDFA,new a.PredictionContextCache)}file(){let t=new K(this,this._ctx,this.state);this.enterRule(t,0,s.RULE_file);let e;try{for(this.enterOuterAlt(t,1),this.state=25,this._errHandler.sync(this),e=this._input.LA(1);!(e&-32)&&1<new a.DFA(t,e)));let c=s;class K extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}file_block_list(){return this.getTypedRuleContexts(L)}file_block(t){return this.getTypedRuleContext(L,t)}get ruleIndex(){return c.RULE_file}enterRule(t){t.enterFile&&t.enterFile(this)}exitRule(t){t.exitFile&&t.exitFile(this)}}class L extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}block(){return this.getTypedRuleContext(d,0)}CLOSE(){return this.getToken(c.CLOSE,0)}get ruleIndex(){return c.RULE_file_block}enterRule(t){t.enterFile_block&&t.enterFile_block(this)}exitRule(t){t.exitFile_block&&t.exitFile_block(this)}}class y extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}block_list(){return this.getTypedRuleContexts(d)}block(t){return this.getTypedRuleContext(d,t)}get ruleIndex(){return c.RULE_body}enterRule(t){t.enterBody&&t.enterBody(this)}exitRule(t){t.exitBody&&t.exitBody(this)}}class d extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}include_block(){return this.getTypedRuleContext(D,0)}tag_block(){return this.getTypedRuleContext(x,0)}text(){return this.getTypedRuleContext(p,0)}get ruleIndex(){return c.RULE_block}enterRule(t){t.enterBlock&&t.enterBlock(this)}exitRule(t){t.exitBlock&&t.exitBlock(this)}}class p extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}TEXT_list(){return this.getTokens(c.TEXT)}TEXT(t){return this.getToken(c.TEXT,t)}ESC_list(){return this.getTokens(c.ESC)}ESC(t){return this.getToken(c.ESC,t)}get ruleIndex(){return c.RULE_text}enterRule(t){t.enterText&&t.enterText(this)}exitRule(t){t.exitText&&t.exitText(this)}}class x extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}OPEN(){return this.getToken(c.OPEN,0)}name(){return this.getTypedRuleContext(S,0)}tag_body(){return this.getTypedRuleContext(m,0)}SELF_CLOSE(){return this.getToken(c.SELF_CLOSE,0)}attr_list(){return this.getTypedRuleContexts(C)}attr(t){return this.getTypedRuleContext(C,t)}get ruleIndex(){return c.RULE_tag_block}enterRule(t){t.enterTag_block&&t.enterTag_block(this)}exitRule(t){t.exitTag_block&&t.exitTag_block(this)}}class m extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}SEPARATOR(){return this.getToken(c.SEPARATOR,0)}body(){return this.getTypedRuleContext(y,0)}CLOSE(){return this.getToken(c.CLOSE,0)}get ruleIndex(){return c.RULE_tag_body}enterRule(t){t.enterTag_body&&t.enterTag_body(this)}exitRule(t){t.exitTag_body&&t.exitTag_body(this)}}class S extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}NAME_list(){return this.getTokens(c.NAME)}NAME(t){return this.getToken(c.NAME,t)}SYSTEM_FLAG(){return this.getToken(c.SYSTEM_FLAG,0)}COLON_list(){return this.getTokens(c.COLON)}COLON(t){return this.getToken(c.COLON,t)}get ruleIndex(){return c.RULE_name}enterRule(t){t.enterName&&t.enterName(this)}exitRule(t){t.exitName&&t.exitName(this)}}class C extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}DOT(){return this.getToken(c.DOT,0)}NAME(){return this.getToken(c.NAME,0)}ATTR_OPEN(){return this.getToken(c.ATTR_OPEN,0)}attr_text(){return this.getTypedRuleContext(U,0)}ATTR_CLOSE(){return this.getToken(c.ATTR_CLOSE,0)}get ruleIndex(){return c.RULE_attr}enterRule(t){t.enterAttr&&t.enterAttr(this)}exitRule(t){t.exitAttr&&t.exitAttr(this)}}class U extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}ATTR_TEXT_list(){return this.getTokens(c.ATTR_TEXT)}ATTR_TEXT(t){return this.getToken(c.ATTR_TEXT,t)}ATTR_ESC_list(){return this.getTokens(c.ATTR_ESC)}ATTR_ESC(t){return this.getToken(c.ATTR_ESC,t)}get ruleIndex(){return c.RULE_attr_text}enterRule(t){t.enterAttr_text&&t.enterAttr_text(this)}exitRule(t){t.exitAttr_text&&t.exitAttr_text(this)}}class D extends a.ParserRuleContext{constructor(t,e,i){super(e,i),this.parser=t}INCLUDE_OPEN(){return this.getToken(c.INCLUDE_OPEN,0)}INCLUDE_CLOSE(){return this.getToken(c.INCLUDE_CLOSE,0)}INCLUDE_TEXT_list(){return this.getTokens(c.INCLUDE_TEXT)}INCLUDE_TEXT(t){return this.getToken(c.INCLUDE_TEXT,t)}get ruleIndex(){return c.RULE_include_block}enterRule(t){t.enterInclude_block&&t.enterInclude_block(this)}exitRule(t){t.exitInclude_block&&t.exitInclude_block(this)}}function w(n){const t=new a.CharStream(n),e=new R(t);return new a.CommonTokenStream(e)}function Y(n){const t=w(n),i=new c(t).file();return f(i)}function $(n){return w(n).tokens.map(e=>[e.text,R.symbolicNames[e.type]??""])}function j(n){const{name:t,value:e,empty:i}=n,h=i?"":`{${e}}`;return`.${t}${h}`}function P(n){return n.blocks.map(t=>{if(t.text)return t.text;if(t.include)return`{{${t.include.value}}}`;if(t.tag){const{attrList:e,body:i,name:h,separator:E}=t.tag,T=e.map(j).join(""),u=i?P(i):"";return`{${h}${T}${E}${u}}`}}).join("")}exports.getTokens=$;exports.parse=Y;exports.prepareFile=f;exports.stringify=P;