mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-08 17:22:26 +03:00
* fix: test for buggy behavior * feat: implement whitespaceInTags mode * feat: move all char arrays to Map * feat: revert Map for char arrays
This commit is contained in:
@@ -67,7 +67,6 @@ export function createLexer(buffer: string, options: LexerOptions = {}): LexerTo
|
||||
const NOT_CHAR_TOKENS = [
|
||||
openTag, SPACE, TAB, N,
|
||||
];
|
||||
|
||||
const isCharReserved = (char: string) => (RESERVED_CHARS.indexOf(char) >= 0);
|
||||
const isCharToken = (char: string) => (NOT_CHAR_TOKENS.indexOf(char) === -1);
|
||||
const isEscapableChar = (char: string) => (char === openTag || char === closeTag || char === BACKSLASH);
|
||||
@@ -198,13 +197,19 @@ export function createLexer(buffer: string, options: LexerOptions = {}): LexerTo
|
||||
const currChar = chars.getCurr();
|
||||
const nextChar = chars.getNext();
|
||||
|
||||
chars.skip();
|
||||
chars.skip(); // skip openTag
|
||||
|
||||
// detect case where we have '[My word [tag][/tag]' or we have '[My last line word'
|
||||
const substr = chars.substrUntilChar(closeTag);
|
||||
const hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0;
|
||||
|
||||
if ((nextChar && isCharReserved(nextChar)) || hasInvalidChars || chars.isLast()) {
|
||||
|
||||
const hasInvalidChars = substr.length === 0 || substr.indexOf(openTag) >= 0;
|
||||
const isNextCharReserved = nextChar && isCharReserved(nextChar)
|
||||
const isLastChar = chars.isLast()
|
||||
const hasSpace = substr.indexOf(SPACE) >= 0;
|
||||
const isSpaceRestricted = hasSpace && options.whitespaceInTags === false;
|
||||
|
||||
if (isNextCharReserved || hasInvalidChars || isLastChar || isSpaceRestricted) {
|
||||
emitToken(TYPE_WORD, currChar);
|
||||
|
||||
return STATE_WORD;
|
||||
|
||||
@@ -321,6 +321,7 @@ function parse(input: string, opts: ParseOptions = {}) {
|
||||
contextFreeTags: options.contextFreeTags,
|
||||
caseFreeTags: options.caseFreeTags,
|
||||
enableEscapeTags: options.enableEscapeTags,
|
||||
whitespaceInTags: options.whitespaceInTags,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
|
||||
Reference in New Issue
Block a user