updated grammars and started terminal grammar

master
Jeremy 2019-08-07 14:32:51 -05:00
parent eca3da6455
commit 7cc7611944
6 changed files with 226 additions and 84 deletions

View File

@ -1,8 +1,8 @@
# Author:Brandon Lovrien
# This script includes some commands for various useful symbols used in programming
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule)
#from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule)
from dragonfly import *
# Useful commands for encapsulation of quotes, etc.
class UsefulStuff(MappingRule):
@ -15,7 +15,11 @@ class UsefulStuff(MappingRule):
"in angle brackets": Text("<>") + Key("left"),
"parameters": Text("()"),
"arrow": Text("->"),
"double arrow": Text("=>"),
"double arrow": Text("=>"),
"enter|slap": Key("enter"),
"east": Key("end"),
"west": Key("home"),
}
globalStuff = Grammar("useful custom global commands") # Create a grammar to contain the command rule.

View File

@ -1,36 +0,0 @@
# This file is part of Aenea
#
# Aenea is free software: you can redistribute it and/or modify it under
# the terms of version 3 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# Aenea is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Aenea. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (2014) Alex Roper
# Alex Roper <alex@aroper.net>
from aenea import Grammar, MappingRule, Text
grammar = Grammar('hello world aenea')
print 'Aenea hello world grammar: Loaded.'
class TestRule(MappingRule):
mapping = {
'test hello world remote grammar': Text('Aenea remote setup operational'),
}
grammar.add_rule(TestRule())
grammar.load()
def unload():
global grammar
if grammar:
grammar.unload()
grammar = None

View File

@ -2,23 +2,27 @@
# This script includes commands used for HTML coding
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
class HTMLEnabler(CompoundRule):
spec = "Enable HTML" # Spoken form of command.
spec = "Activate HTML" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
htmlBootstrap.disable()
htmlGrammar.enable()
print "HTML grammar enabled"
s = "HTML grammar activated"
print s
speaker.Speak(s)
class HTMLDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
htmlGrammar.disable()
htmlBootstrap.enable()
print "HTML grammar disabled"
s = "HTML grammar deactivated"
print s
speaker.Speak(s)
class HTMLTestRule(CompoundRule):
spec = "test HTML" # Spoken form of command.

View File

