git.dumitru.net fructose / master src / tests / utils.ts
master

Tree @master (Download .tar.gz)

utils.ts @masterraw · history · blame

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

export function doc(text: string): Document {
  return new Document(text.split("\n"));
}

export function loc(line: number, char: number): DocumentLocation {
  return new DocumentLocation(line, char);
}

export function val<T>(value: T, location: DocumentLocation): ParserValue<T> {
  return new ParserValue(value, location);
}

export function err(reason: string, location: DocumentLocation, parentError: ParserError | null): ParserError {
  return new ParserError(reason, location, parentError);
}