var type;function ret(t,e){return type=e,t}function tokenBase(t,e){var n=t.next();if("<"!=n||!t.eat("!")){if("<"==n&&t.eat("?"))return e.tokenize=inBlock("meta","?>"),ret("meta",n);if("#"==n&&t.eatWhile(/[\w]/))return ret("atom","tag");if("|"==n)return ret("keyword","separator");if(n.match(/[\(\)\[\]\-\.,\+\?>]/))return ret(null,n);if(n.match(/[\[\]]/))return ret("rule",n);if('"'==n||"'"==n)return e.tokenize=tokenString(n),e.tokenize(t,e);if(t.eatWhile(/[a-zA-Z\?\+\d]/)){var r=t.current();return null!==r.substr(r.length-1,r.length).match(/\?|\+/)&&t.backUp(1),ret("tag","tag")}return "%"==n||"*"==n?ret("number","number"):(t.eatWhile(/[\w\\\-_%.{,]/),ret(null,null))}return t.eatWhile(/[\-]/)?(e.tokenize=tokenSGMLComment,tokenSGMLComment(t,e)):t.eatWhile(/[\w]/)?ret("keyword","doindent"):void 0}function tokenSGMLComment(t,e){for(var n,r=0;null!=(n=t.next());){if(r>=2&&">"==n){e.tokenize=tokenBase;break}r="-"==n?r+1:0;}return ret("comment","comment")}function tokenString(t){return function(e,n){for(var r,a=!1;null!=(r=e.next());){if(r==t&&!a){n.tokenize=tokenBase;break}a=!a&&"\\"==r;}return ret("string","tag")}}function inBlock(t,e){return function(n,r){for(;!n.eol();){if(n.match(e)){r.tokenize=tokenBase;break}n.next();}return t}}const dtd={startState:function(){return {tokenize:tokenBase,baseIndent:0,stack:[]}},token:function(t,e){if(t.eatSpace())return null;var n=e.tokenize(t,e),r=e.stack[e.stack.length-1];return "["==t.current()||"doindent"===type||"["==type?e.stack.push("rule"):"endtag"===type?e.stack[e.stack.length-1]="endtag":"]"==t.current()||"]"==type||">"==type&&"rule"==r?e.stack.pop():"["==type&&e.stack.push("["),n},indent:function(t,e,n){var r=t.stack.length;return "]"===e.charAt(0)?r--:">"===e.substr(e.length-1,e.length)&&("<"===e.substr(0,1)||"doindent"==type&&e.length>1||("doindent"==type?r--:">"==type&&e.length>1||"tag"==type&&">"!==e||("tag"==type&&"rule"==t.stack[t.stack.length-1]?r--:"tag"==type?r++:">"===e&&"rule"==t.stack[t.stack.length-1]&&">"===type?r--:">"===e&&"rule"==t.stack[t.stack.length-1]||("<"!==e.substr(0,1)&&">"===e.substr(0,1)?r-=1:">"===e||(r-=1)))),null!=type&&"]"!=type||r--),t.baseIndent+r*n.unit},languageData:{indentOnInput:/^\s*[\]>]$/}};

export { dtd };
