Consider the following code sample:
export const fnName1 = P.matchWhile((c) => c === 'S' || c === 'U' || c === 'M');
export const fnName2 = P.str('SUM');
export const fnName3 = P.pipe<CU.CharStream[], CU.CharStream>(P.many1(P.letter))(CU.CharStream.concat);
// Test with full execution
const nameAndParen = P.left<CU.CharStream, CU.CharStream>(fnName1)(P.char('('));
const parser = P.seq(nameAndParen)(P.eof);
const input = new CU.CharStream('SUM(');
console.log('initial hasEOF', input.hasEOF);
const nameTest = parser(input);
let result = nameTest.next();
if (result.done) {
console.log('final', result.value);
}
When using fnName1, the parse fails because it doesn't reach EOF. When using fnName2 or fnName3 it succeeds.
Is this an incorrect way to match?
Consider the following code sample:
When using
fnName1, the parse fails because it doesn't reach EOF. When usingfnName2orfnName3it succeeds.Is this an incorrect way to match?