Initial commit

master
Jeremy 2019-08-02 15:25:33 -05:00
commit eca3da6455
14 changed files with 1589 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__/
*.py[cod]

122
_angularjs_grammar.py Normal file
View File

@ -0,0 +1,122 @@
# Author:Brandon Lovrien
# This script includes commands that are to be used for Angular programming
from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic)
def doSomethingToCommand(command):
newCommand = Sequence(command)
newCommand.execute()
class AngularEnabler(CompoundRule):
spec = "Activate Angular JS" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
AngularBootstrap.disable()
AngularGrammar.enable()
print "Angular JS grammar enabled"
class AngularDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
AngularGrammar.disable()
AngularBootstrap.enable()
print "Angular JS grammar disabled"
class AngularTestRule(CompoundRule):
spec = "test Angular JS" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "Angular JS grammar tested"
class AngularControlStructures(MappingRule):
mapping = {
"variable": Text("var "),
"function": Text("function functionName() {") + 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 AngularCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
}
class AngularMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"new": Text("new "),
}
class AngularComparisonOperators(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 AngularArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
}
class AngularAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
"modulus equals": Text("%="),
}
AngularBootstrap = Grammar("Angular bootstrap") # Create a grammar to contain the command rule.
AngularBootstrap.add_rule(AngularEnabler())
AngularBootstrap.load()
AngularGrammar = Grammar("Angular grammar")
AngularGrammar.add_rule(AngularTestRule())
AngularGrammar.add_rule(AngularControlStructures())
AngularGrammar.add_rule(AngularCommentsSyntax())
AngularGrammar.add_rule(AngularMiscellaneousStuff())
AngularGrammar.add_rule(AngularComparisonOperators())
AngularGrammar.add_rule(AngularArithmeticOperators())
AngularGrammar.add_rule(AngularAssignmentOperators())
AngularGrammar.add_rule(AngularDisabler())
AngularGrammar.load()
AngularGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global AngularGrammar
if AngularGrammar: AngularGrammar.unload()
AngularGrammar = None

201
_cpp_grammar.py Normal file
View File

