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.
- 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)
- Parsing backend -- currently only Packrat parsing is supported
- Windows and macOS installation is possible but not officially supported
- SCons
- gcc
sudo apt install gcc 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
Hammer provides bindings for use from languages other than C.
Requires SWIG 4.x, Python 3.8+, and setuptools.
sudo apt install swig
scons bindings=pythonSee src/bindings/python/README.md for the full API reference and usage guide.
Requires SWIG 4.x and JDK 11+.
sudo apt install swig default-jdk
scons bindings=javaSee src/bindings/java/README.md for the full API reference and usage guide.
Requires g++ and libgtest-dev (for tests).
sudo apt install libgtest-dev
scons bindings=cppSee src/bindings/cpp/README.md for the full API reference and usage guide.
Requires SWIG 4.x and Go 1.22.2.
sudo apt install swig golang
scons bindings=goSee src/bindings/go/README.md for the full API reference and usage guide.
The examples/ directory contains some simple examples, currently including:
See the example-specific READMEs and the wiki for build and walkthrough details.
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
