Skip to content

SimpleRegex/SRL-CPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SRL-CPP

This is a header-only C++ libary for Simple Regex Language.

Currently under development.

Usage

You only need to include the library directory and use C++ 14 standard to compile. The namespace used is spre::.

The library uses C++ 11 features heavily, and uses make_unique from C++ 14. You could use latest Visual Studio, or g++-4.9 or later, or clang++-3.8 or later. The project uses cmake as the builing system.

// test.cpp
#include <string>
#include <iostream>
#include <spre/spre.hpp>
int main()
{
    std::string src = "literally \"something\"";
    spre::SRL srl(src);
    std::cout << srl.get_pattern() << std::endl;
    return 0;
}
$ tree .
.
|-- test.cpp
`-- include
    `-- spre
        |-- ast.hpp
        |-- ...
        ...

$ g++ -I./include -std=c++14 test.cpp
$ ./test
(?:something)

License

MIT.

Limitations and TODOs

  • The Builder is yet to be implemented.
  • The error reports are implemented as outputing to stderr.

Technical Structures

First of all, it's designed to be a header-only library. Thus everything are written in the header files (.hpp). Ideally users only need to #include <spre/spre.hpp>.

The library is written as a light-weight compiler-like thing, although SRL is a DSL and does not have control flow (as a subset of Regex) thus could not be considered turing-complete. As a result, this library has lexer and parser and code generator. This library has specific lexer instead of using yacc. The code is written following the tutorials from llvm and @frozengene.

The structure:

token.hpp
  |
  V
dictionary.hpp         ast.hpp
  |                       |  
  V                       V
lexer.hpp  ---------> parser.hpp --------> generator.hpp
(get tokens)  (get (vector of) asts) (get the compiled regex string)
                                             |
                                             V
                                          spre.hpp
                                        (`SRL` and `Builder`)

Releases

No releases published

Packages

No packages published