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

Function join1

toml/_parser.ts:294–313  ·  view source on GitHub ↗

Join the parse results of the given parser into an array. * * This requires the parser to succeed at least once.

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

Source from the content-addressed store, hash-verified

292 * This requires the parser to succeed at least once.
293 */
294function join1<T>(
295 parser: ParserComponent<T>,
296 separator: string,
297): ParserComponent<T[]> {
298 const Separator = character(separator);
299 return (scanner: Scanner): ParseResult<T[]> => {
300 const first = parser(scanner);
301 if (!first.ok) return failure();
302 const out: T[] = [first.body];
303 while (!scanner.eof()) {
304 if (!Separator(scanner).ok) break;
305 const result = parser(scanner);
306 if (!result.ok) {
307 throw new SyntaxError(`Invalid token after "${separator}"`);
308 }
309 out.push(result.body);
310 }
311 return success(out);
312 };
313}
314
315function kv<T>(
316 keyParser: ParserComponent<string[]>,

Callers 1

_parser.tsFile · 0.85

Calls 5

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

Tested by

no test coverage detected