hammer/README.md

90 lines
4.5 KiB
Markdown
Raw Permalink Normal View History

2012-11-11 02:28:07 -05:00
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, but will provide bindings for other languages. If you don't see a language you're interested in on the list, just ask.
2013-10-18 03:26:27 -07:00
Hammer currently builds under Linux and OS X. (Windows is coming.)
2012-11-11 02:28:07 -05:00
2013-07-11 17:39:53 -07:00
[![Build Status](https://travis-ci.org/UpstandingHackers/hammer.png)](https://travis-ci.org/UpstandingHackers/hammer)
2012-11-11 02:28:07 -05:00
Features
========
* Bit-oriented -- grammars can include single-bit flags or multi-bit constructs that span character boundaries, with no hassle
* Thread-safe, reentrant
2012-11-13 21:50:48 -05:00
* Benchmarking for parsing backends -- determine empirically which backend will be most time-efficient for your grammar
2012-11-11 02:28:07 -05:00
* Parsing backends:
* Packrat parsing
* LL(k)
* GLR
* LALR
* Regular expressions
* Language bindings:
2014-01-16 21:14:15 +01:00
* C++
2013-11-26 16:27:28 -08:00
* Java (not currently building; give us a few days)
* Python
2014-01-16 21:14:15 +01:00
* Ruby
2013-12-06 10:19:56 +01:00
* Perl
2013-12-02 15:40:56 -08:00
* [Go](https://github.com/prevoty/hammer)
2013-12-22 09:48:24 -08:00
* PHP
2014-01-05 02:07:14 +01:00
* .NET
2012-11-11 02:28:07 -05:00
Installing
==========
2012-11-11 02:29:34 -05:00
### Prerequisites
2016-08-11 22:48:18 +02:00
* [SCons](http://scons.org/)
2012-11-11 02:28:07 -05:00
2012-11-13 21:50:48 -05:00
### Optional Dependencies
2013-12-06 10:19:56 +01:00
* pkg-config (for `scons test`)
* glib-2.0 (>= 2.29) (for `scons test`)
* glib-2.0-dev (for `scons test`)
2019-05-10 22:08:41 +01:00
* [swig](http://swig.org/) (for Python/Perl/PHP bindings; Perl requires >= 2.0.8; Python 3.x requires >= 3.0.0)
* python2.7-dev (for Python 2 bindings)
* python3-dev (>= 3.5) (for Python 3 bindings)
2013-12-06 10:19:56 +01:00
* a JDK (for Java bindings)
2013-12-22 09:48:24 -08:00
* a working [phpenv](https://github.com/CHH/phpenv) configuration (for PHP bindings)
2016-08-11 22:50:20 +02:00
* [Ruby](https://www.ruby-lang.org/) >= 1.9.3 and bundler, for the Ruby bindings
2014-01-05 02:07:14 +01:00
* mono-devel and mono-mcs (>= 3.0.6) (for .NET bindings)
2016-08-11 22:55:43 +02:00
* [nunit](http://www.nunit.org/) (for testing .NET bindings)
2012-11-13 21:50:48 -05:00
2014-01-05 02:07:14 +01:00
To build, type `scons`. To run the built-in test suite, type `scons test`. For a debug build, add `--variant=debug`.
2012-11-11 02:28:07 -05:00
2013-12-06 10:19:56 +01:00
To build bindings, pass a "bindings" argument to scons, e.g. `scons bindings=python`. `scons bindings=python test` will build Python bindings and run tests for both C and Python. `--variant=debug` is valid here too. You can build more than one set of bindings at a time; just separate them with commas, e.g. `scons bindings=python,perl`.
2013-11-26 16:27:28 -08:00
For Java, if jni.h and jni_md.h aren't already somewhere on your include path, prepend
2013-07-10 21:32:05 +02:00
`C_INCLUDE_PATH=/path/to/jdk/include` to that.
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.
2013-11-28 22:41:02 -08:00
`scons install prefix=$HOME`. A suitable `bindings=` argument will install bindings in whatever place your system thinks is appropriate.
2012-11-11 02:28:07 -05:00
Usage
=====
2013-11-26 16:27:28 -08:00
Just `#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.
2012-11-11 02:28:07 -05:00
2016-07-30 13:02:32 +00:00
To learn about hammer check
* the [user guide](https://github.com/UpstandingHackers/hammer/wiki/User-guide)
2016-08-01 12:54:13 +00:00
* [Hammer Primer](https://github.com/sergeybratus/HammerPrimer) (outdated in terms of code, but good to get the general thinking)
2016-07-30 13:02:32 +00:00
* [Try Hammer](https://github.com/sboesen/TryHammer)
2014-11-30 19:23:29 -05:00
2012-11-11 02:28:07 -05:00
Examples
========
The `examples/` directory contains some simple examples, currently including:
2016-08-11 23:59:59 +02:00
* [base64](https://en.wikipedia.org/wiki/Base64)
* [DNS](https://en.wikipedia.org/wiki/Domain_Name_System)
2013-02-17 19:57:12 -05:00
2013-11-26 16:29:30 -08:00
Known Issues
============
2019-05-10 22:08:41 +01:00
The Python bindings work with Python 2.7, and Python 3.5+.
2013-11-26 16:29:30 -08:00
2013-12-06 10:19:56 +01:00
The requirement for SWIG >= 2.0.8 for Perl bindings is due to a [known bug](http://sourceforge.net/p/swig/patches/324/) in SWIG. [ppa:dns/irc](https://launchpad.net/~dns/+archive/irc) has backports of SWIG 2.0.8 for Ubuntu versions 10.04-12.10; you can also [build SWIG from source](http://www.swig.org/download.html).
2014-01-05 02:07:14 +01:00
The .NET bindings are for Mono 3.0.6 and greater. If you're on a Debian-based distro that only provides Mono 2 (e.g., Ubuntu 12.04), there are backports for [3.0.x](http://www.meebey.net/posts/mono_3.0_preview_debian_ubuntu_packages/), and a [3.2.x PPA](https://launchpad.net/~directhex/+archive/monoxide) maintained by the Mono team.
2013-02-17 19:57:12 -05:00
Community
=========
2013-02-18 20:03:19 -05:00
Please join us at `#hammer` on `irc.upstandinghackers.com` if you have any questions or just want to talk about parsing.
Contact
=======
You can also email us at <hammer@upstandinghackers.com>.