Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. from dragonfly import *
  2. class CommandRule(MappingRule):
  3. mapping = {
  4. "amp": Key("a"),
  5. "bairch": Key("b"),
  6. "lanty [<n>]": Key("left"),
  7.  
  8. }
  9. extras = [IntegerRef("n", 1, 10)]
  10. defaults = {"n":1}
  11. command_rule = CommandRule()
  12.  
  13. cmd_sequence = Repetition(RuleRef(command_rule), min=1, max=10, name="cmd_sequence")
  14. class SequenceRule2(CompoundRule):
  15. spec = "<cmd_sequence>"
  16. extras = [cmd_sequence]
  17. def _process_recognition(self, node, extras):
  18. for action in extras["cmd_sequence"]:
  19. print(action)
  20. action.execute()
  21.  
  22. homemade_ccr_grammar = Grammar("random_name_for_homemade_ccr_grammar")
  23. sequence_rule2 = SequenceRule2()
  24. homemade_ccr_grammar.add_rule(sequence_rule2)
  25. homemade_ccr_grammar.load()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement