Skip to content

Tolc-Software/Parser

Repository files navigation

Ubuntu MacOS Windows Windows-debug-deploy

Parser

Parser is the library for converting a header file of C++ to the intermediate representation declared in the library IR::IR.

Installation

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.

Usage

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';
    }
}