@ -0,0 +1,201 @@
# Author:Brandon Lovrien
# this script includes the macros for C++ programming
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Integer)
class CPPEnabler(CompoundRule):
spec = "Enable CPP" # note: this command couldn't be "enable C++" because it causes problems with the grammar engine due to complexity.
def _process_recognition(self, node, extras): # Callback when command is spoken.
CPPBootstrap.disable()
CPPGrammar.enable()
print "C++ grammar enabled"
class CPPDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
CPPGrammar.disable()
CPPBootstrap.enable()
print "C++ grammar disabled"
# test rule to see if this script is working
class CPPTestRule(CompoundRule):
spec = "test CPP" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "C++ grammar tested"
#Rules for implementing control structures in C++
class CPPControlStructures(MappingRule):
mapping = {
"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("enter") + Text("} while();"),
"for loop": Text("for(;;) {") + Key("enter")+ Key("enter") + Text("}"),
"switch statement": Text("switch() {") + Key("enter")+ Key("enter") + Text("}"),
"try catch": Text("try {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("catch() {") + Key("enter")+ Key("enter") + Text("}"),
}
#Some syntax rules for functions, classes, etc. in C++
class CPPFunctionsAndClassesSyntax(MappingRule):
mapping = {
#function syntax stuff
"function prototype": Text("returnType functionName();"),
"function": Text("returnType functionName() {")+Key("enter")+ Key("enter")+ Text("}"),
#miscellaneous syntax stuff
"struct": Text("struct structName {") + Key("enter")+ Key("enter") + Text("};"),
"union": Text("union unionName {") + Key("enter")+ Key("enter") + Text("};"),
"enumeration": Text("enum enumerationName {") + Key("enter")+ Key("enter") + Text("};"),
"type definition": Text("typedef existingDatatype name;"),
"create namespace": Text("namespace namespaceName {") + Key("enter")+ Key("enter") + Text("}"),
#class syntax stuff
"class": Text("class ClassName {") + Key("enter")+ Text("public:")+ Key("enter") + Key("enter") + Text("};"),
"constructor": Text("();") + Key("left")+ Key("left")+ Key("left"),
"destructor": Text("~();") + Key("left")+ Key("left")+ Key("left"),
}
class CPPOperators(MappingRule):
mapping = {
"scope operator": Text("::"),
"plus plus": Text("++"),
"minus minus": Text("--"),
"plus": Text("+"),
"minus": Text("-"),
"divided by": Text("/"),
"address of": Text("&"),
"left shift": Text(" << "),
"right shift": Text(" >> "),
"equals": Text("="),
"greater than": Text(">"),
"less than": Text("<"),
"greater than or equal to": Text(">="),
"less than or equal to": Text("<="),
"equals equals": Text("=="),
"not equal to": Text("!="),
"logical and": Text("&&"),
"logical or": Text("||"),
"plus equals": Text("+="),
"minus equals": Text("-="),
}
#Handles the C++ commenting syntax
class CPPCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") + Key("enter") + Text("*/") + Key("up")
}
#Some useful miscellaneous C++ functions
class CPPUsefulFunctions(MappingRule):
mapping = {
"print statement": Text("cout << ;") + Key("left"),
"input statement": Text("cin >> ;") + Key("left"),
"end line": Text("endl"),
}
#Syntax for preprocessor directives in C++
class CPPPreprocessorDirectives(MappingRule):
mapping = {
"directive include": Text("#include "),
"directive pragma": Text("#pragma "),
"directive if": Text("#if "),
"directive else": Text("#else"),
"directive else if": Text("#elif "),
"directive if defined": Text("#ifdef "),
"directive if not defined": Text("#ifndef "),
"directive end if": Text("#endif"),
"directive define": Text("#define "),
"directive undefine": Text("#undef "),
"directive error": Text("#error"),
"directive line": Text("#line ")
}
#C++ datatypes
class CPPDataTypes(MappingRule):
mapping = {
"integer": Text("int "),
"float": Text("float "),
"double": Text("double "),
"boolean": Text("bool "),
"char": Text("char "),
"string": Text("string "),
"long": Text("long "),
"long double": Text("long double "),
"wide character": Text("wchar_t "),
"short": Text("short "),
"constant": Text("const "),
"null": Text("NULL"),
#my attempt at a C++ script for shortcut float notation
"<n> point <n2> float": Text("%(n)d.%(n2)d") + Text("f"),
"<n> point <n2> <n3> float": Text("%(n)d.%(n2)d%(n3)d") + Text("f"),
"<n> point <n2> <n3> <n4> float": Text("%(n)d.%(n2)d%(n3)d%(n4)d") + Text("f"),
}
extras = [
Integer("n", -1000, 1000),
Integer("n2", 0, 1000),
Integer("n3", 0, 1000),
Integer("n4", 0, 1000)
]
class CPPEscapeSequences(MappingRule):
mapping = {
"escape quotes": Text("\ ")+ Key("left") + Text("\"") + Text("\ ")+ Key("left") + Text("\""),
"escape single quotes": Text("\ ")+ Key("left") + Text("\'") + Text("\ ")+ Key("left") + Text("\'"),
"escape line": Text("\ ")+ Key("left") + Text("n"),
"escape tab": Text("\ ")+ Key("left") + Text("t"),
"escape carriage return": Text("\ ")+ Key("left") + Text("r"),
}
CPPBootstrap = Grammar("C++ bootstrap") # Create a grammar to contain the command rule.
CPPBootstrap.add_rule(CPPEnabler())
CPPBootstrap.load()
CPPGrammar = Grammar("C++ grammar")
CPPGrammar.add_rule(CPPTestRule())
CPPGrammar.add_rule(CPPControlStructures())
CPPGrammar.add_rule(CPPCommentsSyntax())
CPPGrammar.add_rule(CPPUsefulFunctions())
CPPGrammar.add_rule(CPPPreprocessorDirectives())
CPPGrammar.add_rule(CPPOperators())
CPPGrammar.add_rule(CPPEscapeSequences())
CPPGrammar.add_rule(CPPFunctionsAndClassesSyntax())
CPPGrammar.add_rule(CPPDataTypes())
CPPGrammar.add_rule(CPPDisabler())
CPPGrammar.load()
CPPGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global CPPGrammar
if CPPGrammar: CPPGrammar.unload()
CPPGrammar = None

186
_cs_grammar.py Normal file
View File

