Parser is the library for converting a header file of C++
to the intermediate representation declared in the library IR::IR
.
Use FetchContent
in your CMakeLists.txt
as follows:
include(FetchContent)
FetchContent_Declare(
Parser
GIT_REPOSITORY git@github.com:Tolc-Software/Parser.git
GIT_TAG main)
# Downloads and makes the parser library available
FetchContent_MakeAvailable(Parser)
# Link it to your target
target_link_libraries(your_target PRIVATE Tolc::Parser)
And you should get all the necessary components of the library.
Parser
exposes the header file Parser/Parse.h
, which can be used as:
#include <Parser/Parse.hpp>
#include <iostream>
int main() {
// Returns a std::optional<IR::Namespace>
auto maybeParsed = Parser::parseString(R"(
int f() {
return 5;
}
)");
if (maybeParsed) {
auto& globalNamespace = maybeParsed.value();
// Will return "f"
std::cout << globalNamespace.m_functions[0].m_name << '\n';
}
}