diff --git a/source/dyaml/loader.d b/source/dyaml/loader.d index 7e7096c..09c19db 100644 --- a/source/dyaml/loader.d +++ b/source/dyaml/loader.d @@ -165,6 +165,7 @@ struct Loader void name(string name) pure @safe nothrow @nogc { name_ = name; + scanner_.name = name; } /// Specify custom Resolver to use. @@ -392,3 +393,19 @@ struct Loader auto doc = Loader.fromString(yaml).load(); assert(doc.isValid); } + +@safe unittest +{ + import std.exception : collectException; + + auto yaml = q"EOS + value: invalid: string +EOS"; + auto filename = "invalid.yml"; + auto loader = Loader.fromString(yaml); + loader.name = filename; + + Node unused; + auto e = loader.load().collectException!ScannerException(unused); + assert(e.mark.name == filename); +} diff --git a/source/dyaml/reader.d b/source/dyaml/reader.d index 9fe42fc..ae44c80 100644 --- a/source/dyaml/reader.d +++ b/source/dyaml/reader.d @@ -405,6 +405,9 @@ final class Reader /// Get file name. string name() const @safe pure nothrow @nogc { return name_; } + /// Set file name. + void name(string name) pure @safe nothrow @nogc { name_ = name; } + /// Get current line number. uint line() const @safe pure nothrow @nogc { return line_; } diff --git a/source/dyaml/scanner.d b/source/dyaml/scanner.d index 2009521..3f0f394 100644 --- a/source/dyaml/scanner.d +++ b/source/dyaml/scanner.d @@ -185,6 +185,12 @@ struct Scanner return tokens_.empty; } + /// Set file name. + void name(string name) @safe pure nothrow @nogc + { + reader_.name = name; + } + private: /// Most scanning error messages have the same format; so build them with this /// function.