Tries to match a given value separated by a given separator.
value
separator
Available since: v1.0.0-alpha.1
v1.0.0-alpha.1
const separatedBy: (separator: Parser) => (value: Parser, name?: string) => Parser;
In this example we are going to parse the string "Hello" separated by a comma.
"Hello"
import { many, separatedBy, string } from "rudus"; const commaSeparated = separatedBy(string(",")); const parser = many(commaSeparated(string("Hello"))); const result = parser.run("Hello,Hello,Hello,");
The result of the parser above will be:
result
{ "input": "Hello,Hello,Hello", "isError": false, "offset": 12, "result": ["Hello", "Hello", "Hello"]}