parjs
Version:
A parser-combinator library for JavaScript.
28 lines (25 loc) • 739 B
text/typescript
/**
* @module parjs
*/
/** */
import {ParsingState} from "../state";
import {ResultKind} from "../result";
import {Parjser} from "../parjser";
import {ParjserBase} from "../parser";
/**
* Returns a parser that consumes all the rest of the input and yields the
* text that was parsed. Always succeeds.
*/
export function rest(): Parjser<string> {
return new class Rest extends ParjserBase {
expecting = "expecting anything";
type = "rest";
_apply(pr: ParsingState) {
let {position, input} = pr;
let text = input.substr(Math.min(position, input.length));
pr.position = input.length;
pr.value = text;
pr.kind = ResultKind.Ok;
}
}();
}