Skip to content

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_type list with both common scalar types (such as Int, Boolean, Double, Unit) and generic/collection types (like Array, List, Map, Option, Seq, Try).
  • Modifiers: Maps access modifiers like public, private, and protected to user.scala_modifier.
  • Keywords: Exposes common Scala keywords to the user.scala_keyword list, 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, and user.code_public_function_formatter to PRIVATE_CAMEL_CASE in scala.talon.
  • Method Declarations: Implements helper actions for generating method signatures. For instance, code_private_function inserts private def <name>(), formats the function name appropriately, and places the cursor within the parameter parentheses.
  • Type Annotations: Customizes type constraints and returns, inserting : Type as 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 LAMBDA to the Scala fat arrow =>

Additional operators unique to Scala or common in functional paradigms are declared directly in scala.talon:

  • op right arrow outputs -> (commonly used in Map initializations or pattern matching)
  • op left arrow outputs <- (used in generator expressions within for comprehensions)
  • op subtype outputs <: (for upper type bounds)
  • block string helper outputs """""" and positions the cursor inside for writing multi-line raw strings.