Skip to content

c

This directory provides robust voice-programming capabilities for the C programming language within the Talon voice navigation ecosystem. It translates spoken commands into valid C syntax, covering standard types, standard library functions, control structures, pointer manipulations, and preprocessor directives.

By separating python-based syntactic parsing, voice-command rules, and vocabulary datasets, this module ensures high flexibility, ease of maintenance, and partial interoperability with companion languages like C++.

Architectural Overview

The core of the C language support is divided into three key areas:

  1. Context and Action Definition (c.py): Defines custom AST captures, contextual actions (e.g., how to insert null pointers, generate function signatures, and handle boolean states), and language-specific operators.
  2. Command Mappings (c.talon): Declares the voice syntax used to invoke C structures, including standard library headers, preprocessor macros, type casting, variable declarations, and formatting rules.
  3. Domain-Specific Vocabulary (Talon Lists): A collection of .talon-list files containing specialized vocabularies—such as standard functions, type prefixes, and common headers—designed to optimize voice recognition accuracy.

Language Setup and Execution Flow

Context and Operators

The python file c.py registers contexts for code.language: c and code.language: cpp. It overrides the global user actions to return a heavily customized Operators container. This handles C-specific spacing, assignment operators (such as +=, &=, <<=), pointer modifiers (->, *, &), and comparison operations.

Furthermore, c.py defines how private/static functions are typed out based on active formatter settings, ensuring that when a user declares a function, it dynamically conforms to the snake_case rules defined in c.talon:

settings():
    user.code_private_function_formatter = "SNAKE_CASE"

Type and Cast Parsing

To construct variables or perform casts via voice, c.py leverages capture rules that dynamically group elements from the user's spoken input. These captures combine lists describing signedness, base types, and pointer levels:

  • Variable Declarations: The custom capture <user.c_variable> allows users to say combinations of pointers, signed modifiers, and data types (e.g., unsigned int *). In c.talon, this is combined with formatters to instantiate formatted variable names on the fly:

talon <user.c_variable> <phrase>: insert("{c_variable} ") insert(user.formatted_text(phrase, "PRIVATE_CAMEL_CASE,NO_SPACES"))

  • Type Casts: Captured by <user.c_cast> or <user.stdint_cast>, these commands wrap type declarations in standard parentheses, converting spoken utterances like "cast to unsigned char pointer" into (unsigned char *).

Vocabulary Lists

The following lists supply the parser with language-specific vocabularies.

Standard and Extended Types

Language Keywords and Controls

Standard Library Support

  • code_common_function.talon-list: Maps common library functions from headers such as <string.h>, <stdlib.h>, and <stdio.h>. Pronunciations like "mem copy" map cleanly to memcpy, "print eff" to printf, and "re alloc" to realloc.
  • code_libraries.talon-list: Maps voice terms for headers (e.g., "standard int" to stdint.h or "math" to math.h). Spoken words trigger automated, context-aware inclusion in c.talon:

talon include <user.code_libraries>: user.code_insert_library(code_libraries, "") key(end enter)


Preprocessor and Macro Integration

The rules in c.talon define several voice shortcuts for handling the C preprocessor. It relies on standard system snippet hooks (defined globally in the parent repository) to generate macros dynamically:

  • Includes: state include parses local and system-level #include structures.
  • Conditional compilation: Syntaxes for block-level conditionals (state pre if, state pre else if, state pre end, and state if define <user.text>) automate the construction of #if, #elif, #endif, and #ifdef structures, keeping the voice developer's focus on logic rather than boilerplate formatting.