2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-08 17:22:26 +03:00

feat(#271): whitespaceInTags mode (#272)

* 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:
Nikolay Kost
2025-03-09 02:23:03 +02:00
committed by GitHub
parent f0c9da683d
commit 0566241e23
5 changed files with 77 additions and 4 deletions
+9 -4
View File
@@ -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;
+1
View File
@@ -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