@ -0,0 +1,186 @@
# Author:Brandon Lovrien
# This script includes the macros for the C# programming language
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Integer)
class CSEnabler(CompoundRule):
spec = "Enable C sharp" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
csBootstrap.disable()
csGrammar.enable()
print "C# grammar enabled"
class CSDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
csGrammar.disable()
csBootstrap.enable()
print "C# grammar disabled"
# This is a test rule to see if the C# grammar is enabled
class CSTestRule(CompoundRule):
spec = "test C sharp" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "C# grammar tested"
# Handles C# commenting syntax
class CSCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") + Key("enter") + Text("*/") + Key("up")
}
# Deals with printing C# datatypes
class CSDataTypes(MappingRule):
mapping = {
"integer": Text("int "),
"float": Text("float "),
"float <n>": Text("float%(n)d "),
"double": Text("double "),
"boolean": Text("bool "),
"char": Text("char "),
"string": Text("string "),
"long": Text("long ")
}
extras = [
Integer("n", 0, 64)
]
# This rule deals with the C# comparison operators
class CSComparisonOperators(MappingRule):
mapping = {
"equal to": Text("=="),
"not equal to": Text("!="),
"greater than": Text(">"),
"less than": Text("<"),
"less than or equal to": Text("<="),
"greater than or equal to": Text(">="),
}
# This rule deals with the C# Boolean operators
class CSBooleanOperators(MappingRule):
mapping = {
"logical and": Text("&&"),
"logical or": Text("||"),
"true": Text("true"),
"false": Text("false"),
"not": Text("!")
}
class CSControlStructures(MappingRule):
mapping = {
"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("}"),
"for each loop": Text("foreach() {") + Key("enter")+ Key("enter") + Text("}"),
"switch statement": Text("switch() {") + Key("enter")+ Key("enter") + Text("}"),
"try catch": Text("try {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("catch(Exception e) {") + Key("enter")+ Key("enter") + Text("}"),
"class": Text("<access modifier> class ClassName {") + Key("enter")+ Key("enter") + Text("}"),
"interface": Text("<access modifier> interface InterfaceName {") + Key("enter")+ Key("enter") + Text("}"),
"enumeration": Text("<access modifier> enum EnumName {") + Key("enter")+ Key("enter") + Text("}"),
"method": Text("<datatype> methodName() {") + Key("enter") + Key("enter") + Text("}"),
}
# This rule provides some useful method calls in C#
class CSUsefulMethods(MappingRule):
mapping = {
"print statement": Text("Console.WriteLine()") + Key("left"),
}
# This rule deals with some of the C# arithmetic operators
class CSArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
"multiplied by": Text("*"),
"plus": Text("+"),
"minus": Text("-"),
"divided by": Text("/"),
"modulus": Text("%") #causes some weird problem in dragonfly so this doesn't work, use "percent sign" instead
}
class CSAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
}
class CSMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"new": Text("new "),
}
class CSAccessModifiers(MappingRule):
mapping = {
"public": Text("public "),
"private": Text("private "),
"protected": Text("protected ")
}
class CSEscapeSequences(MappingRule):
mapping = {
"escape quotes": Text("\ ")+ Key("left") + Text("\"") + Text("\ ")+ Key("left") + Text("\""),
"escape single quotes": Text("\ ")+ Key("left") + Text("\'") + Text("\ ")+ Key("left") + Text("\'"),
"escape line": Text("\ ")+ Key("left") + Text("n"),
"escape tab": Text("\ ")+ Key("left") + Text("t"),
"escape carriage return": Text("\ ")+ Key("left") + Text("r"),
}
# The main C# grammar rules are activated here
csBootstrap = Grammar("C sharp bootstrap")
csBootstrap.add_rule(CSEnabler())
csBootstrap.load()
csGrammar = Grammar("C sharp grammar")
csGrammar.add_rule(CSTestRule())
csGrammar.add_rule(CSCommentsSyntax())
csGrammar.add_rule(CSDataTypes())
csGrammar.add_rule(CSComparisonOperators())
csGrammar.add_rule(CSBooleanOperators())
csGrammar.add_rule(CSControlStructures())
csGrammar.add_rule(CSUsefulMethods())
csGrammar.add_rule(CSArithmeticOperators())
csGrammar.add_rule(CSAssignmentOperators())
csGrammar.add_rule(CSMiscellaneousStuff())
csGrammar.add_rule(CSAccessModifiers())
csGrammar.add_rule(CSEscapeSequences())
csGrammar.add_rule(CSDisabler())
csGrammar.load()
csGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global csGrammar
if csGrammar: csGrammar.unload()
csGrammar = None

84
_css_grammar.py Normal file
View File

