scala
This directory provides comprehensive support for the Scala programming language within the Talon voice recognition ecosystem. It defines the syntax mappings, keywords, modifiers, type lists, and standard code actions necessary to write Scala code efficiently using voice commands.
The implementation consists of two core files working in tandem:
- scala.py registers the Scala context, defines the programming vocabulary (types, modifiers, keywords), sets up standard code operators, and overrides generalized coding actions.
- scala.talon activates relevant language tags, configures local code formatting settings, and maps voice commands to keywords, modifiers, and specialized Scala-specific operators.
Structural Overview
Type, Keyword, and Modifier Management
scala.py defines lists for Scala's type system, keywords, and access modifiers, mapping spoken phrases to their respective code representations:
- Scala Types: Populates the standard
user.code_typelist with both common scalar types (such asInt,Boolean,Double,Unit) and generic/collection types (likeArray,List,Map,Option,Seq,Try). - Modifiers: Maps access modifiers like
public,private, andprotectedtouser.scala_modifier. - Keywords: Exposes common Scala keywords to the
user.scala_keywordlist, covering structural and control-flow syntax (e.g.,case class,def,implicit,lazy val,trait,yield).
These lists are exposed to the Talon engine, enabling voice triggers in scala.talon to insert modifiers or keywords dynamically using syntax-aware states:
state {user.scala_modifier}: insert("{user.scala_modifier} ")
state {user.scala_keyword}: insert("{scala_keyword} ")
Formatting and Function Creation
The module overrides global programming actions (UserActions) to conform to Scala-specific conventions:
- Function Formatting: Defines default naming conventions. It sets
user.code_private_function_formatter,user.code_protected_function_formatter, anduser.code_public_function_formattertoPRIVATE_CAMEL_CASEin scala.talon. - Method Declarations: Implements helper actions for generating method signatures. For instance,
code_private_functioninsertsprivate def <name>(), formats the function name appropriately, and places the cursor within the parameter parentheses. - Type Annotations: Customizes type constraints and returns, inserting
: Typeas required by Scala's static typing style.
Code Operators
Operators are registered in scala.py by populating the standard Operators structure. This covers:
- Assignment (e.g.,
=,+=,&=) - Bitwise operations (e.g.,
~,&,|,<<) - Mathematical evaluations (e.g.,
+,-,==,!=) - Lambda expressions, mapping
LAMBDAto the Scala fat arrow=>
Additional operators unique to Scala or common in functional paradigms are declared directly in scala.talon:
op right arrowoutputs->(commonly used in Map initializations or pattern matching)op left arrowoutputs<-(used in generator expressions withinforcomprehensions)op subtypeoutputs<:(for upper type bounds)block stringhelper outputs""""""and positions the cursor inside for writing multi-line raw strings.