- Introduction
- Using the library
- Writing a parser
- Using a parser
- Debugging a parser
- Parsing left recursion grammars
- Writing a tokenizer and parser
- Examples
- Changes
Full code documentation at: ./doc/doxygen/html/index.html.
Parserlib is a c++17 header only library that allows building of recursive-descent parsers using EBNF-like syntax.
Features
- c++17 (tested with msvc and gcc).
- header-only.
- recursive-descent parsing.
- parsing of left-recursive grammars.
- EBNF-like syntax.
- character/custom type parsing.
- extensible via templates.
- multiple error handling.
- ASTs (Abstract Syntax Trees).
- debugging via annotations.
- debugging via inspecting grammar as text.
Version
1.0.0.9
Quick example
The following program implements and uses a calculator parser on strings:
#include "parserlib.hpp"
using namespace parserlib;
extern rule<> expr;
const auto digit = range('0', '9');
const auto number = +digit >> -('.' >> +digit);
rule<> val = number
| '(' >> expr >> ')';
rule<> mul = mul >> '*' >> val
| mul >> '/' >> val
| val;
rule<> add = add >> '+' >> mul
| add >> '-' >> mul
| mul;
rule<> expr = add;
int main() {
std::string input = "1+2/(3*4)";
parse_context<> pc(input);
const bool result = expr.parse(pc);
return 0;
}-
1.0.0.9
- Rewritten again from scratch in order to improve the quality.
- changes:
- renamed some functions in order to make more sense when the code is read.
- improved support for catching errors and continuing.
- more analytical documentation.
- new features:
- better debugging support.
- grammar annotations.
- extensible parse context.
- infinite recursion exception.
- loop breaks.
- compile-time rule optimizations.
-
1.0.0.8
- Rewritten again from scratch, in order to deal with error handling in a much better way,
to make everything
noexceptfor increased performance, to add new capabilities.
- Rewritten again from scratch, in order to deal with error handling in a much better way,
to make everything
-
1.0.0.7
- Rewritten from scratch, to improve quality of the API.
-
1.0.0.6
- Added function-based parsing.
-
1.0.0.5
- Added custom match functions in order to allow the resolution of ambiguities while parsing.
- allowed terminal values to be of different type that the value of the source container, in order to allow the result of a parse (the ast nodes created by a parse) to be fed to another parse function.
- added terminal parsing via functions.
- added parsing via standalone functions.
- added multiple error handling.
-
1.0.0.4
- Rewrote the library:
- all parser grammar classes are now inside a single template class
class parser_engine<SourceT, MatchIdT>, for the following reasons:- compiler performance (MSVC 32-bit regularly crashed with out of memory error from the many template instantiations of previous versions).
- library code organization; writing a grammar usually requires including all the grammar constructs, so it is reduntant to have separate files for each grammar-related class.
- user code organization; whole grammars need to be specialized on source type.
- coding style is closer to the standard: all identifiers are lower case, words are separated by underscores, idiomatic c++ is used whenever possible.
- all parser grammar classes are now inside a single template class
- Rewrote the documentation, due to more functionality to be added in the future.
- Rewrote the library:
-
1.0.0.3
- Reorganized the library in order to support compiler front ends into a separate namespace. The main library is now in
namespace parserlib::core. - Added
namespace parserlib::cfewhich now contains the compiler-front-end functionality. - separated tokenization and parsing phases for compiler-front-ends.
- Added relevant documentation and unit tests.
- Reorganized the library in order to support compiler front ends into a separate namespace. The main library is now in
-
1.0.0.2
- Rewrote the library from scratch in order to provide a better interface. Changes:
- All the getter methods now start with 'get', in order to play better with Intellisense.
- The
ParseContextclass is now configured over the Source type, with the default class being the classSourceString. - The class
SourceStringprovides custom iterator which counts lines and columns, compatible with thestd::stringinterface. - The functions
terminal,terminalSet,terminalRangeare changed toterm,oneOf,oneIn. - Matches are now only hierarchical (as in
operator >=of previous version). - The
'operator >=has been replaced withoperator ->*, which is much more distinct than the former; no more typing accidentally '>>' where>=was intended. - The default match id type is no longer a string; it is an int.
- Simplified the left recursion parsing implementation.
- Rewrote the library from scratch in order to provide a better interface. Changes:
-
1.0.0.1
- Added support for compiler front-end construction.
-
1.0.0.0
- Initial release.