@ -0,0 +1,84 @@
# Author:Brandon Lovrien
# This script includes commands used for CSS coding
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice, Integer, Function)
# Voice command rule for "middle-slash" naming convention.
def middle_slash_format(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
printer = Text(someString.replace(' ', '-'))
printer.execute()
class CSSEnabler(CompoundRule):
spec = "Enable CSS" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
cssBootstrap.disable()
cssGrammar.enable()
print "CSS grammar enabled"
class CSSDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
cssGrammar.disable()
cssBootstrap.enable()
print "CSS grammar disabled"
class CSSTestRule(CompoundRule):
spec = "test CSS" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "CSS grammar tested"
class CSSSelectors(MappingRule):
mapping = {
"ID selector": Text("#idName")+ Key("enter") + Text("{\n\n}"),
"class selector": Text(".className")+ Key("enter") + Text("{\n\n}"),
"tag selector": Text("tagName")+ Key("enter") + Text("{\n\n}"),
# I know there are more types of selectors in CSS but these are the most common
}
class CSSValues(MappingRule):
mapping = {
"<value> (pixels | pixel)": Text("%(value)dpx"),
"<value> (points | point)": Text("%(value)dpt"),
}
extras = [
Integer("value", 0, 800),
]
class CSSTags(MappingRule):
mapping = {
"property <command>": Function(middle_slash_format) + Text(":;") + Key("left"),
"comment": Text("/* */"),
}
extras = [
Dictation("command"),
]
# Code for initial setup of the HTML grammar
cssBootstrap = Grammar("css bootstrap") # Create a grammar to contain the command rule.
cssBootstrap.add_rule(CSSEnabler())
cssBootstrap.load()
cssGrammar = Grammar("css grammar")
cssGrammar.add_rule(CSSTestRule())
cssGrammar.add_rule(CSSDisabler())
cssGrammar.add_rule(CSSValues())
cssGrammar.add_rule(CSSSelectors())
cssGrammar.add_rule(CSSTags())
cssGrammar.load()
cssGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global cssGrammar
if cssGrammar: cssGrammar.unload()
cssGrammar = None

23
_custom_globals.py Normal file
View File

@ -0,0 +1,23 @@
# 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)
# Useful commands for encapsulation of quotes, etc.
class UsefulStuff(MappingRule):
mapping = {
"in quotes": Text("\"\"") + Key("left"),
"in single quotes": Text("\'\'") + Key("left"),
"in parentheses": Text("()") + Key("left"),
"in brackets": Text("[]") + Key("left"),
"in braces": Text("{}") + Key("left"),
"in angle brackets": Text("<>") + Key("left"),
"parameters": Text("()"),
"arrow": Text("->"),
"double arrow": Text("=>"),
}
globalStuff = Grammar("useful custom global commands") # Create a grammar to contain the command rule.
globalStuff.add_rule(UsefulStuff())
globalStuff.load()

36
_hello_world_aenea.py Normal file
View File

@ -0,0 +1,36 @@
# 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

188
_html_grammar.py Normal file
View File

@ -0,0 +1,188 @@
# Author:Brandon Lovrien
# This script includes commands used for HTML coding
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
class HTMLEnabler(CompoundRule):
spec = "Enable HTML" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
htmlBootstrap.disable()
htmlGrammar.enable()
print "HTML grammar enabled"
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"
class HTMLTestRule(CompoundRule):
spec = "test HTML" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "HTML grammar tested"
class HTMLTags(MappingRule):
mapping = {
"doc type": Text("<!DOCTYPE HTML>"),
"comment": Text( "<!---->" ) + Key( "left" ) + Key( "left" ) + Key( "left" ),
"tags": Text("<>") + Text("</>"),
"single tag": Text("</>"),
"line break": Text( "<br />" ),
"image": Text( "<img />" ),
"equals": Text( "=" ),
"<tagname> tags": Text("<%(tagname)s>") ,#+ Text("</%(tagname)s>"),
# used to specify tag attributes
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
"attribute <attribute>": Text( ' %(attribute)s=""' ) + Key( "left" ),
}
extras = [
Choice("attribute", {
"ID": "id",
"class": "class",
"style": "style",
"title": "title",
"SRC": "src",
"HREF": "href",
}
),
Choice("tagname", {
"anchor": "a",
"abbreviation": "abbr",
"address": "address",
"area": "area",
"article": "article",
"aside": "aside",
"audio": "audio",
"bold": "b",
"base": "base",
"BDI": "bdi",
"BDO": "bdo",
"block quote": "blockquote",
"body": "body",
"button": "button",
"Canvas": "canvas",
# means the same thing and represents a table caption
"caption": "caption", "table caption": "caption",
"cite": "cite",
"code": "code",
"table column": "col",
"table column group": "colgroup",
"command": "command",
"data list": "datalist",
"definition description": "dd",
"del": "del",
"details": "details",
"dfn": "dfn",
"div": "div",
"dl": "dl",
"dt": "dt",
"em": "em",
"embed": "embed",
"field set": "fieldset",
"figure caption": "figcaption",
"figure": "figure",
"footer": "footer",
"form": "form",
"H1": "h1",
"H2": "h2",
"H3": "h3",
"H4": "h4",
"H5": "h5",
"H6": "h6",
"head": "head",
"H group": "hgroup",
"HR": "hr",
"HTML": "html",
"I": "i",
"I frame": "iframe",
"input": "input",
"INS": "ins",
"key gen": "keygen",
"KBD": "kbd",
"label": "label",
"legend": "legend",
"list item": "li",
"Link": "link",
"Mark": "mark",
"menu": "menu",
"meta": "meta",
"meter": "meter",
"nav": "nav",
"no script": "noscript",
"object": "object",
"ordered list": "ol",
"option group": "optgroup",
"option": "option",
"output": "output",
"p": "p",
"parameter": "param",
"pre": "pre",
"progress": "progress",
"g": "g",
"RP": "rp",
"RT": "rt",
"Ruby": "ruby",
"s": "s",
"sample": "samp",
"script": "script",
"section": "section",
"select": "select",
"small": "small",
"source": "source",
"span": "span",
"strong": "strong",
"style": "style",
"sub": "sub",
"summary": "summary",
"superscript": "sup",
"table": "table",
"T body": "tbody",
# means the same thing and represents a table cell
"TD": "td", "table cell": "td",
"textarea": "textarea",
"T foot": "tfoot",
# means the same thing and represents a table header
"TH": "th", "table header": "th",
"T head": "thead",
"time": "time",
"title": "title",
# means the same thing and represents a table row
"table row": "tr", "TR": "tr",
"track": "track",
"unordered list": "ul",
"variable": "var",
"video": "video",
"label": "label",
}
)
]
# Code for initial setup of the HTML grammar
htmlBootstrap = Grammar("html bootstrap") # Create a grammar to contain the command rule.
htmlBootstrap.add_rule(HTMLEnabler())
htmlBootstrap.load()
htmlGrammar = Grammar("html grammar")
htmlGrammar.add_rule(HTMLTestRule())
htmlGrammar.add_rule(HTMLDisabler())
htmlGrammar.add_rule(HTMLTags())
htmlGrammar.load()
htmlGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global htmlGrammar
if htmlGrammar: htmlGrammar.unload()
htmlGrammar = None

181
_java_grammar.py Normal file
View File

@ -0,0 +1,181 @@
# Author:Brandon Lovrien
# This script includes commands that are useful for the Java programming language
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule)
class JavaEnabler(CompoundRule):
spec = "Enable Java" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
javaBootstrap.disable()
javaGrammar.enable()
print "Java grammar enabled"
class JavaDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
javaGrammar.disable()
javaBootstrap.enable()
print "Java grammar disabled"
# This is a test rule to see if the Java grammar is enabled
class JavaTestRule(CompoundRule):
spec = "test Java" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "Java grammar tested"
# Handles Java commenting syntax
class JavaCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
}
# Deals with printing Java datatypes
class JavaDataTypes(MappingRule):
mapping = {
"integer": Text("int "),
"float": Text("float "),
"double": Text("double "),
"boolean": Text("boolean "),
"char": Text("char "),
"string": Text("String "),
"long": Text("long ")
}
# This rule deals with the Java comparison operators
class JavaComparisonOperators(MappingRule):
mapping = {
"equal to": Text("=="),
"not equal to": Text("!="),
"greater than": Text(">"),
"less than": Text("<"),
"less than or equal to": Text("<="),
"greater than or equal to": Text(">="),
}
# This rule deals with the Java Boolean operators
class JavaBooleanOperators(MappingRule):
mapping = {
"logical and": Text("&&"),
"logical or": Text("||"),
"true": Text("true"),
"false": Text("false"),
"not": Text("!")
}
class JavaControlStructures(MappingRule):
#note: the last curly braces were commented out so that these commands properly work with the auto formatting of the eclipse IDE.
mapping = {
"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("}"),
"try catch": Text("try {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("catch(Exception e) {") + Key("enter")+ Key("enter"), #+ Text("}"),
"class": Text("<access modifier> class ClassName {") + Key("enter")+ Key("enter"), #+ Text("}"),
"interface": Text("<access modifier> interface InterfaceName {") + Key("enter")+ Key("enter"), #+ Text("}"),
"enumeration": Text("<access modifier> enum EnumName {") + Key("enter")+ Key("enter"), #+ Text("}")
"method": Text("<datatype> methodName() {") + Key("enter")+ Key("enter"), #+ Text("}"),
}
# This rule provides some useful method calls in Java
class JavaUsefulMethods(MappingRule):
mapping = {
"print statement": Text("System.out.println()") + Key("left")
}
# This rule deals with some of the Java arithmetic operators
class JavaArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
"multiplied by": Text("*"),
"plus": Text("+"),
"minus": Text("-"),
"divided by": Text("/"),
"modulus": Text("%") #causes some weird problem in dragonfly so this doesn't work, use "percent sign" instead
}
class JavaAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
}
class JavaMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"import": Text("import ;") + Key("left"),
"new": Text("new "),
}
class JavaAccessModifiers(MappingRule):
mapping = {
"public": Text("public "),
"private": Text("private "),
"protected": Text("protected ")
}
class JavaEscapeSequences(MappingRule):
mapping = {
"escape quotes": Text("\ ")+ Key("left") + Text("\"") + Text("\ ")+ Key("left") + Text("\""),
"escape single quotes": Text("\ ")+ Key("left") + Text("\'") + Text("\ ")+ Key("left") + Text("\'"),
"escape line": Text("\ ")+ Key("left") + Text("n"),
"escape tab": Text("\ ")+ Key("left") + Text("t"),
"escape carriage return": Text("\ ")+ Key("left") + Text("r"),
}
# The main Java grammar rules are activated here
javaBootstrap = Grammar("java bootstrap")
javaBootstrap.add_rule(JavaEnabler())
javaBootstrap.load()
javaGrammar = Grammar("java grammar")
javaGrammar.add_rule(JavaTestRule())
javaGrammar.add_rule(JavaCommentsSyntax())
javaGrammar.add_rule(JavaDataTypes())
javaGrammar.add_rule(JavaComparisonOperators())
javaGrammar.add_rule(JavaBooleanOperators())
javaGrammar.add_rule(JavaControlStructures())
javaGrammar.add_rule(JavaUsefulMethods())
javaGrammar.add_rule(JavaArithmeticOperators())
javaGrammar.add_rule(JavaAssignmentOperators())
javaGrammar.add_rule(JavaMiscellaneousStuff())
javaGrammar.add_rule(JavaAccessModifiers())
javaGrammar.add_rule(JavaEscapeSequences())
javaGrammar.add_rule(JavaDisabler())
javaGrammar.load()
javaGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global javaGrammar
if javaGrammar: javaGrammar.unload()
javaGrammar = None

