From 3fb7754bb26ba7926897715f53210d4727ff5720 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 9 Aug 2019 17:30:37 -0500 Subject: [PATCH] julia grammar started --- _julia_grammar.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 _julia_grammar.py diff --git a/_julia_grammar.py b/_julia_grammar.py new file mode 100644 index 0000000..a8c702f --- /dev/null +++ b/_julia_grammar.py @@ -0,0 +1,71 @@ +# Author:Brandon Lovrien +# This script is to be used for programming in the Julia programming language + +from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule) + +class JuliaEnabler(CompoundRule): + spec = "Enable Julia" # Spoken command to enable the Julia grammar. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + JuliaBootstrap.disable() + JuliaGrammar.enable() + print "Julia grammar enabled" + +class JuliaDisabler(CompoundRule): + spec = "switch language" # spoken command to disable the Julia grammar. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + JuliaGrammar.disable() + JuliaBootstrap.enable() + print "Julia grammar disabled" + +# This is a test rule to see if the Julia grammar is enabled +class JuliaTestRule(CompoundRule): + spec = "test Julia" # Spoken form of command. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + print "Julia grammar tested" + +# Handles Julia commenting syntax +class JuliaCommentsSyntax(MappingRule): + + mapping = { + "comment": Text("# "), + + + } + + +# handles Julia control structures +class JuliaControlStructures(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("function functionName()") + Key("enter") + Key("enter") + Text("end"), + "class": Text("class className(inheritance):") + Key("enter"), + + + } + + +# The main Julia grammar rules are activated here +JuliaBootstrap = Grammar("Julia bootstrap") +JuliaBootstrap.add_rule(JuliaEnabler()) +JuliaBootstrap.load() + +JuliaGrammar = Grammar("Julia grammar") +JuliaGrammar.add_rule(JuliaTestRule()) +JuliaGrammar.add_rule(JuliaCommentsSyntax()) +JuliaGrammar.add_rule(JuliaControlStructures()) +JuliaGrammar.add_rule(JuliaDisabler()) +JuliaGrammar.load() +JuliaGrammar.disable() + + +# Unload function which will be called by natlink at unload time. +def unload(): + global JuliaGrammar + if JuliaGrammar: JuliaGrammar.unload() + JuliaGrammar = None