/* * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * from https://github.com/dsehnal/CIFTools.js * @author David Sehnal */ type ReaderResult = ReaderResult.Success | ReaderResult.Error namespace ReaderResult { export function error(message: string, line = -1): ReaderResult { return new Error(message, line); } export function success(result: T, warnings: string[] = []): ReaderResult { return new Success(result, warnings); } export class Error { isError: true = true; toString() { if (this.line >= 0) { return `[Line ${this.line}] ${this.message}`; } return this.message; } constructor( public message: string, public line: number) { } } export class Success { isError: false = false; constructor(public result: T, public warnings: string[]) { } } } export { ReaderResult };