We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sepBy1
possibly
Following code (with sepBy1 wrapped as needed to workaround #109):
import { optionalWhitespace, Parser, possibly, sepBy1 as _sepBy1, sequenceOf, str, whitespace } from "arcsecond"; const sepBy1 = <S, T>(sep: Parser<S>, value: Parser<T>) => _sepBy1(sep)(value) as Parser<T[]>; const b = str("b") const c = str("c") const a1 = sequenceOf([ str("a"), possibly(sequenceOf([whitespace, b])), possibly(sequenceOf([whitespace, c]))]) const a2 = sequenceOf([ str("a"), possibly(sequenceOf([whitespace, sepBy1(optionalWhitespace, b)])), possibly(sequenceOf([whitespace, sepBy1(optionalWhitespace, c)]))]) export const parse1 = (input: string) => a1.run(input); export const parse2 = (input: string) => a2.run(input);
parses the string "a b c" in the a1 variant, but not in the a2 variant:
"a b c"
a1
a2
❯ pnpm build > [email protected] build [REDACTED]/arcsecond-repro3 > tsc -p . ❯ node Welcome to Node.js v18.17.1. Type ".help" for more information. > p = await import("./dist/parser.js?v1") [Module: null prototype] { parse1: [Function: parse1], parse2: [Function: parse2] } > p.parse1("a b c") { isError: false, result: [ 'a', [ ' ', 'b' ], [ ' ', 'c' ] ], index: 5, data: null } > p.parse2("a b c") { isError: false, result: [ 'a', null, null ], index: 1, data: null }
Please find a complete example in https://github.com/devurandom/arcsecond-issue-111-repro.
The text was updated successfully, but these errors were encountered:
I found an implementation of sepBy1 that works:
import { coroutine, either, lookAhead, Parser, sequenceOf, } from "arcsecond"; const sepBy1 = <T>(sep: Parser<string>, val: Parser<T>) => coroutine((run) => { const results: T[] = [run(val)]; const next = sequenceOf([sep, val]) while (!run(either(lookAhead(next))).isError) { const [_, value] = run(next); results.push(value); } return results; });
Sorry, something went wrong.
No branches or pull requests
Following code (with
sepBy1
wrapped as needed to workaround #109):parses the string
"a b c"
in thea1
variant, but not in thea2
variant:Please find a complete example in https://github.com/devurandom/arcsecond-issue-111-repro.
The text was updated successfully, but these errors were encountered: