Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from dragonfly import *
- class CommandRule(MappingRule):
- mapping = {
- "amp": Key("a"),
- "bairch": Key("b"),
- "lanty [<n>]": Key("left"),
- }
- extras = [IntegerRef("n", 1, 10)]
- defaults = {"n":1}
- command_rule = CommandRule()
- cmd_sequence = Repetition(RuleRef(command_rule), min=1, max=10, name="cmd_sequence")
- class SequenceRule2(CompoundRule):
- spec = "<cmd_sequence>"
- extras = [cmd_sequence]
- def _process_recognition(self, node, extras):
- for action in extras["cmd_sequence"]:
- print(action)
- action.execute()
- homemade_ccr_grammar = Grammar("random_name_for_homemade_ccr_grammar")
- sequence_rule2 = SequenceRule2()
- homemade_ccr_grammar.add_rule(sequence_rule2)
- homemade_ccr_grammar.load()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement