class HardwareRule(MappingRule): mapping = { # Windows 10 changes volume by increments 2 "volume <volume_mode> [<n_volume>]": R(Key("%(volume_mode)s") * Repeat(extra="n_volume")), "media <multimedia_control> [<n_media>]": R(Key("%(multimedia_control)s") * Repeat(extra="n_media")), "change monitor": R(Key("w-p") + Pause("100") + Function(change_monitor)) } extras = [ IntegerRefST("n_media", 1, 15), IntegerRefST("n_volume", 1, 50), Choice("multimedia_control", { "next": "tracknext", "back": "trackprev", "play|pause": "playpause", }), Choice("volume_mode", { "mute|unmute": "volumemute", "up": "volumeup", "down": "volumedown", }) ] defaults = { "n_volume": 1, "n_media": 1, "volume_mode": "setsysvolume", }
class NPPRule(MappingRule): mapping = { "stylize <n2>": R( Mouse("right") + Key("down:6/5, right") + (Key("down") * Repeat(extra="n2")) + Key("enter")), "remove style": R(Mouse("right") + Key("down:6/5, right/5, down:5/5, enter")), "preview in browser": R(Key("cas-r")), # requires function list plug-in: "function list": R(Key("cas-l")), "open": R(Key("c-o")), "go [to] line <n>": R(Key("c-g/10") + Text("%(n)s") + Key("enter")), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), IntegerRefST("n2", 1, 10), ] defaults = {"n": 1}
class SudokuGridRule(MappingRule): pronunciation = "sudoku grid" mapping = { "<n> [grid <s>] [<action>]": R(Function(move_mouse)), "[<n0>] [grid <s0>] drag <n> [grid <s>] [<action>]": R(Function(drag_mouse)), "escape": R(Function(kill)), SymbolSpecs.CANCEL: R(Function(kill)), } extras = [ IntegerRefST("n", -1, 1500), IntegerRefST("n0", -1, 1500), IntegerRefST("s", 0, 10), IntegerRefST("s0", 0, 10), Choice("action", { "move": 0, "kick": 1, "kick (double | 2)": 2, "psychic": 3, }), ] defaults = { "n": 0, "n0": 0, "s": 0, "s0": 0, "action": 0, }
class Numbers(MergeRule): pronunciation = "numbers" mapping = { "word number <wn>": R(Function(word_number, extra="wn")), "numb <wnKK>": R(Function(numbers2, extra="wnKK"), rspec="Number"), } extras = [ IntegerRefST("wn", 0, 10), IntegerRefST("wnKK", 0, 1000000), ] defaults = {}
class HMCHistoryRule(MappingRule): mapping = { # specific to macro recorder "check <n>": R(Function(hmc_checkbox)), "check from <n> to <n2>": R(Function(hmc_recording_check_range)), "exclude <n>": R(Function(hmc_recording_exclude)), "[make] repeatable": R(Function(hmc_recording_repeatable)) } extras = [ IntegerRefST("n", 1, 25), IntegerRefST("n2", 1, 25), ]
class Markdown(MergeRule): pronunciation = "mark down" mapping = { "heading [<num>] [<dict>]": R(Store() + Function(lambda num, dict: Text( ("#" * num) + " " + str(dict).capitalize()).execute()) + Retrieve() + Key("enter")), "table row <n>": R(Function(lambda n: Text("|" * (n - 1)).execute()) + Key("home")), "table (break | split) <n>": R( Function(lambda n: Text("---|" * (n - 1) + "---").execute()) + Key("enter")), "insert <element>": R(Store() + Key("%(element)s") + Retrieve(action_if_text="c-right")), "insert header": R(Text("---\nauthor: \ntitle: \n---\n")), } extras = [ Dictation("dict"), IntegerRefST("n", 1, 12), IntegerRefST("num", 1, 7), Choice( "element", { "list": "asterisk, space", "numbered list": "one, dot, space", "[block] quote": "rangle, space", "link": "lbracket, rbracket, lparen, rparen, left:3", "image": "exclamation, lbracket, rbracket, lparen, rparen, left:3", "reference": "lbracket, rbracket, left, at", "equation": "dollar, dollar, enter:2, dollar, dollar, up", "math": "dollar, dollar, left", "(italics | italic text)": "underscore:2, left", "bold [text]": "asterisk:4, left:2", "strike through [text]": "tilde:4, left:2", "horizontal rule": "asterisk, asterisk, asterisk, enter", "R code": "backtick:3, lbrace, r, rbrace, enter:2, backtick:3, up", "in line code": "backtick:2, left", "code [block]": "backtick:6, left:3, enter:2, up", }), ] defaults = { "num": 1, "dict": "", }
class CppSnippetExample(MappingRule): pronunciation = "sublime snippet" mapping = { "<snippet>": R(Function(insert_snippet)), "<snippet_variants> [<n>]": R(Function(insert_snippet_with_variants)), "variant <n>": R(Key("c-z") + Function(insert_variant)), "display variants": R(Key("c-z") + Function(display_variants)), "small test": R( Function(send_sublime, c="insert_snippe", data={ "contents": "${1:$PARAK}=2", "PARAK": "y" })) + R(Text("hello")), "small jerry": R(Function(send_sublime, c="prev_field", data={})), } extras = [ IntegerRefST("n", 1, 10), Choice("snippet", {k: v for k, v in snippets.items() if isinstance(v, str)}), Choice("snippet_variants", {k: v for k, v in snippets.items() if not isinstance(v, str)}), ] defaults = {}
class EclipseCCR(MergeRule): pronunciation = "eclipse jump" mapping = { #Line Ops "configure": R(Paste(ec_con.analysis_chars) + Key("left:2/5, c-f/20, backslash, rbracket, enter") + Function(ec_con.analyze_for_configure)), "jump in [<n>]": R(Key("c-f, a-o") + Paste(r"[\(\[\{\<]") + Function(ec_con.regex_on) + Key("enter:%(n)d/5, escape, right")), "jump out [<n>]": R(Key("c-f, a-o") + Paste(r"[\)\] \}\>]") + Function(ec_con.regex_on) + Key("enter:%(n)d/5, escape, right")), "jump back [<n>]": R(Key("c-f/5, a-b") + Paste(r"[\)\]\}\>]") + Function(ec_con.regex_on) + Key("enter:%(n)d/5, escape, left")), "[go to] line <n>": R(Key("c-l") + Pause("50") + Text("%(n)d") + Key("enter") + Pause("50")), "shackle <n> [<back>]": R(Key("c-l") + Key("right, cs-left") + Function(ec_con.lines_relative)), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), Boolean("back"), ] defaults = {"n": 1, "back": False}
class MSVCRule(MappingRule): mapping = { "cursor prior": R(Key("c-minus")), "cursor next": R(Key("cs-minus")), "toggle full screen": R(Key("sa-enter")), "resolve": R(Key("c-dot")), "jump to source": R(Key("f12")), "snippet": R(Key("tab")), "step over [<n>]": R(Key("f10/50") * Repeat(extra="n")), "step into": R(Key("f11")), "step out [of]": R(Key("s-f11")), "resume": R(Key("f8")), "build [last]": R(Key("ca-f7")), "debug [last]": R(Key("f5")), "comment out": R(Key("c-k/50, c-c")), "on comment out": R(Key("c-k/50, c-u")), "set bookmark": R(Key("c-k, c-k")), "next bookmark": R(Key("c-k, c-n")), "break point": R(Key("f9")), "format code": R(Key("cs-f")), "(do imports | import all)": R(Key("cs-o")), "comment line": R(Key("c-slash")), "go to line": R(Key("c-g")), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1}
class WindowManagementRule(MappingRule): mapping = { 'maximize': R(Function(utilities.maximize_window)), 'minimize': R(Function(utilities.minimize_window)), # Workspace management "show work [spaces]": R(Key("w-tab")), "(create | new) work [space]": R(Key("wc-d")), "close work [space]": R(Key("wc-f4")), "close all work [spaces]": R(Function(virtual_desktops.close_all_workspaces)), "next work [space] [<n>]": R(Key("wc-right"))*Repeat(extra="n"), "(previous | prior) work [space] [<n>]": R(Key("wc-left"))*Repeat(extra="n"), "go work [space] <n>": R(Function(virtual_desktops.go_to_desktop_number)), "send work [space] <n>": R(Function(virtual_desktops.move_current_window_to_desktop)), "move work [space] <n>": R(Function(virtual_desktops.move_current_window_to_desktop, follow=True)), } extras = [ IntegerRefST("n", 1, 20, default=1), ]
class GitHubDeskRule(MappingRule): mapping = { "new repository": R(Key("c-n")), "add local repository": R(Key("c-o")), "clone repository": R(Key("c-o")), "options": R(Key("c-comma")), "changes": R(Key("c-1")), "history": R(Key("c-2")), "(repositories | repository list)": R(Key("c-t")), "branches [list]": R(Key("c-b")), "zoom in [<n>]": R(Key("c-equals")) * Repeat(extra="n"), "zoom out [<n>]": R(Key("c-minus")) * Repeat(extra="n"), "reset zoom": R(Key("c-0")), "push [repository]": R(Key("c-p")), "pull [repository]": R(Key("cs-p")), "remove repository": R(Key("c-delete")), "view on github": R(Key("cs-g")), "(terminal | command prompt)": R(Key("c-backtick")), "explorer": R(Key("cs-f")), "edit": R(Key("cs-a")), "new branch": R(Key("cs-n")), "rename branch": R(Key("cs-r")), "delete branch": R(Key("cs-d")), "update from master": R(Key("cs-u")), "compare to branch": R(Key("cs-b")), "merge into current [branch]": R(Key("cs-m")), "compare on github": R(Key("cs-c")), "[create] pull request": R(Key("c-r")), } extras = [ IntegerRefST("n", 1, 10), ] defaults = {"n": 1}
class CppSnippetExampleExperimental(MappingRule): pronunciation = "sublime snippet" mapping = { "<snippet>": R(Function(insert_snippet)), "<snippet_variants> [<n>]": R(Function(insert_snippet_with_variants)), "variant <n>": R(Key("c-z") + Function(insert_variant)), "display variants": R(Key("c-z") + Function(display_variants)), "apply <transformation>": R(Key("c-z") + Function(transform_last_snippet)), "small test": R(Function(send_sublime,c = "insert_snippet",data = {"contents":"${1:${PARAK:y}}=2 + ${PARAK:z}","PARAK":"x"})), "small jerry": R(Function(send_sublime,c = "prev_field",data = {})), "jerry": R(Function(store_and_next)), "<snippet> over": R(Function(insert_snippet_with_defaults)), "<snippet_variants> [<n>] over": R(Function(insert_snippet_with_variants_and_defaults)), } extras = [ IntegerRefST("n",1,10), Choice("snippet",{k:v for k,v in snippets.items() if isinstance(v,str)}), Choice("snippet_variants",{k:v for k,v in snippets.items() if not isinstance(v,str)}), Choice("transformation",transformations), ] defaults = {}
class SSMSRule(MappingRule): mapping = { # There doesn't seem to be a hotkey for sequential tab navigation in SSMS, but something is better than nothing... "next tab [<n>]": R(Key("c-tab")) * Repeat(extra="n"), "prior tab [<n>]": R(Key("cs-tab")) * Repeat(extra="n"), "close tab [<n>]": R(Key("c-f4/20")) * Repeat(extra="n"), "go to line": R(Key("c-g")), "comment line": R(Key("c-k, c-c")), "comment block": R(Key("c-k, c-c")), "(un | on) comment line": R(Key("c-k/50, c-u")), "(un | on) comment block": R(Key("c-k/50, c-u")), "[toggle] full screen": R(Key("sa-enter")), "(set | toggle) bookmark": R(Key("c-k, c-k")), "next bookmark": R(Key("c-k, c-n")), "prior bookmark": R(Key("c-k, c-p")), "[toggle] break point": R(Key("f9")), "step over [<n>]": R(Key("f10/50") * Repeat(extra="n")), "step into": R(Key("f11")), "step out [of]": R(Key("s-f11")), "resume": R(Key("f5")), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim": ""}
class Again(MappingRule): mapping = { "again (<n> [(times|time)] | do)": R(Function(lambda n: Again._create_asynchronous(n)), show=False), # pylint: disable=E0602 } extras = [IntegerRefST("n", 1, 50)] defaults = {"n": 1} @staticmethod def _repeat(utterance): Playback([(utterance, 0.0)]).execute() return False @staticmethod def _create_asynchronous(n): if len(_history) == 0: return last_utterance_index = 1 if settings.WSR: # ContextStack adds the word to history before executing it if len(_history) == 1: return last_utterance_index = 2 utterance = [ str(x) for x in " ".join(_history[len(_history) - last_utterance_index]).split() ] if utterance[0] == "again": return forward = [L(S(["cancel"], lambda: Again._repeat(utterance)))] AsynchronousAction(forward, rdescript="Repeat Last Action", time_in_seconds=0.2, repetitions=int(n), blocking=False).execute()
class MouseAlternativesRule(MappingRule): mapping = { "legion [<monitor>] [<rough>]": R( Function(navigation.mouse_alternates, mode="legion") + Function(utilities.focus_mousegrid, gridtitle="legiongrid")), "rainbow [<monitor>]": R( Function(navigation.mouse_alternates, mode="rainbow") + Function(utilities.focus_mousegrid, gridtitle="rainbowgrid")), "douglas [<monitor>]": R( Function(navigation.mouse_alternates, mode="douglas") + Function(utilities.focus_mousegrid, gridtitle="douglasgrid")), "sudoku [<monitor>]": R( Function(navigation.mouse_alternates, mode="sudoku") + Function(utilities.focus_mousegrid, gridtitle="sudokugrid")), } extras = [ IntegerRefST("monitor", 1, 10), Choice("rough", { "rough": True, "detailed": False }) ] defaults = {"rough": True}
def get_extras(): return [ Choice( "nth", { "first": "1", "second": "2", "third": "3", "fourth": "4", "fifth": "5", "sixth": "6", "seventh": "7", "eighth": "8", }), IntegerRefST("n", 1, 100), IntegerRefST("m", 1, 10) ]
class MSTeamsRule(MappingRule): name = "microsoft teams" mapping = { # General "search": R(Key("c-e")), "keyboard shortcuts": R(Key("c-.")), "settings": R(Key("c-comma")), "help": R(Key("f1")), "commands": R(Key("c-slash")), "filter": R(Key("cs-f")), "go to": R(Key("c-g")), "new chat": R(Key("c-n")), # Navigation "activity": R(Key("c-1")), "chat": R(Key("c-2")), "teams": R(Key("c-3")), "calendar": R(Key("c-4")), "calls": R(Key("c-5")), "files": R(Key("c-6")), "shifts": R(Key("c-7")), "previous item [<nnavi10>]": R(Key("a-up")) * Repeat(extra="nnavi10"), "next item [<nnavi10>]": R(Key("a-down")) * Repeat(extra="nnavi10"), "previous team": R(Key("cs-up")), "next team": R(Key("cs-down")), "previous section": R(Key("cs-f6")), "next section": R(Key("c-f6")), # Messaging "focus compose": R(Key("c")), "expand compose": R(Key("cs-x")), "send": R(Key("c-enter")), "attach": R(Key("c-o")), "new-line": R(Key("s-enter")), "reply": R(Key("r")), # meetings calls and calendar "Accept [video] call": R(Key("cs-a")), "Accept [audio] call": R(Key("cs-")), "decline [call]": R(Key("cs-d")), "start audio call": R(Key("cs-c")), "Start video call": R(Key("cs-u")), "toggle mute": R(Key("cs-m")), "screen share": R(Key("cs-e")), "toggle video": R(Key("cs-o")), "sharing toolbar": R(Key("cs-space")), "decline screen share": R(Key("cs-d")), "Accept screen share": R(Key("cs-a")), "Schedule meeting": R(Key("as-n")), "go to current time": R(Key("a-.")), "go to previous (day | week)": R(Key("ca-left")), "go to next (day | week)": R(Key("ca-right")), "View day": R(Key("ca-1")), "View workweek": R(Key("ca-2")), "View week": R(Key("ca-3")), } exported = True extras = [IntegerRefST("nnavi10", 1, 11)] defaults = {"nnavi10": 1}
class StackTest(MappingRule): '''test battery for the ContextStack''' mapping = { "close last tag": ContextSeeker([ L(S(["cancel"], None), S(["html spoken"], close_last_spoken, use_spoken=True), S(["span", "div"], close_last_rspec, use_rspec=True)) ]), "html": R(Text("<html>"), rspec="html spoken"), "divider": R(Text("<div>"), rspec="div"), "span": R(Text("<span>"), rspec="span"), "backward seeker [<text>]": ContextSeeker([ L(S(["ashes"], Text("ashes1 [%(text)s] ")), S(["bravery"], Text("bravery1 [%(text)s] "))), L(S(["ashes"], Text("ashes2 [%(text)s] ")), S(["bravery"], Text("bravery2 [%(text)s] "))) ]), "forward seeker [<text>]": ContextSeeker(forward=[ L(S(["ashes"], Text("ashes1 [%(text)s] ")), S(["bravery"], Text("bravery1 [%(text)s] "))), L(S(["ashes"], Text("ashes2 [%(text)s] ")), S(["bravery"], Text("bravery2 [%(text)s] "))) ]), "asynchronous test": AsynchronousAction([ L(S(["ashes", "charcoal"], print_time, None), S(["bravery"], Text, "bravery1")) ], time_in_seconds=0.2, repetitions=20, finisher=Text(FINISHER_TEXT), blocking=False), "ashes": RegisteredAction(Text("ashes _ "), rspec="ashes"), "bravery": RegisteredAction(Text("bravery _ "), rspec="bravery"), "charcoal <text> [<n>]": R(Text("charcoal _ %(text)s"), rspec="charcoal"), "test confirm action": ConfirmAction(Key("a"), rdescript="Confirm Action Test", instructions="some words here"), "test box action": BoxAction(lambda data: _abc(data), rdescript="Test Box Action", box_type=settings.QTYPE_DEFAULT, log_failure=True), } extras = [Dictation("text"), Dictation("text2"), IntegerRefST("n", 1, 5)] defaults = {"text": "", "text2": ""}
class MSWordRule(MappingRule): mapping = { "insert image": R(Key("alt, n, p")), } extras = [ Dictation("dict"), IntegerRefST("n", 1, 100), ] defaults = {"n": 1, "dict": "nothing"}
class MainRule(MappingRule): mapping = { # it is this section that you want to fiddle around with if you're new: mapping, extras, and defaults # in the next line, there are two things to observe: # the first is the use of parentheses and the pipe symbol (|) # --this lets me use either "lock dragon" or "deactivate" to trigger that command. # The next is the playback action, which lets me tell Dragon to simulate me speaking some words. '(lock Dragon | deactivate)': Playback([(["go", "to", "sleep"], 0.0)]), # Here I'm using BringApp-- this is the same as typing what goes in between the parentheses # into the Windows command prompt, without the quotes and commas, like: # explorer C:\NatLink\NatLink\MacroSystem # -- (which would open Windows Explorer at the specified location). Anything you can do with the command line can be done this way # IMPORTANT: If you don't have Dragonfly 6.6 or later, lines 40 and 46 will cause this file to crash and should be commented out "open natlink folder": BringApp("explorer", r"C:\NatLink\NatLink\MacroSystem"), # here I'm using the Key action to press some keys -- see the documentation here: http://dragonfly.readthedocs.org/en/latest/actions.html?highlight=key#module-dragonfly.actions.action_key "remax": Key("a-space/10,r/10,a-space/10,x"), # here I'm chaining a bunch of different actions together to do a complex task "(show | open) documentation": BringApp( 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe') + WaitWindow(executable="chrome.exe") + Key('c-t') + WaitWindow(title="New Tab") + Text('http://dragonfly.readthedocs.org/en/latest') + Key('enter'), # here I'm just saying one word to trigger some other words "hotel": Text("hotels are not cheap"), # If you need to do more complicated tasks, or use external resources, a function might be what you need. # note that here, I'm using extras: "n" and "text" # The angle brackets <> meaning I'm using an extra, and the square brackets [] mean that I don't have to speak that word, it's optional. # Advice: if you use an optional extra, like I am with "text", you should set a default value in the defaults section down below. # To trigger the following command, you would have to say the word "function" followed by a number between 1 and 1000. '[use] function <n> [<text>]': Function(my_function, extra={'n', 'text'}), } extras = [ IntegerRefST("n", 1, 1000), Dictation("text"), Choice("choice", { "alarm": "alarm", "custom grid": "CustomGrid", "element": "e" }), ] defaults = { "n": 1, "text": "", }
class KDiff3Rule(MappingRule): mapping = { "refresh": R(Key("f5")), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim": ""}
class MouseAlternativesRule(MappingRule): mapping = { "legion [<monitor>]": R(Function(navigation.mouse_alternates, mode="legion")), "rainbow [<monitor>]": R(Function(navigation.mouse_alternates, mode="rainbow")), "douglas [<monitor>]": R(Function(navigation.mouse_alternates, mode="douglas")), } extras = [IntegerRefST("monitor", 1, 10)] defaults = {}
class LegionGridRule(MappingRule): mapping = { "<n> [<action>]": R(Function(send_input)), "refresh": R(Function(navigation.mouse_alternates, mode="legion")), SymbolSpecs.CANCEL: R(Function(kill)), "<n1> (select | light) <n2>": R(Function(drag_highlight)), } extras = [ Choice("action", { "kick": 0, "psychic": 1, "select | light": 2, }), IntegerRefST("n", 0, 1000), IntegerRefST("n1", 0, 1000), IntegerRefST("n2", 0, 1000), ] defaults = { "action": -1, }
class FlashDevelopRule(MappingRule): mapping = { "prior tab [<n>]": R(Key("c-pgup")) * Repeat(extra="n"), "next tab [<n>]": R(Key("c-pgdown")) * Repeat(extra="n"), "open resource": R(Key("c-r")), "jump to source": R(Key("f4")), "jump away": R(Key("s-f4")), "step over [<n>]": R(Key("f10") * Repeat(extra="n")), "step into": R(Key("f11")), "step out [of]": R(Key("s-f11")), "resume": R(Key("a-d, c")), "terminate": R(Key("s-f5")), "find everywhere": R(Key("cs-f")), "refractor symbol": R(Key("a-r, r")), "symbol next [<n>]": R(Key("f3")) * Repeat(extra="n"), "symbol prior [<n>]": R(Key("s-f3")) * Repeat(extra="n"), "format code": R(Key("cs-2")), "comment line": R(Key("c-q")), "clean it": R(Key("s-f8")), "build it": R(Key("f8")), "(debug | run) last": R(Key("f5")), "split view horizontal": R(Key("cs-enter")), "auto complete": R(Key("cs-1")), "[go to] line <n>": R(Key("c-g") + Pause("50") + Text("%(n)d") + Key("enter")), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim": ""}
class FoxitRule(MappingRule): mapping = { "next tab [<n>]": R(Key("c-tab")) * Repeat(extra="n"), "prior tab [<n>]": R(Key("cs-tab")) * Repeat(extra="n"), "close tab [<n>]": R(Key("c-f4/20")) * Repeat(extra="n"), } extras = [ Dictation("text"), Dictation("mim"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1, "mim": ""}
class SQLDeveloperRule(MappingRule): mapping = { "run this query": R(Key("f9")), "format code": R(Key("c-f7")), "comment line": R(Key("c-slash")), } extras = [ Dictation("text"), IntegerRefST("n", 1, 1000), ] defaults = {"n": 1}
class DouglasGridRule(MappingRule): mapping = { "<x> [by] <y> [<action>]": R(Function(send_input)), "<x1> [by] <y1> (grab | select) <x2> [by] <y2>": R(Function(send_input_select)), "<x1> [by] <y1> (grab | select) <x2>": R(Function(send_input_select_short)), "squat": R(Function(store_first_point)), "bench": R(Function(select_text)), SymbolSpecs.CANCEL: R(Function(kill)), } extras = [ IntegerRefST("x", 0, 300), IntegerRefST("y", 0, 300), IntegerRefST("x1", 0, 300), IntegerRefST("y1", 0, 300), IntegerRefST("x2", 0, 300), IntegerRefST("y2", 0, 300), Choice("action", { "kick": 0, "psychic": 1, "move": 2, }), Choice("point", { "one": 1, "two": 2, }), ] defaults = { "action": -1, }
class Punctuation(MergeRule): pronunciation = "punctuation" mapping = { "[<long>] <text_punc> [<npunc>]": R(Text("%(long)s" + "%(text_punc)s" + "%(long)s"))*Repeat(extra="npunc"), # For some reason, this one doesn't work through the other function "[<long>] backslash [<npunc>]": R(Text("%(long)s" + "\\" + "%(long)s"))*Repeat(extra="npunc"), "<double_text_punc> [<npunc>]": R(Text("%(double_text_punc)s") + Key("left"))*Repeat(extra="npunc"), "tabby [<npunc>]": R(Key("tab"))*Repeat(extra="npunc"), "(back | shin) tabby [<npunc>]": R(Key("s-tab"))*Repeat(extra="npunc"), "boom [<npunc>]": R(Text(", "))*Repeat(extra="npunc"), "bam [<npunc>]": R(Text(". "))*Repeat(extra="npunc"), "ace [<npunc100>]": R(Text(" "))*Repeat(extra="npunc100"), } extras = [ IntegerRefST("npunc", 0, 10), IntegerRefST("npunc100", 0, 100), Choice( "long", { "long": " ", }), Choice( "text_punc", text_punc_dict()), Choice( "double_text_punc", double_text_punc_dict()) ] defaults = { "npunc": 1, "npunc100": 1, "long": "", }
class Numbers(MergeRule): pronunciation = "numbers" mapping = { "word number <wn>": R(Function(word_number, extra="wn")), "[<long>] numb <wnKK>": R(Text("%(long)s") + Function(numbers2, extra="wnKK") + Text("%(long)s"), rspec="Number"), } extras = [ IntegerRefST("wn", 0, 10), IntegerRefST("wnKK", 0, 1000000), Choice( "long", { "long": " ", }), ] defaults = { "long": "", }
class CppSnippetMoreExampleExperimental(MappingRule): pronunciation = "sublime snippet" mapping = { "<snippet>": R(Snippet("%(snippet)s")), "<snippet_variants> [<n>]": R(Snippet("%(snippet_variants)s")), "<stream> <thing> [<n>] [with <delimiter>]": R( Snippet(lambda stream, thing, n, delimiter: stream[0] + stream[ 1].format(delimiter).join([thing(x) for x in range(1, n + 1)]) + stream[2])), "variant (<thing>|<stream>)": R(Key("c-z") + SnippetVariant(thing="thing", stream="stream")), "apply <transformation>": R(Key("c-z") + SnippetTransform("%(transformation)s")), "instead apply <transformation>": R(Key("c-z") + SnippetTransform("%(transformation)s", steps=1)), "display delimiter variants": R( Key("c-z") + DisplaySnippetVariants("delimiter", delimiter.values())), } extras = [ IntegerRefST("n", 1, 10), Choice( "stream", { "output": ("std::cout<< ", ' << {0} << ', " << std::endl;"), "error": ("std::cerr<< ", ' << {0} << ', " << std::endl;"), "input": ("std::cin>> ", " >> ", ";"), }), Choice( "thing", { "line": lambda x: "$" + str(x), "attribute": lambda x: "$1.$" + str(x + 1), "index": lambda x: "$1[${0}]".format(x + 1), "named": lambda x: '"${0}" << " " << ${0}'.format(x), "common attribute": lambda x: "${0}.$1".format(x + 1), "common index": lambda x: "${0}[$1]".format(x + 1), }), Choice("delimiter", delimiter), Choice("snippet", {k: v for k, v in snippets.items() if isinstance(v, str)}), Choice("snippet_variants", {k: v for k, v in snippets.items() if not isinstance(v, str)}), Choice("transformation", transformations), ] defaults = {"n": 1, "delimiter": '" "'}