MCPcopy Create free account
hub / github.com/denoland/std / join

Function join

toml/_parser.ts:268–288  ·  view source on GitHub ↗

Join the parse results of the given parser into an array. * * If the parser fails at the first attempt, it will return an empty array.

(
  parser: ParserComponent<T>,
  separator: string,
)

Source from the content-addressed store, hash-verified

266 * If the parser fails at the first attempt, it will return an empty array.
267 */
268function join<T>(
269 parser: ParserComponent<T>,
270 separator: string,
271): ParserComponent<T[]> {
272 const Separator = character(separator);
273 return (scanner: Scanner): ParseResult<T[]> => {
274 const out: T[] = [];
275 const first = parser(scanner);
276 if (!first.ok) return success(out);
277 out.push(first.body);
278 while (!scanner.eof()) {
279 if (!Separator(scanner).ok) break;
280 const result = parser(scanner);
281 if (!result.ok) {
282 throw new SyntaxError(`Invalid token after "${separator}"`);
283 }
284 out.push(result.body);
285 }
286 return success(out);
287 };
288}
289
290/** Join the parse results of the given parser into an array.
291 *

Callers 1

inlineTableFunction · 0.70

Calls 4

characterFunction · 0.85
successFunction · 0.85
pushMethod · 0.45
eofMethod · 0.45

Tested by

no test coverage detected