Skip to content

Commit

Permalink
Added postprocessing for js imports to avoid clash with c++ import.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed Nov 4, 2023
1 parent 9a4297d commit 090a767
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class InlineExtractor

private:
bool parseInlineDirective(std::string const& line, Section& section) const;
void postProcessImports(std::string& line);

private:
SectionCache sectionCache_;
Expand Down
9 changes: 9 additions & 0 deletions tools/inline_parser/src/inline_parser/inline_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <thread>

#include <iostream>
#include <regex>

namespace
{
Expand Down Expand Up @@ -123,6 +124,13 @@ bool InlineExtractor::parseInlineDirective(std::string const& line, Section& sec
return true;
}

void InlineExtractor::postProcessImports(std::string& line)
{
std::regex pattern(R"(^\s*js_import)");
std::string replacement = "import";
line = std::regex_replace(line, pattern, replacement);
}

void InlineExtractor::parseFileForSections(std::filesystem::path const& path)
{
std::ifstream reader{path, std::ios_base::binary};
Expand All @@ -148,6 +156,7 @@ void InlineExtractor::parseFileForSections(std::filesystem::path const& path)
{
line.resize(line.size() + 1);
line.back() = '\n';
postProcessImports(line);
currentSection.content.append(std::move(line));
}
};
Expand Down

0 comments on commit 090a767

Please sign in to comment.