Implement rule iterators.

Fixes #154.