How Ecasound Parses Escaped Chain Arguments
This article explains how Ecasound processes escaped characters within chain operator arguments. It covers how the internal tokenizer recognizes delimiters, handles backslash escape sequences, and interacts with shell-level parsing, enabling users to pass complex string arguments—such as filenames with spaces or plugins requiring literal commas—without breaking parameter processing.
The Role of Delimiters in Chain Operators
In Ecasound, chain operators are applied to audio chains using
options like -el, -ea, or -ef3,
followed by parameters separated by commas (,). For
example, in -ea:100,50, the comma acts as a delimiter
separating the gain values for different channels.
When an argument must contain a literal delimiter—such as a comma within a string parameter, a colon, or quotation marks—Ecasound requires an escape mechanism so the internal parser does not misinterpret the character as a boundary between distinct arguments.
The Backslash as an Escape Character
Ecasound uses the backslash (\) as its escape character
during argument tokenization:
- State-Based Tokenization: As the parser iterates through the argument string character by character, encountering a backslash shifts the tokenizer into an "escape state."
- Literal Interpretation: The character immediately
following the backslash is treated as a raw, literal character. It is
appended directly to the current parameter buffer rather than being
evaluated as a structural token (like a comma
,or a closing quote). - Backslash Removal: The backslash itself is stripped
from the finalized argument string. For example, the sequence
\,results in a literal,stored inside the single argument value. - Escaping the Escape Character: To pass an actual
backslash into an operator argument, two backslashes (
\\) must be used; the parser consumes the first and retains the second.
Shell Interpretation vs. Ecasound Parsing
A frequent point of confusion when working with escaped characters in Ecasound is the interaction between the operating system's shell (such as Bash or Zsh) and Ecasound's internal parser.
Before Ecasound receives an argument string, the shell processes its own escape rules. If a command is entered as:
-ea:value\,test
The shell strips the backslash before launching Ecasound, causing
Ecasound to see -ea:value,test and split it into two
separate arguments.
To ensure the backslash reaches Ecasound's parser, you must either:
- Quote the parameter string:
"-ea:value\,test"or'-ea:value\,test' - Double-escape the character:
-ea:value\\,test
Quoting Mechanisms Inside Ecasound
In addition to backslash escaping, Ecasound supports double-quote
(") grouping within chain arguments to enclose values that
contain spaces or special characters. When quotes are used:
- Commas inside quoted strings are treated as literals and are not split into separate parameters.
- Escaped quotes (
\") allow literal quotation marks to be included within a quoted argument without prematurely terminating the string.