-
Notifications
You must be signed in to change notification settings - Fork 5
Grammar
Tibor Benke edited this page Oct 3, 2015
·
2 revisions
The grammar is generated by the awesome rust-peg crate. Unfortunately it's
compatible only with nightly Rust and we stick to stable, so we need
a way to generate the grammar.
You can use multirust or a Docker container to generate the grammar files.
Here are the steps for using containsers:
- Clone
rust-peginto a directory (~/workspace/rust-peg) - Start a docker container wich has the current nightly Rust installed
docker run --rm -it -v ~/workspace/rust-peg:/source schickling/rust
cargo build
This will build the crate and produce a peg binary under
/source/target/debug. This peg binary reads a grammar definition from a
file and prints to the stdout the generated Rust code.
- Start a docker container which has access to
actiondb's source code and to thepegbinary:
docker run -it -v ~/workspace/rust-peg:/source -v ~/workspace/actiondb:/actiondb schickling/rust /bin/bash
- Generate the grammar files with
peg:
target/debug/peg /actiondb/src/grammar/parser/pattern.rustpeg > /actiondb/src/grammar/parser/pattern_parser.rs.IN
- Add the
F: ParserFactorygeneric type parameters before every functions:
rm -f pattern_parser.rs; cat pattern_parser.rs.IN | sed "s/\(fn [a-zA-Z0-9_]*<'input\)/\1, F: ParserFactory/" | sed "s/\(parse[a-zA-Z0-9_]*\)(/\1::<F>(/" >> pattern_parser.rs
The first sed adds the F: ParserFactory generic type parameter to every function definition.
The second sed threads this F parameter through the call sites as well.
- Rebuild
actiondbwithcargo
cargo build