git.dumitru.net fructose / master src / parser / combinators / NamedParser.ts
master

Tree @master (Download .tar.gz)

NamedParser.ts @masterraw · history · blame

import Document from "../../Document";
import DocumentLocation from "../../DocumentLocation";
import Parser from "../Parser";
import ParserError from "../ParserError";
import ParserValue from "../ParserValue";

export default class NamedParser<T> implements Parser<T> {
  public readonly name: string;
  private p: () => Parser<T>;

  constructor(name: string, p: () => Parser<T>) {
    this.name = name;
    this.p = p;
  }

  public parse(doc: Document, loc: DocumentLocation): ParserValue<T> | ParserError {
    const result = this.p().parse(doc, loc);
    return result;
  }
}