@ -15,7 +15,7 @@ class JavaScriptEnabler(CompoundRule):
def _process_recognition(self, node, extras): # Callback when command is spoken.
JavaScriptBootstrap.disable()
JavaScriptGrammar.enable()
s = "JavaScript grammar enabled"
s = "JavaScript grammar activated"
print s
speaker.Speak(s)
@ -26,7 +26,7 @@ class JavaScriptDisabler(CompoundRule):
def _process_recognition(self, node, extras): # Callback when command is spoken.
JavaScriptGrammar.disable()
JavaScriptBootstrap.enable()
s = "JavaScript grammar disabled"
s = "JavaScript grammar deactivated"
print s
speaker.Speak(s)
@ -50,38 +50,10 @@ class JavaScriptControlStructures(MappingRule):
"else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"while loop": Text("while() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"do while loop": Text("do {") + Key("enter") + Key("down") + Text("while()"),
"for loop": Text("for(;;) {") + Key("enter")+ Key("enter"), #+ Text("}"),
"for loop": Text("for( ; ; ) {") + Key("enter")+ Key("enter"), #+ Text("}"),
"switch statement": Text("switch() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"alpha": Text("a"),
"bravo": Text("b"),
"charlie": Text("c"),
"delta": Text("d"),
"echo": Text("e"),
"foxtrot": Text("f"),
"golf": Text("g"),
"hotel": Text("h"),
"(india|indigo) ": Text("i"),
"juliet": Text("j"),
"kilo": Text("k"),
"lima": Text("l"),
"mike": Text("m"),
"november": Text("n"),
"oscar": Text("o"),
"(P|papa|poppa) ": Text("p"),
"(Q|quebec|quiche) ": Text("q"),
"romeo": Text("r"),
"sierra": Text("s"),
"tango": Text("t"),
"uniform": Text("u"),
"victor": Text("v"),
"whiskey": Text("w"),
"(X|x-ray) ": Text("x"),
"yankee": Text("y"),
"zulu": Text("z"),
}
class JavaScriptCommentsSyntax(MappingRule):
mapping = {
@ -103,11 +75,13 @@ class JavaScriptComparisonOperators(MappingRule):
mapping = {
"equal to": Text("=="),
"exactly equal to": Text("==="),
"not equal to": Text("!="),
"(not equal to|bang it)": Text("!="),
"greater than": Text(">"),
"less than": Text("<"),
"greater than or equal to": Text(">="),
"less than or equal to": Text("<="),
"(lake|open curly)": Text("{"),
"(rake|rate|close curly)": Text("}")
}

View File

@ -115,6 +115,75 @@ class ProgrammingNamingConventions(MappingRule):
"space free <command>": Function(SpaceFreeFormat),
"space free <command> <symbol>": Function(SpaceFreeFormat) + Text("%(symbol)s"),
"<symbol> space free <command>": Text("%(symbol)s") + Function(SpaceFreeFormat),
# Numbers
"zero": Text("0"),
"one": Text("1"),
"(two|to)": Text("2"),
"three": Text("3"),
"four": Text("4"),
"five": Text("5"),
"six": Text("6"),
"seven": Text("7"),
"eight": Text("8"),
"nine": Text("9"),
"pipe": Text("|"),
# Alpha codes
"alpha": Text("a"),
"bravo": Text("b"),
"charlie": Text("c"),
"delta": Text("d"),
"echo": Text("e"),
"foxtrot": Text("f"),
"golf": Text("g"),
"hotel": Text("h"),
"(india|indigo) ": Text("i"),
"juliet": Text("j"),
"kilo": Text("k"),
"lima": Text("l"),
"mike": Text("m"),
"november": Text("n"),
"oscar": Text("o"),
"(P|papa|poppa) ": Text("p"),
"(Q|quebec|quiche) ": Text("q"),
"romeo": Text("r"),
"sierra": Text("s"),
"tango": Text("t"),
"uniform": Text("u"),
"victor": Text("v"),
"whiskey": Text("w"),
"(X|x-ray) ": Text("x"),
"yankee": Text("y"),
"zulu": Text("z"),
# Caps Alpha codes
"caps alpha": Text("A"),
"caps bravo": Text("B"),
"caps charlie": Text("C"),
"caps delta": Text("D"),
"caps echo": Text("E"),
"caps foxtrot": Text("F"),
"caps golf": Text("G"),
"caps hotel": Text("H"),
"caps (india|indigo) ": Text("I"),
"caps juliet": Text("J"),
"caps kilo": Text("K"),
"caps lima": Text("L"),
"caps mike": Text("M"),
"caps november": Text("N"),
"caps oscar": Text("O"),
"caps (P|papa|poppa) ": Text("P"),
"caps (Q|quebec|quiche) ": Text("Q"),
"caps romeo": Text("R"),
"caps sierra": Text("S"),
"caps tango": Text("T"),
"caps uniform": Text("U"),
"caps victor": Text("V"),
"caps whiskey": Text("W"),
"caps (X|x-ray) ": Text("X"),
"caps yankee": Text("Y"),
"caps zulu": Text("Z"),
}
extras = [

127
_terminal_grammar.py Normal file
View File

@ -0,0 +1,127 @@
# Author: Jeremy Hayes
# This script includes commands that are to be used for Terminal programming
from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic)
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
def doSomethingToCommand(command):
newCommand = Sequence(command)
newCommand.execute()
class TerminalEnabler(CompoundRule):
spec = "Activate Terminal" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
TerminalBootstrap.disable()
TerminalGrammar.enable()
s = "Terminal grammar activated"
print s
speaker.Speak(s)
class TerminalDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
TerminalGrammar.disable()
TerminalBootstrap.enable()
s = "Terminal grammar deactivated"
print s
speaker.Speak(s)
class TerminalTestRule(CompoundRule):
spec = "test Terminal" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "Terminal grammar tested"
class TerminalControlStructures(MappingRule):
mapping = {
"variable": Text("var "),
"console": Text("console.log();"),
"function": Text("function functionName() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"variable function": Text("functionName = function () {") + Key("enter")+ Key("enter"), #+ Text("}"),
"self function": Text("(function() {") + Key("enter")+ Key("enter"), #+ Text("}())"),
"code block": Text("{") + Key("enter")+ Key("enter"), #+ Text("}"),
"if": Text("if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"if else": Text("if() {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("else {") + Key("enter")+ Key("enter"), #+ Text("}"),
"else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"while loop": Text("while() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"do while loop": Text("do {") + Key("enter") + Key("down") + Text("while()"),
"for loop": Text("for( ; ; ) {") + Key("enter")+ Key("enter"), #+ Text("}"),
"switch statement": Text("switch() {") + Key("enter")+ Key("enter"), #+ Text("}"),
}
class TerminalCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
}
class TerminalMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"new": Text("new "),
}
class TerminalComparisonOperators(MappingRule):
mapping = {
"equal to": Text("=="),
"exactly equal to": Text("==="),
"not equal to": Text("!="),
"greater than": Text(">"),
"less than": Text("<"),
"greater than or equal to": Text(">="),
"less than or equal to": Text("<="),
}
class TerminalArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
}
class TerminalAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
"modulus equals": Text("%="),
}
TerminalBootstrap = Grammar("Terminal bootstrap") # Create a grammar to contain the command rule.
TerminalBootstrap.add_rule(TerminalEnabler())
TerminalBootstrap.load()
TerminalGrammar = Grammar("Terminal grammar")
TerminalGrammar.add_rule(TerminalTestRule())
TerminalGrammar.add_rule(TerminalControlStructures())
TerminalGrammar.add_rule(TerminalCommentsSyntax())
TerminalGrammar.add_rule(TerminalMiscellaneousStuff())
TerminalGrammar.add_rule(TerminalComparisonOperators())
TerminalGrammar.add_rule(TerminalArithmeticOperators())
TerminalGrammar.add_rule(TerminalAssignmentOperators())
TerminalGrammar.add_rule(TerminalDisabler())
TerminalGrammar.load()
TerminalGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global TerminalGrammar
if TerminalGrammar: TerminalGrammar.unload()
TerminalGrammar = None