How idni/parser works
Main Components
• Core Parsing Engine (src): This includes the fundamental modules for defining grammars (e.g., “grammar”, “nonterminals”, “lit”, “prod”) and for performing the parsing process (e.g., “parser”, “parser::result”, “forest”, “traverser”).
• Grammar Construction and Representation: Classes/functions for programmatically constructing grammars, including Boolean, conjunctive, and TGF-related modules.
• TGF Tool (tools/tgf): A command-line interface component dedicated to reading a TGF file, debugging grammars, and generating C++ parser code from the specified grammar.
• CLI & REPL Components (within src such as cli.cpp/repl.h): Modules responsible for managing and processing command-line arguments and interactive sessions.
• Utilities & Helpers (docs/devhelpers.md, src/devhelpers.h): Helper code for forest transformations and additional debugging or transformation functionalities.
• Build & Test Infrastructure: Managed by CMake (CMakeLists.txt in several folders) and a collection of test applications and scripts (e.g., “tests”, “benchmark.sh”, “debug.sh”).
• Examples and Tutorials (examples): A set of usage examples aimed at demonstrating how to create parsers for various tasks (e.g., CSV parsers).
Relationships and Interactions
• The Central Core (Parsing Engine) interacts with the Grammar Construction modules to create a valid grammar structure. This design emphasizes templating and generic programming.
• The Parser module uses the grammar to perform scannerless parsing (i.e., both lexing and parsing without a dedicated lexer).
• The resulting parse forest is then manipulated using traversal and rewriting functions to transform ambiguous parses or to extract trees and graphs.
• The CLI components and the TGF tool serve as user interface layers that interface directly with the underlying parser API. They take input (grammar files or command-line input) and invoke the core engine to perform parsing or code generation.
• External scripts and CMake configuration files orchestrate the build process and potential integration/continuous integration pipelines.
Important Architectural Patterns and Design Principles
• Modularity: There is clear separation between the parser core, tools, tests, and examples. This reflects an intent to keep the core logic reusable.
• Templating and Generic Programming: Most modules are templated so that the parser can work with different character and terminal types (the type parameters “C” and “T”).
• Command-Line Interface Design: The “tgf” tool and CLI functions provide a front-end that makes the library accessible both programmatically and interactively.
• Build and Configuration Management: Usage of CMake provides a consistent build strategy across multiple platforms (including Windows with MinGW-w64, as seen in the cmake configurations).
Technologies, Frameworks, and Libraries
• C++ as the primary programming language.
• CMake for build configuration and dependency management.
• Shell scripts (e.g., build.sh, debug.sh) used for automation.
• No external dependencies are required, which simplifies integration.