comprehensive example file for scripting




According to the author, this single example file should cover global
and programs/window specific Dragonfly scripts.







from dragonfly import *

class SeriesMappingRule(CompoundRule):

def __init__(self, mapping, extras=None, defaults=None):
mapping_rule = MappingRule(
mapping=mapping,
extras=extras,
defaults=defaults,
exported=False,
)
single = RuleRef(rule=mapping_rule)
series = Repetition(single, min=1, max=16, name="series")

compound_spec = "demo <series>"
compound_extras = [series]
CompoundRule.__init__(self, spec=compound_spec,
extras=compound_extras, exported=True)

def _process_recognition(self, node, extras):
series = extras["series"]
for action in series:
action.execute()

global_series_rule = SeriesMappingRule(
mapping ={
"global one": Text("Series command: global 1!\n"),
"global two": Text("Series command: global 2!\n"),
"global three": Text("Series command: global 3!\n"),
},
extras =[
],
defaults={
},
)

global_context = None # Context is None, so grammar will be globally
active.
global_grammar = Grammar("demo global", context=global_context)
global_grammar.add_rule(global_series_rule)
global_grammar.load()

notepad_series_rule = SeriesMappingRule(
mapping ={
"notepad one": Text("Series command: notepad 1!\n"),
"notepad two": Text("Series command: notepad 2!\n"),
"notepad three": Text("Series command: notepad 3!\n"),
},
extras =[
],
defaults={
},
)

notepad_context = AppContext(executable="notepad.exe")
notepad_grammar = Grammar("demo notepad", context=notepad_context)
notepad_grammar.add_rule(notepad_series_rule)
notepad_grammar.load()

grammar_list = [
global_grammar,
notepad_grammar,
]

def unload():
global grammar_list
while grammar_list:
grammar = grammar_list.pop()
grammar.unload()
.



Relevant Pages

  • Re: Constructibility of X -> X^2 bijection
    ... Consider the mapping from the ... enumerates exactly the elements of X (or a grammar that enumerates ... the first two characters in the alphabet. ... characters, changing the ordering of the expressions, thus changing ...
    (sci.math)
  • Re: Tree Creation
    ... I'm working on a project to parse EDI documents and I'm learning Lisp ... a segment and an element delimiter. ... figure out what a more verbose mapping would be. ... include in the mapping that would make it more of a grammar definition. ...
    (comp.lang.lisp)

Loading