diff --git a/cpp.cpp b/cpp.cpp index d520e782..8804c826 100644 --- a/cpp.cpp +++ b/cpp.cpp @@ -39,12 +39,16 @@ processor::add (std::string token, std::unique_ptr handler) void processor::process (std::ostream &os, const std::filesystem::path &src) const { - const auto data = cruft::slurp (src); + auto data = cruft::slurp (src); context ctx; ctx.source.push (src); + // Workaround to prevent an empty trailing line after line splitting + if (!data.empty () and data.back () == '\n') + data.pop_back (); + cruft::tokeniser tok (data, '\n'); - process (os, ctx, cruft::view (tok.begin (), tok.end ())); + process (os, ctx, cruft::view (tok)); } @@ -68,7 +72,6 @@ processor::process ( if (equal (*head, "#endif")) return l; - if (equal (*head, "#define")) { auto key = head; ++key; @@ -150,7 +153,10 @@ include::process (std::ostream &os, std::filesystem::path fragment { name.begin (), name.end () }; const auto target = ctx.source.top ().parent_path () / fragment; - const auto data = cruft::slurp (target); + auto data = cruft::slurp (target); + + if (!data.empty () and data.back () == '\n') + data.pop_back (); ctx.source.push (target); cruft::tokeniser tok (data, '\n');