Skip to content

Commit 5e5e8ad

Browse files
author
LexiconCode
committed
Adapted bundled grammar for Caster 0.6.11
1 parent 4b1ffc4 commit 5e5e8ad

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
from dragonfly import (Choice, Dictation, Grammar, Repeat, StartApp, Function)
2+
3+
from castervoice.lib import control
4+
from castervoice.lib import settings
5+
from castervoice.lib.actions import Key, Text
6+
from castervoice.lib.context import AppContext
7+
from castervoice.lib.dfplus.additions import IntegerRefST
8+
from castervoice.lib.dfplus.merge import gfilter
9+
from castervoice.lib.dfplus.merge.mergerule import MergeRule
10+
from castervoice.lib.dfplus.state.short import R
11+
12+
13+
14+
import os
15+
import subprocess
16+
import json
17+
18+
def create_arguments(command,format,**kwargs):
19+
p = {x:kwargs[x] for x in kwargs.keys() if x not in ['_node','_rule','_grammar']}
20+
p["format"] = format
21+
p["command"] = command
22+
return {"arg":p}
23+
24+
25+
def send_sublime(c,data):
26+
x = json.dumps(data).replace('"','\\"')
27+
y = "subl --command \"" + c + " " + x + "\""
28+
subprocess.call(y, shell = True)
29+
# subprocess.call("subl --command \"argument {\\\"arg\\\":[1,\\\"None\\\", \\\"argument\\\", 1]}\"",shell = True)
30+
subprocess.call("subl", shell = True)
31+
32+
def noob_send(command,format,**kwargs):
33+
data = create_arguments(command,format,**kwargs)
34+
send_sublime("python_voice_coding_plugin", data)
35+
36+
def lazy_value(c,f,**kwargs):
37+
return R(Function(noob_send, command = c, format = f,**kwargs))
38+
39+
40+
class SublimeRulePlugin(MergeRule):
41+
pronunciation = "python voice coding plugin"
42+
mapping = {
43+
# alternative rule
44+
"[smart] alternative <alternative_index>":
45+
lazy_value("alternative",1),
46+
"smart <color> [alternative]":
47+
lazy_value("alternative",2),
48+
49+
# paste back rule
50+
"[smart] paste back [<paste_back_index>]":
51+
lazy_value("paste_back",1),
52+
"[smart] paste <color> back":
53+
lazy_value("paste_back",2),
54+
55+
# argument rule
56+
"[smart] [<adjective>] argument <argument_index>":
57+
lazy_value("argument",1),
58+
"[smart] <vertical_direction> [<ndir>] [<adjective>] argument <argument_index>":
59+
lazy_value("argument",2),
60+
"[smart] [<adjective>] <level> [<level_index>] argument <argument_index>":
61+
lazy_value("argument",3),
62+
"[smart] <level> [<level_index>] <adjective> argument <argument_index>":
63+
lazy_value("argument",4),
64+
65+
# big roi rule
66+
"smart <big_roi> [<big_roi_sub_index>]":
67+
lazy_value("big_roi",1),
68+
"[smart] <adjective> <big_roi> [<big_roi_sub_index>]":
69+
lazy_value("big_roi",2),
70+
"[smart] <vertical_abstract_only_direction> [<ndir>] <big_roi> [<big_roi_sub_index>]":
71+
lazy_value("big_roi",3),
72+
"[smart] <vertical_abstract_only_direction> [<ndir>] <block> [<adjective>] <big_roi> [<big_roi_sub_index>]":
73+
lazy_value("big_roi",4),
74+
75+
76+
# insert rule
77+
"(smart insert|insert item) <item_index>":
78+
lazy_value("insert_item",1),
79+
80+
# collect rule
81+
"[smart] collect <collectable>":
82+
lazy_value("collect_indexable",1),
83+
"[smart] variable <collect_index>":
84+
lazy_value("collect_variable",2),
85+
"[smart] parameter <collect_index>":
86+
lazy_value("collect_parameter",2),
87+
"[smart] module <collect_index>":
88+
lazy_value("collect_module",2),
89+
"[smart] imported (value|object) <collect_index>":
90+
lazy_value("collect_imported_value",2),
91+
92+
93+
94+
# banana example
95+
# "banana [<adjective>] <big_roi> [<big_roi_sub_index>]":
96+
# lazy_value("big_roi",4,vertical_abstract_only_direction = "above",
97+
# ndir = 1,block = "function"),
98+
99+
}
100+
extras = [
101+
IntegerRefST("argument_index", 1, 10),
102+
IntegerRefST("alternative_index", 1, 10),
103+
IntegerRefST("ndir",1,20),
104+
IntegerRefST("level_index",1,10),
105+
IntegerRefST("big_roi_sub_index",0,10),
106+
IntegerRefST("paste_back_index",0,10),
107+
IntegerRefST("collect_index",1,30),
108+
IntegerRefST("item_index",1,30) ,
109+
Choice("adjective",{
110+
"first" : "first",
111+
"second": "second",
112+
"third": "third",
113+
"fourth": "fourth",
114+
"fifth": "fifth",
115+
"sixth": "sixth",
116+
"seventh": "seventh",
117+
"eighth": "eighth",
118+
"ninth":"ninth",
119+
"last":"last",
120+
"second last": "second last",
121+
"third last": "third last",
122+
"fourth last": "fourth last",
123+
}
124+
) ,
125+
Choice("vertical_direction",{
126+
"up":"up",
127+
"down":"down",
128+
"above":"above",
129+
"below":"below",
130+
}
131+
),
132+
Choice("vertical_abstract_only_direction",{
133+
"above":"above",
134+
"below":"below",
135+
}
136+
),
137+
Choice("color",{
138+
"red":1,
139+
"blue":2,
140+
"green":3,
141+
"yellow":4,
142+
"orange":5,
143+
}
144+
),
145+
Choice("level",{
146+
"inside":"inside",
147+
}
148+
),
149+
Choice("big_roi",{
150+
"if condition" : "if condition",
151+
"else if condition" : "else if condition",
152+
"while condition" : "while condition",
153+
"if expression condition" : "if expression condition",
154+
"if expression body" : "if expression body",
155+
"if expression":"if expression",
156+
"comprehension condition" : "comprehension condition",
157+
"return value" : "return value",
158+
"pass":"pass",
159+
"break" : "break",
160+
"continue" : "continue",
161+
"assertion message" : "assertion message",
162+
"assertion condition" : "assertion condition",
163+
"(assignment right| right)" : "assignment right",
164+
"(assignment left| left)" : "assignment left",
165+
"assignment full" : "assignment full",
166+
"import statement":"import statement",
167+
#"(import|imported) (value|item|object|element)":"import value",
168+
#"module" : "module",
169+
"(expression statement|expression)" : "expression statement",
170+
"iterator" : "iterator",
171+
"iterable" : "iterable",
172+
173+
}
174+
),
175+
Choice("block",{
176+
"(function|functions)" :"function",
177+
}
178+
),
179+
Choice("collectable",{
180+
"(variable|variables)":"variable",
181+
"( parameter | parameters)":"parameter",
182+
"(module|modules)":"module",
183+
"(import|imported) (value|item|object|element)":"import value",
184+
"function ( name |names)":"function name",
185+
}
186+
),
187+
188+
189+
]
190+
defaults = {
191+
"adjective":"None",
192+
"ndir":1,
193+
"level_index":1,
194+
"big_roi_sub_index":0,
195+
"paste_back_index":0,
196+
197+
}
198+
199+
200+
#---------------------------------------------------------------------------
201+
202+
context = AppContext(executable="sublime_text", title="Sublime Text")
203+
control.non_ccr_app_rule(SublimeRulePlugin(), context=context)

0 commit comments

Comments
 (0)