A C++ DSL Parsing Assitant Library

Parse Domain Specific Languages in C++

LMX - C++ XML Databinding  LMX  DSL Parsing Assistant  dsl-pa  Annotated XML Extension  AXE  Code Scrapbook  Code Scrapbook   
dsl-pa Overview  Overview   

dsl-pa - A C++ Domain Specific Language Parsing Assistant

dsl-pa is an open source C++ Domain Specific Language Parsing Assistant library designed to take advantage of the C++ logic shortcut operators such as && and ||.

dsl-pa function calls extract sections of language input based on a specified alphabet. Calls to dsl-pa functions are combined using the C++ shortcut operators in order to parse a language in a reasonably compact form. Consequently all dsl-pa functions return either a boolean value or a value that can be implicitly converted to a bool, such as an integer.

The idea is that the set of shortcut operations should mirror the BNF or similar notation (such as ABNF) that is used to describe the langauge being parsed.

Various reader classes can be used to read from file, std::string and memory buffer sources.

dsl-pa's license is based on the BSD-3-Clause license.

For details on how to use dsl-pa, visit dsl-pa's README.md page on github.

To use dsl-pa either download it from github using git, or download the zip file from github.

A simple example of parsing input using dsl-pa is shown below. Further examples are shown on github.

#include "dsl-pa/dsl-pa.h"

#include <iostream>
#include <fstream>

using namespace cl;

void example( std::ostream & fout )
    // What we want to parse
    const char * const to_parse = " width=10, height = 5";

    // Create a reader with the desired input
    reader_string my_reader( to_parse );

    // Create a parser instance specifying the created reader
    dsl_pa pa( my_reader );

    // Create variables to capture parsed data
    size_t width, height;

    // Parse the 'to_parse' string
    if( pa.opt_space() &&
            pa.fixed( "width" ) &&
            pa.opt_space() && pa.is_char( '=' ) && pa.opt_space() &&
            pa.get_uint( &width ) &&
            pa.opt_space() && pa.is_char( ',' ) && pa.opt_space() &&
            pa.fixed( "height" ) &&
            pa.opt_space() && pa.is_char( '=' ) && pa.opt_space() &&
            pa.get_uint( &height ) )
        // Report the results
        fout << "Example 1 OK: w=" << width << " & h=" << height << "\n";
        fout << "Unable to parse input\n";

Copyright © 2003-2024, Codalogic Ltd. All Rights Reserved.