MCPcopy Index your code
hub / github.com/TruthHun/BookStack / parseStringGroup

Method parseStringGroup

static/katex/katex.mjs:15424–15475  ·  view source on GitHub ↗

* Parses a group, essentially returning the string formed by the * brace-enclosed tokens plus some position information.

(modeName, // Used to describe the mode in error messages.
  optional, raw)

Source from the content-addressed store, hash-verified

15422
15423
15424 parseStringGroup(modeName, // Used to describe the mode in error messages.
15425 optional, raw) {
15426 const groupBegin = optional ? "[" : "{";
15427 const groupEnd = optional ? "]" : "}";
15428 const nextToken = this.nextToken;
15429
15430 if (nextToken.text !== groupBegin) {
15431 if (optional) {
15432 return null;
15433 } else if (raw && nextToken.text !== "EOF" && /[^{}[\]]/.test(nextToken.text)) {
15434 // allow a single character in raw string group
15435 this.gullet.lexer.setCatcode("%", 14); // reset the catcode of %
15436
15437 this.consume();
15438 return nextToken;
15439 }
15440 }
15441
15442 const outerMode = this.mode;
15443 this.mode = "text";
15444 this.expect(groupBegin);
15445 let str = "";
15446 const firstToken = this.nextToken;
15447 let nested = 0; // allow nested braces in raw string group
15448
15449 let lastToken = firstToken;
15450
15451 while (raw && nested > 0 || this.nextToken.text !== groupEnd) {
15452 switch (this.nextToken.text) {
15453 case "EOF":
15454 throw new ParseError("Unexpected end of input in " + modeName, firstToken.range(lastToken, str));
15455
15456 case groupBegin:
15457 nested++;
15458 break;
15459
15460 case groupEnd:
15461 nested--;
15462 break;
15463 }
15464
15465 lastToken = this.nextToken;
15466 str += lastToken.text;
15467 this.consume();
15468 }
15469
15470 this.mode = outerMode;
15471 this.gullet.lexer.setCatcode("%", 14); // reset the catcode of %
15472
15473 this.expect(groupEnd);
15474 return firstToken.range(lastToken, str);
15475 }
15476 /**
15477 * Parses a regex-delimited group: the largest sequence of tokens
15478 * whose concatenated strings match `regex`. Returns the string

Callers 6

parseGroupOfTypeMethod · 0.95
parseColorGroupMethod · 0.95
parseSizeGroupMethod · 0.95
parseUrlGroupMethod · 0.95
katex.jsFile · 0.80
katex.min.jsFile · 0.80

Calls 4

consumeMethod · 0.95
expectMethod · 0.95
setCatcodeMethod · 0.80
rangeMethod · 0.45

Tested by

no test coverage detected