def generate_all_commands(self, exclude_templates=None):
    """Generate all commands but allow excluding unused templates."""

    # Generate all possible templates from the grammar.
    initial_template = grammar.Template()
    initial_template.add_value(value=ROOT, expandable=True)
    self.generate_all(
        current_template=initial_template,
        all_templates=self.all_templates,
        rule_use_counter={})
    # Remove duplicate templates due to ambiguous PP attachment.
    self.remove_duplicate_templates()
    if exclude_templates:
      self.remove_exclude_templates(exclude_templates)
    # For each template, form all possible commands
    # by combining it with the lexicon.
    for i, (derivation_template,
            derivation_rules) in enumerate(self.all_templates):
      derivations = self.form_commands_from_template(derivation_template,
                                                     derivation_rules)
      self.all_derivations[i] = derivations
Generate all commands but allow excluding unused templates.
language/gscan/data/grammar.py