155
_javascript_grammar.py Normal file
View File

@ -0,0 +1,155 @@
# Author:Brandon Lovrien
# This script includes commands that are to be used for JavaScript 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 JavaScriptEnabler(CompoundRule):
spec = "Activate JS" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
JavaScriptBootstrap.disable()
JavaScriptGrammar.enable()
s = "JavaScript grammar enabled"
print s
speaker.Speak(s)
class JavaScriptDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
JavaScriptGrammar.disable()
JavaScriptBootstrap.enable()
s = "JavaScript grammar disabled"
print s
speaker.Speak(s)
class JavaScriptTestRule(CompoundRule):
spec = "test JavaScript" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "JavaScript grammar tested"
class JavaScriptControlStructures(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("}"),
"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 = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
}
class JavaScriptMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"new": Text("new "),
}
class JavaScriptComparisonOperators(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 JavaScriptArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
}
class JavaScriptAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
"modulus equals": Text("%="),
}
JavaScriptBootstrap = Grammar("JavaScript bootstrap") # Create a grammar to contain the command rule.
JavaScriptBootstrap.add_rule(JavaScriptEnabler())
JavaScriptBootstrap.load()
JavaScriptGrammar = Grammar("JavaScript grammar")
JavaScriptGrammar.add_rule(JavaScriptTestRule())
JavaScriptGrammar.add_rule(JavaScriptControlStructures())
JavaScriptGrammar.add_rule(JavaScriptCommentsSyntax())
JavaScriptGrammar.add_rule(JavaScriptMiscellaneousStuff())
JavaScriptGrammar.add_rule(JavaScriptComparisonOperators())
JavaScriptGrammar.add_rule(JavaScriptArithmeticOperators())
JavaScriptGrammar.add_rule(JavaScriptAssignmentOperators())
JavaScriptGrammar.add_rule(JavaScriptDisabler())
JavaScriptGrammar.load()
JavaScriptGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global JavaScriptGrammar
if JavaScriptGrammar: JavaScriptGrammar.unload()
JavaScriptGrammar = None

