diff --git a/src/__tests__/combinators/sepBy.spec.ts b/src/__tests__/combinators/sepBy.spec.ts index ca348b9..5893e1c 100644 --- a/src/__tests__/combinators/sepBy.spec.ts +++ b/src/__tests__/combinators/sepBy.spec.ts @@ -1,4 +1,4 @@ -import { sepBy, sepBy1 } from '@combinators' +import { sepBy, sepBy1, sequence } from '@combinators' import { string } from '@parsers' import { run, result, should, describe, it } from '@testing' @@ -26,6 +26,14 @@ describe('sepBy', () => { should.matchState(actual, expected) }) + + it('should successfully continue if nothing matched', () => { + const parser = sequence(sepBy(string('hello'), string('?')), sepBy(string('bye'), string('?'))) + const actual = run(parser, 'bye?bye?') + const expected = result(true, [[], ['bye', 'bye']]) + + should.matchState(actual, expected) + }) }) describe('sepBy1', () => { diff --git a/src/combinators/sepBy.ts b/src/combinators/sepBy.ts index 51b81b1..7de3ab7 100644 --- a/src/combinators/sepBy.ts +++ b/src/combinators/sepBy.ts @@ -37,8 +37,8 @@ export function sepBy(parser: Parser, sep: Parser): Parser> return { isOk: true, - span: [pos, resultP.pos], - pos: resultP.pos, + span: [pos, pos], + pos, value: [] } }