Last active
November 25, 2020 00:06
-
-
Save haughki/d9952a190728aca1e9c589dbb1dddb88 to your computer and use it in GitHub Desktop.
NOTE: this doesn't work -- here as a broken example. A dragonfly global CCR rule which references two rules, one of which has an app-specific context. Expect that you can CCR all commands in "code" app, but only Example2 commands in any other context.
This file contains 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 * | |
from supporting import utils | |
class Example(MappingRule): | |
context = AppContext(executable="code") # app-specific context | |
#exported = False | |
mapping = { | |
"command one": Text("comm 1 "), | |
"command two": Text("comm 2 "), | |
} | |
class Example2(MappingRule): | |
#exported = False | |
mapping = { | |
"command three": Text("comm 3 "), | |
"command four": Text("comm 4 "), | |
} | |
alternatives = [ | |
RuleRef(rule=Example()), | |
RuleRef(rule=Example2()), | |
] | |
sequence = Repetition(Alternative(alternatives), min=1, max=16, name="sequence") | |
class ChainRule(CompoundRule): | |
spec = "<sequence>" | |
extras = [ | |
sequence, | |
] | |
def _process_recognition(self, node, extras): | |
for action in extras["sequence"]: | |
action.execute() | |
example_grammar = Grammar("example grammar") | |
example_grammar.add_rule(ChainRule()) | |
example_grammar.load() | |
def unload(): | |
global example_grammar | |
example_grammar = utils.unloadHelper(example_grammar, __name__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment