Skip to content
Tibor Benke edited this page Oct 3, 2015 · 2 revisions

Grammar

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:

  1. Clone rust-peg into a directory (~/workspace/rust-peg)
  2. 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.

  1. Start a docker container which has access to actiondb's source code and to the peg binary:
docker run -it -v ~/workspace/rust-peg:/source -v ~/workspace/actiondb:/actiondb schickling/rust  /bin/bash
  1. Generate the grammar files with peg:
target/debug/peg /actiondb/src/grammar/parser/pattern.rustpeg >  /actiondb/src/grammar/parser/pattern_parser.rs.IN
  1. Add the F: ParserFactory generic 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.

  1. Rebuild actiondb with cargo
cargo build

Clone this wiki locally