Skip to content

Latest commit

 

History

History
93 lines (71 loc) · 2.55 KB

File metadata and controls

93 lines (71 loc) · 2.55 KB

LibSL Parser C++

A C++ implementation of the LibSL parser for building abstract semantic graphs of library specifications written in LibSL.

Overview

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

Requirements

  • C++23 compatible compiler
  • CMake 3.10+
  • ANTLR4 C++ Runtime
  • ANTLR4 Java Tool (for generating parser code)

Install ANTLR

# 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.sh

The script will:

  • Install necessary dependencies
  • Download the ANTLR JAR file
  • Compile the ANTLR C++ runtime
  • Configure paths in the project

Configure and build

mkdir build && cd build
cmake ..
make -j4

Usage Example

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

Key Components

  • 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