Created
August 10, 2019 00:37
-
-
Save alexboche/a0a5080ff76b3ed57a4007ca912947d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment