On March 19, the release of the C++ library Lug, implementing an embedded domain-specific language for expressing parsers in the form of extended syntax expression grammars, and distributed under the MIT license.
Library capabilities:
- Natural syntax reminiscent of external parser generator languages, with support for attributes and semantic actions.
- The ability to work with context-sensitive grammars with symbol tables, conditions, and syntactic predicates.
- The generated parsers are compiled into bytecode and executed in a parser virtual machine.
- Clear separation of syntactic and lexical rules with the ability to configure implicit skipping of whitespace.
- Support for direct and indirect left recursion, with precedence levels to distinguish between sub-expressions with mixed left and right recursions.
- Full support for parsing text in UTF-8 format, including level 1 and partial conformance to level 2 of the technical standard UTS #18 Unicode Regular Expressions.
- Error handling and recovery through marked failures, recovery rules, and error handlers.
- Automatic tracking of line and column numbers, customizable width and tab alignment.
- Header-only library that uses only the standard library and features of the C++17 standard. Promisingly compatible with C++20 and C++23 standards.
- Relatively small library size, aiming to keep the total number of lines across all header files below 6000 lines of concise code.
Change log:
- Collection and object attribute directives have been implemented. The new directive collect[e] synthesizes a sequence or associative container of type C consisting of elements collected from inherited or synthesized attributes in expression e. Similarly, new directives synthesize[e], synthesize_shared[e], and synthesize_unique[e] have been introduced for synthesizing objects, shared pointers, and unique pointers respectively, built from component attributes in expression e.
- The synthesize_collect directive has been implemented, which combines the collect and synthesize directives to enhance code readability and reduce the number of templates when building complex data structures from parsed elements. This is particularly useful for creating nested collections, such as arrays of objects or associative containers with complex value types.
- A template class lug::recursive_wrapper has been added to handle cyclic dependencies in abstract syntax trees, particularly those using std::variant.
- Support for Unicode standard 16.0.0 has been implemented along with build tool support in CMakeLists.txt.
- Range matching and ASCII character set handling have been optimized, resulting in a significant performance increase for commonly used text processing operations. Specialized fast methods for handling only ASCII characters have been added, which are significantly faster than Unicode processing code.
- The test opcodes have been implemented for error optimization, and repeat opcodes for whitespace character skipping optimization. These optimizations will be fully included in the next release after the planned expression tree transformations.
- Input source handling has been improved with enhanced buffering and error reporting for std::istream, as well as improved support for interactive mode that correctly processes line-by-line input for terminal sessions or linear-oriented grammars.
- Support for std::istream has been moved to a separate header file . This reduces compilation time and minimizes header dependencies for projects that do not require stream input/output functionality.
- The parser pinning logic has been redesigned by inlining instructions in lug::basic_parser to better align with the stack frame architecture changes introduced in version 0.4.0, which has improved code organization and performance.
- An issue in the parser example has been fixed. BASIC, when user functions (e.g., FNA(X)) were terminated during evaluation. This was caused by changes in version 0.4.0 that reset lug::environment during nested parsing operations. A new function lug::environment::should_reset_on_parse has been added to provide finer control over this behavior, allowing the environment to be retained during nested parsing operations when necessary.
- Comprehensive testing infrastructure for example programs has been added.
- The include directory hierarchy has been restructured.
- To ensure broader compatibility in GitHub CI, support for additional compilers (GCC 9/10/11/12, Clang 14/15/16/17) has been added.
- Clang and MSVC static analyzers have been added to GitHub CI.
- Address Sanitizer (ASan), Undefined Behavior Sanitizer (UBSan), and Memory Sanitizer (MSan) have been added to GitHub CI.
- Integration of clang-tidy has been added to GitHub CI.
- The use of Ubuntu 20.04 has been removed from GitHub CI.
Source: linux.org.ru
