Hammer is a parsing library. Like many modern parsing libraries, it provides a parser combinator interface for writing grammars as inline domain-specific languages, but Hammer also provides a variety of parsing backends. It's also bit-oriented rather than character-oriented, making it ideal for parsing binary data such as images, network packets, audio, and executables.
Hammer is written in C and provides a packrat parsing backend.
MicroHammer is a slimmed-down version of Hammer with the goal of providing a lightweight, Linux-focused version of Hammer with a minimal, clean codebase. Link to public release.
The main feature of MicroHammer is its significantly smaller codebase, allowing for easier maintenance and onboarding. Key differences from the full Hammer library include:
- Linux-focused development and deployment
- More thorough and consistent documentation
- Windows / macOS not supported
- Packrat parsing backend only
- No bindings for other languages
- Bit-oriented -- grammars can include single-bit flags or multi-bit constructs that span character boundaries, with no hassle
- Thread-safe, reentrant (for most purposes; see Known Issues for details)
- Benchmarking for parsing backends -- determine empirically which backend will be most time-efficient for your grammar
- Parsing backends: -- currently only Packrat parsing is supported
sudo apt install scons- pkg-config
- glib-2.0-dev
sudo apt install pkg-config libglib2.0-devTo build, type scons.
To run the built-in test suite, type scons test.
To avoid the test dependencies, add --no-tests.
For a debug build, add --variant=debug.
To make Hammer available system-wide, use scons install. This places include files in /usr/local/include/hammer and library files in /usr/local/lib by default; to install elsewhere, add a prefix=<destination> argument, e.g. scons install prefix=$HOME.
To remove installed files, use scons uninstall (with the same prefix if non-default).
To check which variant and version of Hammer is currently installed:
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig pkg-config --variable=variant libhammer
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig pkg-config --modversion libhammerJust #include <hammer/hammer.h> (also #include <hammer/glue.h> if you plan to use any of the convenience macros) and link with -lhammer.
If you've installed Hammer system-wide, you can use pkg-config in the usual way.
To learn about hammer, check:
- the user guide
- Hammer Primer (outdated in terms of code, but good to get the general thinking)
- Try Hammer
The examples/ directory contains some simple examples, currently including:
For information on contributing to Hammer, including development setup, code formatting guidelines, and documentation generation, please see DEVELOPMENT.md.
Send an email to parsing@riversideresearch.org
This material is based upon work supported by the Defense Advanced Research Projects Agency (DARPA) under Prime Contract No. HR001119C0077. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the Defense Advanced Research Projects Agency (DARPA).
This work is a fork of the repository found at: https://gitlab.special-circumstanc.es/hammer/hammer
Distribution A: Approved for Public Release