136
_namingcon.py Normal file
View File

@ -0,0 +1,136 @@
"""
Author:Jeremy Hayes
Modified from: Brandon Lovrien version
Command module for programming variable naming conventions
==========================================================
"""
from dragonfly import *
# helper function handling "camelBack"
def camel_back(command):
someString = str(command)
lowerString = someString.lower()
words = lowerString.split()
finalString = ""
isFirst = 1
for word in words:
if isFirst == 1:
finalString = finalString + word
isFirst = 0
else:
finalString = finalString + word.title()
printer = Text(finalString)
printer.execute()
# Voice command rule for "Camel" naming convention.
def camel_format(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
upperString = someString.title()
printer = Text(upperString.replace(' ', ''))
printer.execute()
# Voice command rule for "middle_underscores" naming convention.
def middle_underscores(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
printer = Text(someString.replace(' ', '_'))
printer.execute()
# Voice command rule for "dot.notation" naming convention.
def dot_notation(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
printer = Text(someString.replace(' ', '.'))
printer.execute()
# Voice command rule for "_BEGINNING_UNDERSCORES" naming convention.
def _BEGINNING_UNDERSCORES(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
upperString = "_" + someString.upper()
printer = Text(upperString.replace(' ', '_'))
printer.execute()
# Voice command rule for "middle-slash" naming convention.
def middle_slash_format(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
printer = Text(someString.replace(' ', '-'))
printer.execute()
# Voice command rule for "spacefree" naming convention.
def SpaceFreeFormat(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
printer = Text(someString.replace(' ', ''))
printer.execute()
class ProgrammingNamingConventions(MappingRule):
mapping = {
#both of these commands do the same thing in terms of name formatting example: testValue
"var <command>": Function(camel_back),
"var <command> <symbol>": Function(camel_back) + Text("%(symbol)s"),
"<symbol> var <command>": Text("%(symbol)s") + Function(camel_back),
"camelback <command>": Function(camel_back),
"camelback <command> <symbol>": Function(camel_back) + Text("%(symbol)s"),
"<symbol> camelback <command>": Text("%(symbol)s") + Function(camel_back),
#this command capitalizes the 1st letter of each word and removes spaces example: TestValue
"camel <command>": Function(camel_format),
"camel <command> <symbol>": Function(camel_format) + Text("%(symbol)s"),
"<symbol> camel <command>": Text("%(symbol)s") + Function(camel_format),
#this command replaces spaces between words with underscores example:test_value
"middle under <command>": Function(middle_underscores),
"middle under <command> <symbol>": Function(middle_underscores) + Text("%(symbol)s"),
"<symbol> middle under <command>": Text("%(symbol)s") + Function(middle_underscores),
#this command replaces spaces between words with dots example:test.value
"dot notation <command>": Function(dot_notation),
"dot notation <command> <symbol>": Function(dot_notation) + Text("%(symbol)s"),
"<symbol> dot notation <command>": Text("%(symbol)s") + Function(dot_notation),
#example of this command: _TEST_VALUE
"beginning under <command>": Function(_BEGINNING_UNDERSCORES),
"beginning under <command> <symbol>": Function(_BEGINNING_UNDERSCORES) + Text("%(symbol)s"),
"<symbol> beginning under <command>": Text("%(symbol)s") + Function(_BEGINNING_UNDERSCORES),
#example of this command: test-value
"middle lines <command>": Function(middle_slash_format),
"middle lines <command> <symbol>": Function(middle_slash_format) + Text("%(symbol)s"),
"<symbol> middle lines <command>": Text("%(symbol)s") + Function(middle_slash_format),
# example of this command: testvalue
"space free <command>": Function(SpaceFreeFormat),
"space free <command> <symbol>": Function(SpaceFreeFormat) + Text("%(symbol)s"),
"<symbol> space free <command>": Text("%(symbol)s") + Function(SpaceFreeFormat),
}
extras = [
Dictation("command"),
Choice("symbol",{
"dot":".",
"arrow":"->",
"parameters":"()",
"parameters dot":"()."
}
)
]
# Create a grammar which contains and loads the command rule.
naminggrammar = Grammar("naming conventions") # Create a grammar to contain the command rule.
naminggrammar.add_rule(ProgrammingNamingConventions())
naminggrammar.load()

203
_php_grammar.py Normal file
View File

@ -0,0 +1,203 @@
# Author:Brandon Lovrien
# This script includes commands that are to be used for programming in the PHP programming language
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule)
class PHPEnabler(CompoundRule):
spec = "Enable PHP" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
phpBootstrap.disable()
phpGrammar.enable()
print "PHP grammar enabled"
class PHPDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
phpGrammar.disable()
phpBootstrap.enable()
print "PHP grammar disabled"
class PHPTestRule(CompoundRule):
spec = "test PHP" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "PHP grammar tested"
# Deals with printing PHP datatypes
class PHPDataTypes(MappingRule):
mapping = {
"integer": Text("int"),
"float": Text("float"),
"boolean": Text("boolean"),
"string": Text("string"),
"object": Text("object"),
"null": Text("NULL")
}
class PHPVariableDeclarations(MappingRule):
mapping = {
"variable": Text("$")
}
# Handles PHP commenting syntax
class PHPCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") + Key("enter") + Text("*/") + Key("up")
}
class PHPSuperGlobals(MappingRule):
mapping = {
"globals": Text("$GLOBALS['']"),
"post": Text("$_POST['']"),
"get": Text("$_GET['']"),
"files": Text("$_FILES['']"),
"cookie": Text("$_COOKIE['']"),
"session": Text("$_SESSION['']"),
"request": Text("$_REQUEST['']"),
"environment": Text("$_ENV['']")
}
class PHPControlStructures(MappingRule):
mapping = {
"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("elseif() {") + Key("enter")+ Key("enter") + Text("}"),
"for loop": Text("for(;;) {") + Key("enter")+ Key("enter") + Text("}"),
"for each loop": Text("for(<array> as [<value> |<key> => <value>]) {") + 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()"),
"switch statement": Text("switch() {") + Key("enter")+ Key("enter") + Text("}"),
"try catch": Text("try {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("catch(<ExceptionClass> e) {") + Key("enter")+ Key("enter") + Text("}"),
"function": Text("function functionName() {") + Key("enter")+ Key("enter") + Text("}"),
"class": Text("class ClassName {") + Key("enter")+ Key("enter") + Text("}")
}
class PHPAccessModifiers(MappingRule):
mapping = {
"public": Text("public "),
"private": Text("private "),
"static": Text("static ")
}
class PHPUsefulMethods(MappingRule):
mapping = {
"print statement": Text("echo \"\"") + Key("left")
}
class PHPLogicalOperators(MappingRule):
mapping = {
"logical and": Text("&&"),
"logical or": Text("||"),
"true": Text("true"),
"false": Text("false"),
"not": Text("!"),
"logical exclusive or": Text("xor")
}
class PHPAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
".equals": Text(".=")
}
class PHPArithmeticOperators(MappingRule):
mapping = {
"multiplied by": Text("*"),
"plus": Text("+"),
"minus": Text("-"),
"divided by": Text("/"),
"modulus": Text("%") #causes some weird problem in dragonfly so this doesn't work, use "percent sign" instead
}
class PHPEscapeSequences(MappingRule):
mapping = {
"escape quotes": Text("\ ")+ Key("left") + Text("\"") + Text("\ ")+ Key("left") + Text("\""),
"escape single quotes": Text("\ ")+ Key("left") + Text("\'") + Text("\ ")+ Key("left") + Text("\'"),
"escape line": Text("\ ")+ Key("left") + Text("n"),
"escape tab": Text("\ ")+ Key("left") + Text("t"),
"escape carriage return": Text("\ ")+ Key("left") + Text("r"),
}
class PHPComparisonOperators(MappingRule):
mapping = {
"equal to": Text("=="),
"not equal to": Text("!="),
"equal to type comparison": Text("==="),
"not equal to type comparison": Text("!=="),
"greater than": Text(">"),
"less than": Text("<"),
"less than or equal to": Text("<="),
"greater than or equal to": Text(">="),
}
class PHPMiscellaneousStuff(MappingRule):
mapping = {
"PHP block": Text("<?php ?>"),
"require": Text("require ('');"),
"require once": Text("require_once ('');"),
"include": Text("include ('');"),
"include once": Text("require_once ('');"),
"equals": Text(" = "),
}
phpBootstrap = Grammar("php bootstrap") # Create a grammar to contain the command rule.
phpBootstrap.add_rule(PHPEnabler())
phpBootstrap.load()
phpGrammar = Grammar("php grammar")
phpGrammar.add_rule(PHPTestRule())
phpGrammar.add_rule(PHPDataTypes())
phpGrammar.add_rule(PHPVariableDeclarations())
phpGrammar.add_rule(PHPCommentsSyntax())
phpGrammar.add_rule(PHPSuperGlobals())
phpGrammar.add_rule(PHPControlStructures())
phpGrammar.add_rule(PHPAccessModifiers())
phpGrammar.add_rule(PHPUsefulMethods())
phpGrammar.add_rule(PHPLogicalOperators())
phpGrammar.add_rule(PHPAssignmentOperators())
phpGrammar.add_rule(PHPArithmeticOperators())
phpGrammar.add_rule(PHPEscapeSequences())
phpGrammar.add_rule(PHPComparisonOperators())
phpGrammar.add_rule(PHPMiscellaneousStuff())
phpGrammar.add_rule(PHPDisabler())
phpGrammar.load()
phpGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global phpGrammar
if phpGrammar: phpGrammar.unload()
phpGrammar = None

71
_python_grammar.py Normal file
View File

@ -0,0 +1,71 @@
# Author:Brandon Lovrien
# This script is to be used for programming in the Python programming language
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule)
class PythonEnabler(CompoundRule):
spec = "Enable Python" # Spoken command to enable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonBootstrap.disable()
pythonGrammar.enable()
print "Python grammar enabled"
class PythonDisabler(CompoundRule):
spec = "switch language" # spoken command to disable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonGrammar.disable()
pythonBootstrap.enable()
print "Python grammar disabled"
# This is a test rule to see if the Python grammar is enabled
class PythonTestRule(CompoundRule):
spec = "test Python" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
print "Python grammar tested"
# Handles Python commenting syntax
class PythonCommentsSyntax(MappingRule):
mapping = {
"comment": Text("# "),
}
# handles Python control structures
class PythonControlStructures(MappingRule):
mapping = {
"if": Text("if condition:") + Key("enter"),
"while loop": Text("while condition:") + Key("enter"),
"for loop": Text("for something in something:") + Key("enter"),
"function": Text("def functionName():") + Key("enter"),
"class": Text("class className(inheritance):") + Key("enter"),
}
# The main Python grammar rules are activated here
pythonBootstrap = Grammar("python bootstrap")
pythonBootstrap.add_rule(PythonEnabler())
pythonBootstrap.load()
pythonGrammar = Grammar("python grammar")
pythonGrammar.add_rule(PythonTestRule())
pythonGrammar.add_rule(PythonCommentsSyntax())
pythonGrammar.add_rule(PythonControlStructures())
pythonGrammar.add_rule(PythonDisabler())
pythonGrammar.load()
pythonGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global pythonGrammar
if pythonGrammar: pythonGrammar.unload()
pythonGrammar = None

1
server_state.json Normal file
View File

@ -0,0 +1 @@
{"host": "localhost", "port": 8240}