cpp: fix trailing tokens with new tokeniser
This commit is contained in:
parent
458f109c6f
commit
642d9b95c6
14
cpp.cpp
14
cpp.cpp
@ -39,12 +39,16 @@ processor::add (std::string token, std::unique_ptr<directive> handler)
|
|||||||
void
|
void
|
||||||
processor::process (std::ostream &os, const std::filesystem::path &src) const
|
processor::process (std::ostream &os, const std::filesystem::path &src) const
|
||||||
{
|
{
|
||||||
const auto data = cruft::slurp<char> (src);
|
auto data = cruft::slurp<char> (src);
|
||||||
context ctx;
|
context ctx;
|
||||||
ctx.source.push (src);
|
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<const char*> tok (data, '\n');
|
cruft::tokeniser<const char*> 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"))
|
if (equal (*head, "#endif"))
|
||||||
return l;
|
return l;
|
||||||
|
|
||||||
|
|
||||||
if (equal (*head, "#define")) {
|
if (equal (*head, "#define")) {
|
||||||
auto key = head;
|
auto key = head;
|
||||||
++key;
|
++key;
|
||||||
@ -150,7 +153,10 @@ include::process (std::ostream &os,
|
|||||||
std::filesystem::path fragment { name.begin (), name.end () };
|
std::filesystem::path fragment { name.begin (), name.end () };
|
||||||
|
|
||||||
const auto target = ctx.source.top ().parent_path () / fragment;
|
const auto target = ctx.source.top ().parent_path () / fragment;
|
||||||
const auto data = cruft::slurp<char> (target);
|
auto data = cruft::slurp<char> (target);
|
||||||
|
|
||||||
|
if (!data.empty () and data.back () == '\n')
|
||||||
|
data.pop_back ();
|
||||||
|
|
||||||
ctx.source.push (target);
|
ctx.source.push (target);
|
||||||
cruft::tokeniser<const char*> tok (data, '\n');
|
cruft::tokeniser<const char*> tok (data, '\n');
|
||||||
|
Loading…
Reference in New Issue
Block a user