UNPKG

@bookbox/markup

Version:

Markup language for bookbox format

2,959 lines (2,958 loc) 41.7 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { Lexer, Token, LexerATNSimulator, PredictionContextCache, ATNDeserializer, DFA, Parser, FailedPredicateException, ParserATNSimulator, RecognitionException, NoViableAltException, ATN, ParserRuleContext, CharStream, CommonTokenStream } from "antlr4"; const _bookbox_lexer = class _bookbox_lexer extends Lexer { constructor(input) { super(input); this._interp = new LexerATNSimulator(this, _bookbox_lexer._ATN, _bookbox_lexer.DecisionsToDFA, new PredictionContextCache()); } get grammarFileName() { return "bookbox_lexer.g4"; } get literalNames() { return _bookbox_lexer.literalNames; } get symbolicNames() { return _bookbox_lexer.symbolicNames; } get ruleNames() { return _bookbox_lexer.ruleNames; } get serializedATN() { return _bookbox_lexer._serializedATN; } get channelNames() { return _bookbox_lexer.channelNames; } get modeNames() { return _bookbox_lexer.modeNames; } static get _ATN() { if (!_bookbox_lexer.__ATN) { _bookbox_lexer.__ATN = new ATNDeserializer().deserialize(_bookbox_lexer._serializedATN); } return _bookbox_lexer.__ATN; } }; __publicField(_bookbox_lexer, "ESC", 1); __publicField(_bookbox_lexer, "INCLUDE_OPEN", 2); __publicField(_bookbox_lexer, "OPEN", 3); __publicField(_bookbox_lexer, "CLOSE", 4); __publicField(_bookbox_lexer, "TEXT", 5); __publicField(_bookbox_lexer, "SYSTEM_FLAG", 6); __publicField(_bookbox_lexer, "NAME", 7); __publicField(_bookbox_lexer, "DOT", 8); __publicField(_bookbox_lexer, "COLON", 9); __publicField(_bookbox_lexer, "ATTR_OPEN", 10); __publicField(_bookbox_lexer, "SEPARATOR", 11); __publicField(_bookbox_lexer, "SELF_CLOSE", 12); __publicField(_bookbox_lexer, "UNKNOWN", 13); __publicField(_bookbox_lexer, "ATTR_ESC", 14); __publicField(_bookbox_lexer, "ATTR_CLOSE", 15); __publicField(_bookbox_lexer, "ATTR_TEXT", 16); __publicField(_bookbox_lexer, "INCLUDE_CLOSE", 17); __publicField(_bookbox_lexer, "INCLUDE_TEXT", 18); __publicField(_bookbox_lexer, "EOF", Token.EOF); __publicField(_bookbox_lexer, "BLOCK", 1); __publicField(_bookbox_lexer, "ATTR", 2); __publicField(_bookbox_lexer, "INCLUDE", 3); __publicField(_bookbox_lexer, "channelNames", ["DEFAULT_TOKEN_CHANNEL", "HIDDEN"]); __publicField(_bookbox_lexer, "literalNames", [ null, null, "'{{'", null, null, null, "'#'", null, "'.'", "':'", null, null, null, null, null, null, null, "'}}'" ]); __publicField(_bookbox_lexer, "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" ]); __publicField(_bookbox_lexer, "modeNames", [ "DEFAULT_MODE", "BLOCK", "ATTR", "INCLUDE" ]); __publicField(_bookbox_lexer, "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" ]); __publicField(_bookbox_lexer, "_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 ]); __publicField(_bookbox_lexer, "__ATN"); __publicField(_bookbox_lexer, "DecisionsToDFA", _bookbox_lexer._ATN.decisionToState.map((ds, index) => new DFA(ds, index))); let bookbox_lexer = _bookbox_lexer; const _bookbox_parser = class _bookbox_parser extends Parser { get grammarFileName() { return "bookbox_parser.g4"; } get literalNames() { return _bookbox_parser.literalNames; } get symbolicNames() { return _bookbox_parser.symbolicNames; } get ruleNames() { return _bookbox_parser.ruleNames; } get serializedATN() { return _bookbox_parser._serializedATN; } createFailedPredicateException(predicate, message) { return new FailedPredicateException(this, predicate, message); } constructor(input) { super(input); this._interp = new ParserATNSimulator(this, _bookbox_parser._ATN, _bookbox_parser.DecisionsToDFA, new PredictionContextCache()); } // @RuleVersion(0) file() { let localctx = new FileContext(this, this._ctx, this.state); this.enterRule(localctx, 0, _bookbox_parser.RULE_file); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 25; this._errHandler.sync(this); _la = this._input.LA(1); while ((_la & ~31) === 0 && (1 << _la & 62) !== 0) { { { this.state = 22; this.file_block(); } } this.state = 27; this._errHandler.sync(this); _la = this._input.LA(1); } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) file_block() { let localctx = new File_blockContext(this, this._ctx, this.state); this.enterRule(localctx, 2, _bookbox_parser.RULE_file_block); try { this.state = 30; this._errHandler.sync(this); switch (this._input.LA(1)) { case 1: case 2: case 3: case 5: this.enterOuterAlt(localctx, 1); { this.state = 28; this.block(); } break; case 4: this.enterOuterAlt(localctx, 2); { this.state = 29; this.match(_bookbox_parser.CLOSE); } break; default: throw new NoViableAltException(this); } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) body() { let localctx = new BodyContext(this, this._ctx, this.state); this.enterRule(localctx, 4, _bookbox_parser.RULE_body); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 35; this._errHandler.sync(this); _la = this._input.LA(1); while ((_la & ~31) === 0 && (1 << _la & 46) !== 0) { { { this.state = 32; this.block(); } } this.state = 37; this._errHandler.sync(this); _la = this._input.LA(1); } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) block() { let localctx = new BlockContext(this, this._ctx, this.state); this.enterRule(localctx, 6, _bookbox_parser.RULE_block); try { this.state = 41; this._errHandler.sync(this); switch (this._input.LA(1)) { case 2: this.enterOuterAlt(localctx, 1); { this.state = 38; this.include_block(); } break; case 3: this.enterOuterAlt(localctx, 2); { this.state = 39; this.tag_block(); } break; case 1: case 5: this.enterOuterAlt(localctx, 3); { this.state = 40; this.text(); } break; default: throw new NoViableAltException(this); } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) text() { let localctx = new TextContext(this, this._ctx, this.state); this.enterRule(localctx, 8, _bookbox_parser.RULE_text); let _la; try { let _alt; this.enterOuterAlt(localctx, 1); { this.state = 44; this._errHandler.sync(this); _alt = 1; do { switch (_alt) { case 1: { { this.state = 43; _la = this._input.LA(1); if (!(_la === 1 || _la === 5)) { this._errHandler.recoverInline(this); } else { this._errHandler.reportMatch(this); this.consume(); } } } break; default: throw new NoViableAltException(this); } this.state = 46; this._errHandler.sync(this); _alt = this._interp.adaptivePredict(this._input, 4, this._ctx); } while (_alt !== 2 && _alt !== ATN.INVALID_ALT_NUMBER); } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) tag_block() { let localctx = new Tag_blockContext(this, this._ctx, this.state); this.enterRule(localctx, 10, _bookbox_parser.RULE_tag_block); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 48; this.match(_bookbox_parser.OPEN); this.state = 49; this.name(); this.state = 53; this._errHandler.sync(this); _la = this._input.LA(1); while (_la === 8) { { { this.state = 50; this.attr(); } } this.state = 55; this._errHandler.sync(this); _la = this._input.LA(1); } this.state = 58; this._errHandler.sync(this); switch (this._input.LA(1)) { case 11: { this.state = 56; this.tag_body(); } break; case 12: { this.state = 57; this.match(_bookbox_parser.SELF_CLOSE); } break; default: throw new NoViableAltException(this); } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) tag_body() { let localctx = new Tag_bodyContext(this, this._ctx, this.state); this.enterRule(localctx, 12, _bookbox_parser.RULE_tag_body); try { this.enterOuterAlt(localctx, 1); { this.state = 60; this.match(_bookbox_parser.SEPARATOR); this.state = 61; this.body(); this.state = 62; this.match(_bookbox_parser.CLOSE); } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) name() { let localctx = new NameContext(this, this._ctx, this.state); this.enterRule(localctx, 14, _bookbox_parser.RULE_name); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 65; this._errHandler.sync(this); _la = this._input.LA(1); if (_la === 6) { { this.state = 64; this.match(_bookbox_parser.SYSTEM_FLAG); } } this.state = 67; this.match(_bookbox_parser.NAME); this.state = 72; this._errHandler.sync(this); _la = this._input.LA(1); while (_la === 9) { { { this.state = 68; this.match(_bookbox_parser.COLON); this.state = 69; this.match(_bookbox_parser.NAME); } } this.state = 74; this._errHandler.sync(this); _la = this._input.LA(1); } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) attr() { let localctx = new AttrContext(this, this._ctx, this.state); this.enterRule(localctx, 16, _bookbox_parser.RULE_attr); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 75; this.match(_bookbox_parser.DOT); this.state = 76; this.match(_bookbox_parser.NAME); this.state = 81; this._errHandler.sync(this); _la = this._input.LA(1); if (_la === 10) { { this.state = 77; this.match(_bookbox_parser.ATTR_OPEN); this.state = 78; this.attr_text(); this.state = 79; this.match(_bookbox_parser.ATTR_CLOSE); } } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) attr_text() { let localctx = new Attr_textContext(this, this._ctx, this.state); this.enterRule(localctx, 18, _bookbox_parser.RULE_attr_text); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 86; this._errHandler.sync(this); _la = this._input.LA(1); while (_la === 14 || _la === 16) { { { this.state = 83; _la = this._input.LA(1); if (!(_la === 14 || _la === 16)) { this._errHandler.recoverInline(this); } else { this._errHandler.reportMatch(this); this.consume(); } } } this.state = 88; this._errHandler.sync(this); _la = this._input.LA(1); } } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } // @RuleVersion(0) include_block() { let localctx = new Include_blockContext(this, this._ctx, this.state); this.enterRule(localctx, 20, _bookbox_parser.RULE_include_block); let _la; try { this.enterOuterAlt(localctx, 1); { this.state = 89; this.match(_bookbox_parser.INCLUDE_OPEN); this.state = 93; this._errHandler.sync(this); _la = this._input.LA(1); while (_la === 18) { { { this.state = 90; this.match(_bookbox_parser.INCLUDE_TEXT); } } this.state = 95; this._errHandler.sync(this); _la = this._input.LA(1); } this.state = 96; this.match(_bookbox_parser.INCLUDE_CLOSE); } } catch (re) { if (re instanceof RecognitionException) { localctx.exception = re; this._errHandler.reportError(this, re); this._errHandler.recover(this, re); } else { throw re; } } finally { this.exitRule(); } return localctx; } static get _ATN() { if (!_bookbox_parser.__ATN) { _bookbox_parser.__ATN = new ATNDeserializer().deserialize(_bookbox_parser._serializedATN); } return _bookbox_parser.__ATN; } }; __publicField(_bookbox_parser, "ESC", 1); __publicField(_bookbox_parser, "INCLUDE_OPEN", 2); __publicField(_bookbox_parser, "OPEN", 3); __publicField(_bookbox_parser, "CLOSE", 4); __publicField(_bookbox_parser, "TEXT", 5); __publicField(_bookbox_parser, "SYSTEM_FLAG", 6); __publicField(_bookbox_parser, "NAME", 7); __publicField(_bookbox_parser, "DOT", 8); __publicField(_bookbox_parser, "COLON", 9); __publicField(_bookbox_parser, "ATTR_OPEN", 10); __publicField(_bookbox_parser, "SEPARATOR", 11); __publicField(_bookbox_parser, "SELF_CLOSE", 12); __publicField(_bookbox_parser, "UNKNOWN", 13); __publicField(_bookbox_parser, "ATTR_ESC", 14); __publicField(_bookbox_parser, "ATTR_CLOSE", 15); __publicField(_bookbox_parser, "ATTR_TEXT", 16); __publicField(_bookbox_parser, "INCLUDE_CLOSE", 17); __publicField(_bookbox_parser, "INCLUDE_TEXT", 18); __publicField(_bookbox_parser, "EOF", Token.EOF); __publicField(_bookbox_parser, "RULE_file", 0); __publicField(_bookbox_parser, "RULE_file_block", 1); __publicField(_bookbox_parser, "RULE_body", 2); __publicField(_bookbox_parser, "RULE_block", 3); __publicField(_bookbox_parser, "RULE_text", 4); __publicField(_bookbox_parser, "RULE_tag_block", 5); __publicField(_bookbox_parser, "RULE_tag_body", 6); __publicField(_bookbox_parser, "RULE_name", 7); __publicField(_bookbox_parser, "RULE_attr", 8); __publicField(_bookbox_parser, "RULE_attr_text", 9); __publicField(_bookbox_parser, "RULE_include_block", 10); __publicField(_bookbox_parser, "literalNames", [ null, null, "'{{'", null, null, null, "'#'", null, "'.'", "':'", null, null, null, null, null, null, null, "'}}'" ]); __publicField(_bookbox_parser, "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" ]); // tslint:disable:no-trailing-whitespace __publicField(_bookbox_parser, "ruleNames", [ "file", "file_block", "body", "block", "text", "tag_block", "tag_body", "name", "attr", "attr_text", "include_block" ]); __publicField(_bookbox_parser, "_serializedATN", [ 4, 1, 18, 99, 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, 1, 0, 5, 0, 24, 8, 0, 10, 0, 12, 0, 27, 9, 0, 1, 1, 1, 1, 3, 1, 31, 8, 1, 1, 2, 5, 2, 34, 8, 2, 10, 2, 12, 2, 37, 9, 2, 1, 3, 1, 3, 1, 3, 3, 3, 42, 8, 3, 1, 4, 4, 4, 45, 8, 4, 11, 4, 12, 4, 46, 1, 5, 1, 5, 1, 5, 5, 5, 52, 8, 5, 10, 5, 12, 5, 55, 9, 5, 1, 5, 1, 5, 3, 5, 59, 8, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 3, 7, 66, 8, 7, 1, 7, 1, 7, 1, 7, 5, 7, 71, 8, 7, 10, 7, 12, 7, 74, 9, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 3, 8, 82, 8, 8, 1, 9, 5, 9, 85, 8, 9, 10, 9, 12, 9, 88, 9, 9, 1, 10, 1, 10, 5, 10, 92, 8, 10, 10, 10, 12, 10, 95, 9, 10, 1, 10, 1, 10, 1, 10, 0, 0, 11, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 0, 2, 2, 0, 1, 1, 5, 5, 2, 0, 14, 14, 16, 16, 100, 0, 25, 1, 0, 0, 0, 2, 30, 1, 0, 0, 0, 4, 35, 1, 0, 0, 0, 6, 41, 1, 0, 0, 0, 8, 44, 1, 0, 0, 0, 10, 48, 1, 0, 0, 0, 12, 60, 1, 0, 0, 0, 14, 65, 1, 0, 0, 0, 16, 75, 1, 0, 0, 0, 18, 86, 1, 0, 0, 0, 20, 89, 1, 0, 0, 0, 22, 24, 3, 2, 1, 0, 23, 22, 1, 0, 0, 0, 24, 27, 1, 0, 0, 0, 25, 23, 1, 0, 0, 0, 25, 26, 1, 0, 0, 0, 26, 1, 1, 0, 0, 0, 27, 25, 1, 0, 0, 0, 28, 31, 3, 6, 3, 0, 29, 31, 5, 4, 0, 0, 30, 28, 1, 0, 0, 0, 30, 29, 1, 0, 0, 0, 31, 3, 1, 0, 0, 0, 32, 34, 3, 6, 3, 0, 33, 32, 1, 0, 0, 0, 34, 37, 1, 0, 0, 0, 35, 33, 1, 0, 0, 0, 35, 36, 1, 0, 0, 0, 36, 5, 1, 0, 0, 0, 37, 35, 1, 0, 0, 0, 38, 42, 3, 20, 10, 0, 39, 42, 3, 10, 5, 0, 40, 42, 3, 8, 4, 0, 41, 38, 1, 0, 0, 0, 41, 39, 1, 0, 0, 0, 41, 40, 1, 0, 0, 0, 42, 7, 1, 0, 0, 0, 43, 45, 7, 0, 0, 0, 44, 43, 1, 0, 0, 0, 45, 46, 1, 0, 0, 0, 46, 44, 1, 0, 0, 0, 46, 47, 1, 0, 0, 0, 47, 9, 1, 0, 0, 0, 48, 49, 5, 3, 0, 0, 49, 53, 3, 14, 7, 0, 50, 52, 3, 16, 8, 0, 51, 50, 1, 0, 0, 0, 52, 55, 1, 0, 0, 0, 53, 51, 1, 0, 0, 0, 53, 54, 1, 0, 0, 0, 54, 58, 1, 0, 0, 0, 55, 53, 1, 0, 0, 0, 56, 59, 3, 12, 6, 0, 57, 59, 5, 12, 0, 0, 58, 56, 1, 0, 0, 0, 58, 57, 1, 0, 0, 0, 59, 11, 1, 0, 0, 0, 60, 61, 5, 11, 0, 0, 61, 62, 3, 4, 2, 0, 62, 63, 5, 4, 0, 0, 63, 13, 1, 0, 0, 0, 64, 66, 5, 6, 0, 0, 65, 64, 1, 0, 0, 0, 65, 66, 1, 0, 0, 0, 66, 67, 1, 0, 0, 0, 67, 72, 5, 7, 0, 0, 68, 69, 5, 9, 0, 0, 69, 71, 5, 7, 0, 0, 70, 68, 1, 0, 0, 0, 71, 74, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 15, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 75, 76, 5, 8, 0, 0, 76, 81, 5, 7, 0, 0, 77, 78, 5, 10, 0, 0, 78, 79, 3, 18, 9, 0, 79, 80, 5, 15, 0, 0, 80, 82, 1, 0, 0, 0, 81, 77, 1, 0, 0, 0, 81, 82, 1, 0, 0, 0, 82, 17, 1, 0, 0, 0, 83, 85, 7, 1, 0, 0, 84, 83, 1, 0, 0, 0, 85, 88, 1, 0, 0, 0, 86, 84, 1, 0, 0, 0, 86, 87, 1, 0, 0, 0, 87, 19, 1, 0, 0, 0, 88, 86, 1, 0, 0, 0, 89, 93, 5, 2, 0, 0, 90, 92, 5, 18, 0, 0, 91, 90, 1, 0, 0, 0, 92, 95, 1, 0, 0, 0, 93, 91, 1, 0, 0, 0, 93, 94, 1, 0, 0, 0, 94, 96, 1, 0, 0, 0, 95, 93, 1, 0, 0, 0, 96, 97, 5, 17, 0, 0, 97, 21, 1, 0, 0, 0, 12, 25, 30, 35, 41, 46, 53, 58, 65, 72, 81, 86, 93 ]); __publicField(_bookbox_parser, "__ATN"); __publicField(_bookbox_parser, "DecisionsToDFA", _bookbox_parser._ATN.decisionToState.map((ds, index) => new DFA(ds, index))); let bookbox_parser = _bookbox_parser; class FileContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } file_block_list() { return this.getTypedRuleContexts(File_blockContext); } file_block(i) { return this.getTypedRuleContext(File_blockContext, i); } get ruleIndex() { return bookbox_parser.RULE_file; } enterRule(listener) { if (listener.enterFile) { listener.enterFile(this); } } exitRule(listener) { if (listener.exitFile) { listener.exitFile(this); } } } class File_blockContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } block() { return this.getTypedRuleContext(BlockContext, 0); } CLOSE() { return this.getToken(bookbox_parser.CLOSE, 0); } get ruleIndex() { return bookbox_parser.RULE_file_block; } enterRule(listener) { if (listener.enterFile_block) { listener.enterFile_block(this); } } exitRule(listener) { if (listener.exitFile_block) { listener.exitFile_block(this); } } } class BodyContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } block_list() { return this.getTypedRuleContexts(BlockContext); } block(i) { return this.getTypedRuleContext(BlockContext, i); } get ruleIndex() { return bookbox_parser.RULE_body; } enterRule(listener) { if (listener.enterBody) { listener.enterBody(this); } } exitRule(listener) { if (listener.exitBody) { listener.exitBody(this); } } } class BlockContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } include_block() { return this.getTypedRuleContext(Include_blockContext, 0); } tag_block() { return this.getTypedRuleContext(Tag_blockContext, 0); } text() { return this.getTypedRuleContext(TextContext, 0); } get ruleIndex() { return bookbox_parser.RULE_block; } enterRule(listener) { if (listener.enterBlock) { listener.enterBlock(this); } } exitRule(listener) { if (listener.exitBlock) { listener.exitBlock(this); } } } class TextContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } TEXT_list() { return this.getTokens(bookbox_parser.TEXT); } TEXT(i) { return this.getToken(bookbox_parser.TEXT, i); } ESC_list() { return this.getTokens(bookbox_parser.ESC); } ESC(i) { return this.getToken(bookbox_parser.ESC, i); } get ruleIndex() { return bookbox_parser.RULE_text; } enterRule(listener) { if (listener.enterText) { listener.enterText(this); } } exitRule(listener) { if (listener.exitText) { listener.exitText(this); } } } class Tag_blockContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } OPEN() { return this.getToken(bookbox_parser.OPEN, 0); } name() { return this.getTypedRuleContext(NameContext, 0); } tag_body() { return this.getTypedRuleContext(Tag_bodyContext, 0); } SELF_CLOSE() { return this.getToken(bookbox_parser.SELF_CLOSE, 0); } attr_list() { return this.getTypedRuleContexts(AttrContext); } attr(i) { return this.getTypedRuleContext(AttrContext, i); } get ruleIndex() { return bookbox_parser.RULE_tag_block; } enterRule(listener) { if (listener.enterTag_block) { listener.enterTag_block(this); } } exitRule(listener) { if (listener.exitTag_block) { listener.exitTag_block(this); } } } class Tag_bodyContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } SEPARATOR() { return this.getToken(bookbox_parser.SEPARATOR, 0); } body() { return this.getTypedRuleContext(BodyContext, 0); } CLOSE() { return this.getToken(bookbox_parser.CLOSE, 0); } get ruleIndex() { return bookbox_parser.RULE_tag_body; } enterRule(listener) { if (listener.enterTag_body) { listener.enterTag_body(this); } } exitRule(listener) { if (listener.exitTag_body) { listener.exitTag_body(this); } } } class NameContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } NAME_list() { return this.getTokens(bookbox_parser.NAME); } NAME(i) { return this.getToken(bookbox_parser.NAME, i); } SYSTEM_FLAG() { return this.getToken(bookbox_parser.SYSTEM_FLAG, 0); } COLON_list() { return this.getTokens(bookbox_parser.COLON); } COLON(i) { return this.getToken(bookbox_parser.COLON, i); } get ruleIndex() { return bookbox_parser.RULE_name; } enterRule(listener) { if (listener.enterName) { listener.enterName(this); } } exitRule(listener) { if (listener.exitName) { listener.exitName(this); } } } class AttrContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } DOT() { return this.getToken(bookbox_parser.DOT, 0); } NAME() { return this.getToken(bookbox_parser.NAME, 0); } ATTR_OPEN() { return this.getToken(bookbox_parser.ATTR_OPEN, 0); } attr_text() { return this.getTypedRuleContext(Attr_textContext, 0); } ATTR_CLOSE() { return this.getToken(bookbox_parser.ATTR_CLOSE, 0); } get ruleIndex() { return bookbox_parser.RULE_attr; } enterRule(listener) { if (listener.enterAttr) { listener.enterAttr(this); } } exitRule(listener) { if (listener.exitAttr) { listener.exitAttr(this); } } } class Attr_textContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } ATTR_TEXT_list() { return this.getTokens(bookbox_parser.ATTR_TEXT); } ATTR_TEXT(i) { return this.getToken(bookbox_parser.ATTR_TEXT, i); } ATTR_ESC_list() { return this.getTokens(bookbox_parser.ATTR_ESC); } ATTR_ESC(i) { return this.getToken(bookbox_parser.ATTR_ESC, i); } get ruleIndex() { return bookbox_parser.RULE_attr_text; } enterRule(listener) { if (listener.enterAttr_text) { listener.enterAttr_text(this); } } exitRule(listener) { if (listener.exitAttr_text) { listener.exitAttr_text(this); } } } class Include_blockContext extends ParserRuleContext { constructor(parser, parent, invokingState) { super(parent, invokingState); this.parser = parser; } INCLUDE_OPEN() { return this.getToken(bookbox_parser.INCLUDE_OPEN, 0); } INCLUDE_CLOSE() { return this.getToken(bookbox_parser.INCLUDE_CLOSE, 0); } INCLUDE_TEXT_list() { return this.getTokens(bookbox_parser.INCLUDE_TEXT); } INCLUDE_TEXT(i) { return this.getToken(bookbox_parser.INCLUDE_TEXT, i); } get ruleIndex() { return bookbox_parser.RULE_include_block; } enterRule(listener) { if (listener.enterInclude_block) { listener.enterInclude_block(this); } } exitRule(listener) { if (listener.exitInclude_block) { listener.exitInclude_block(this); } } } function prepareToken(token) { const exist = token.symbol.tokenIndex !== -1; return exist ? token.getText() : ""; } function preparePart(context) { if (!context) return ""; if (context.exception) { return context.getText(); } return context.getText(); } function getReservedText(context, getStandartText) { let reserveText = ""; try { reserveText = getStandartText(context); } catch (e) { reserveText = context.getText(); } if (reserveText === "") { reserveText = context.getText(); } return reserveText; } function getStandartTagBlock(context) { return prepareToken(context.OPEN()) + preparePart(context.name()) + context.attr_list().map(preparePart).join("") + (context.tag_body() ? preparePart(context.tag_body()) : "}"); } function error(value) { return { error: { value } }; } function prepareBlock(ctx) { var _a; const text = ctx.text(); const includeBlock = ctx.include_block(); const tagBlock = ctx.tag_block(); if (text) { return { text: text.getText() }; } else if (includeBlock) { const value = includeBlock.INCLUDE_TEXT_list().map((node) => node.getText()).join(""); return { include: { value } }; } else if (tagBlock) { const reserveText = getReservedText(tagBlock, getStandartTagBlock); try { const name = tagBlock.name().getText(); if (name === "") return error(reserveText); const tagBody = tagBlock.tag_body(); const separator = ((_a = tagBody == null ? void 0 : tagBody.SEPARATOR()) == null ? void 0 : _a.getText()) ?? ""; const body = prepareBody((tagBody == null ? void 0 : tagBody.body()) ?? null); const attrList = tagBlock.attr_list().filter((attr) => !attr.exception).map((attr) => { var _a2; const name2 = attr.NAME().getText(); const value = (_a2 = attr.attr_text()) == null ? void 0 : _a2.getText(); return { name: name2, value: value ?? "", empty: !value }; }); const result = { tag: { name, body, attrList, separator } }; return result; } catch (e) { return error(reserveText); } } return error(ctx.getText()); } function prepareBody(ctx) { const blocks = []; for (const block of (ctx == null ? void 0 : ctx.block_list()) ?? []) { blocks.push(prepareBlock(block)); } return { blocks }; } function prepareFile(ctx) { const blocks = []; for (const fileBlock of ctx.file_block_list()) { const block = fileBlock.block(); const close = fileBlock.CLOSE(); if (block) { blocks.push(prepareBlock(block)); } else if (close) { blocks.push({ text: close.getText() }); } } return { blocks }; } function getTokensStream(text) { const chars = new CharStream(text); const lexer = new bookbox_lexer(chars); const tokens = new CommonTokenStream(lexer); return tokens; } function parse(text) { const tokens = getTokensStream(text); const parser = new bookbox_parser(tokens); const file = parser.file(); return prepareFile(file); } function getTokens(text) { const tokens = getTokensStream(text); return tokens.tokens.map((token) => [token.text, bookbox_lexer.symbolicNames[token.type] ?? ""]); } function stringifyAttr(attr) { const { name, value, empty } = attr; const body = empty ? "" : `{${value}}`; return `.${name}${body}`; } function stringify(body) { return body.blocks.map((block) => { if (block.text) return block.text; if (block.include) return `{{${block.include.value}}}`; if (block.tag) { const { attrList, body: body2, name, separator } = block.tag; const attrs = attrList.map(stringifyAttr).join(""); const tagBody = body2 ? stringify(body2) : ""; return `{${name}${attrs}${separator}${tagBody}}`; } return ""; }).join(""); } async function readMarkup(path) { const { readFile } = await import("node:fs/promises"); const text = await readFile(path, { encoding: "utf-8" }); const ast = parse(text); if (text.includes("#import")) return resolveImports(ast, path); return ast; } async function resolveImports(ast, parentPath) { var _a, _b, _c, _d; const { dirname, resolve } = await import("node:path"); const resultAst = { blocks: [] }; const bodiesPromises = []; let currentBlocks = []; const saveBlocks = () => { if (currentBlocks.length > 0) { bodiesPromises.push({ blocks: currentBlocks }); currentBlocks = []; } }; for (const block of ast.blocks) { const name = (_a = block.tag) == null ? void 0 : _a.name; if (name === "#import") { const childPath = (_c = (_b = block.tag) == null ? void 0 : _b.body) == null ? void 0 : _c.blocks.filter((x) => x.text).map((x) => x.text).join(""); if (!childPath) continue; saveBlocks(); const childAst = readMarkup(resolve(dirname(parentPath), childPath)); bodiesPromises.push(childAst); } else if ((_d = block.tag) == null ? void 0 : _d.body) { saveBlocks(); const tagAst = resolveImports(block.tag.body, parentPath); bodiesPromises.push(tagAst.then((body) => ({ blocks: [{ tag: { ...block.tag, body } }] }))); } else { currentBlocks.push(block); } } saveBlocks(); for (const result of await Promise.allSettled(bodiesPromises)) { if (result.status === "fulfilled") { resultAst.blocks.push(...result.value.blocks); } else { resultAst.blocks.push({ error: { value: "the import cannot be added", message: String(result.reason) } }); } } return resultAst; } export { getTokens, parse, readMarkup, resolveImports, stringify };