Generalised rules

Adds RuleGenerators, which allow a more compact (but less efficient) specification of grammar rules for patterns (e.g. numbers, which can match a regular expression).