Skip to content

Instantly share code, notes, and snippets.

@alexboche
Created August 10, 2019 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexboche/a0a5080ff76b3ed57a4007ca912947d6 to your computer and use it in GitHub Desktop.
Save alexboche/a0a5080ff76b3ed57a4007ca912947d6 to your computer and use it in GitHub Desktop.
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