A C++ implementation of the LibSL parser for building abstract semantic graphs of library specifications written in LibSL.
This library provides tools for parsing LibSL (Library Specification Language) files and building an abstract semantic graph (ASG) representing the library description. It allows you to:
- Parse LibSL files into memory
- Navigate and query the resulting data structures
- Modify the ASG programmatically
- Serialize the ASG back to LibSL format
- C++23 compatible compiler
- CMake 3.10+
- ANTLR4 C++ Runtime
- ANTLR4 Java Tool (for generating parser code)
# Clone the repository
git clone https://github.com/bubelovv/libsl-parser-cpp.git
cd libsl-parser-cpp
To install ANTLR, use the provided script:
# Make the script executable
chmod +x scripts/install_antlr.sh
# Run the installation script
./scripts/install_antlr.shThe script will:
- Install necessary dependencies
- Download the ANTLR JAR file
- Compile the ANTLR C++ runtime
- Configure paths in the project
mkdir build && cd build
cmake ..
make -j4#include <iostream>
#include "libsl/libsl.h"
int main() {
// Initialize the parser
libsl::LibSL parser("/path/to/library/files");
// Parse a LibSL file
try {
auto library = parser.loadFromFile("/path/to/library.lsl");
// Access library metadata
std::cout << "Library name: " << library->getMetadata()->getName() << std::endl;
std::cout << "LibSL version: " << library->getMetadata()->getStringVersion() << std::endl;
// Check for errors
if (parser.getErrorManager()->hasErrors()) {
std::cout << "Errors found during parsing:" << std::endl;
for (const auto& error : parser.getErrorManager()->getErrors()) {
std::cout << error.getFormattedMessage() << std::endl;
}
}
}
catch (const std::exception& e) {
std::cerr << "Error parsing file: " << e.what() << std::endl;
return 1;
}
return 0;
}- LibSL: Main class for parsing and working with LibSL files
- Library: Represents a parsed LibSL library with its declarations
- Type System: Classes for working with LibSL types
- Automaton: Classes representing automata defined in LibSL
- Context Management: Classes for name resolution and scoping
- Visitors: Classes for traversing the ASG
- Error Handling: Classes for managing parsing errors and warnings