From 60c3079f11ac2d6b7d518329762e4ceaf9224383 Mon Sep 17 00:00:00 2001 From: Ferdinand Majerech Date: Thu, 24 Jul 2014 18:42:55 +0200 Subject: [PATCH] Functions to simplify error setting/throwing in Scanner. --- source/dyaml/scanner.d | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index a7731a8..6afcdbd 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -178,6 +178,29 @@ final class Scanner reader_ = null; } + /// If error_ is true, throws a ScannerException constructed from errorData_ and + /// sets error_ to false. + void throwIfError() @safe pure + { + if(!error_) { return; } + error_ = false; + throw new ScannerException(errorData_); + } + + /// Called by internal nothrow/@nogc methods to set an error to be thrown by + /// their callers. + /// + /// See_Also: dyaml.exception.MarkedYamlException + void setError(string context, const Mark contextMark, string problem, + const Mark problemMark) @safe pure nothrow @nogc + { + assert(error_ == false, + "Setting an error when there already is a not yet thrown error"); + error_ = true; + errorData_ = + MarkedYAMLExceptionData(context, contextMark, problem, problemMark); + } + /** * Check if the next token is one of specified types. *