uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Quote Override `
Product:
Class:
Remarks
Quote Override
Shortcut: ` (backtick)Associated Method: uCalc.Rule.QuoteAware(bool)
Description: A postfix modifier that allows a pattern variable to ignore the atomic boundaries of quoted strings, enabling it to match content inside or across quotes.
By default, uCalc is "Quote Aware." The lexer identifies quoted strings (e.g., "Hello World") as single, atomic tokens. This prevents transformation rules from accidentally breaking into a string and changing its contents unless explicitly intended.
The Quote Override (`) is used to bypass this protection.
Default vs. Override Behavior
- Default (Quote Aware): A variable match for
{v}will treat a quoted string as one unit. It cannot capture just the first word inside the quotes because the quotes act as a container. - Override (
{v`}): Appending the backtick tells the engine that quotes are not atomic for this specific variable. The engine will treat the quote characters as literal delimiters or standard text, allowing the capture to stop or start inside the quoted segment.
The QuoteAware() Method
You can toggle this behavior globally using the QuoteAware() method on the uCalc object.
uc.QuoteAware(true): (Default) Quoted strings are treated as unbreakable atomic tokens.uc.QuoteAware(false): All variables behave as if they have the backtick postfix, treating quote characters as standard text.
Examples
1. Succinct (Breaking the Atomic Quote)
Showing how a standard variable fails to split a quoted string, while the override succeeds.
New(uCalc::Transformer, t)// Default: Tries to match 'say' then any variable. // It will match the WHOLE quoted string as one token.t.FromTo("say {msg}", "MSG:{msg}")// Override: Allows splitting the quoted string.t.FromTo("say \"{msg`}\"", "INSIDE_QUOTE:{msg}")wl(t.Transform("say \"Hello\"")) // Output with ` : INSIDE_QUOTE:Hello2. Practical (Content Manipulation inside Quotes)
Useful when you need to perform a search-and-replace for specific keywords that only appear inside quoted strings.
New(uCalc::Transformer, t)// Capture the content inside double quotes using the overridet.FromTo("\"{content`}\"", "QUOTE_START {content} QUOTE_END")wl(t.Transform("\"Secret Data\""))[Expected Output]QUOTE_START Secret Data QUOTE_END
3. Internal Test (Global Configuration)
Verifying that disabling global quote awareness allows all patterns to penetrate quoted strings.
// Disable quote awareness globallyuc.QuoteAware(false)New(uCalc::Transformer, t)// Now the pattern can match 'Word' even if it's inside quotest.FromTo("Word", "MATCH")wl(t.Transform("\"Word\""))[Expected Output]"MATCH"
Strategy & Critique
- Data Protection: uCalc's default quote awareness is a critical safety feature for code transpilation (e.g., you don't want to change a variable name inside a print statement's string literal). Only use the override when you are explicitly processing string content.
- Lexer Interaction: Because the backtick forces the engine to look "inside" the token, it can increase the complexity of the match. Use it surgically.
- Naming: Like
NestingAware(), the methodQuoteAware()clearly defines the engine's stance on structural integrity. - See Also: Refer to Topic 781 for Nesting Overrides and Topic 780 for Statement Boundary Overrides.
Examples
Ignore quote directive `
using uCalcSoftware;
var uc = new uCalc();
var t = uc.NewTransformer();
t.FromTo("a {txt} c", "<{@Self}>"); // Quoted text treated as 1 token
t.FromTo("x {txt`} z", "<{@Self}>"); // Quotes treated as ordinary chars
Console.WriteLine(t.Transform("a 'b c' b c :: x 'y z' y z"));
<a 'b c' b c> :: <x 'y z>' y z using uCalcSoftware; var uc = new uCalc(); var t = uc.NewTransformer(); t.FromTo("a {txt} c", "<{@Self}>"); // Quoted text treated as 1 token t.FromTo("x {txt`} z", "<{@Self}>"); // Quotes treated as ordinary chars Console.WriteLine(t.Transform("a 'b c' b c :: x 'y z' y z"));
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
auto t = uc.NewTransformer();
t.FromTo("a {txt} c", "<{@Self}>"); // Quoted text treated as 1 token
t.FromTo("x {txt`} z", "<{@Self}>"); // Quotes treated as ordinary chars
cout << t.Transform("a 'b c' b c :: x 'y z' y z") << endl;
}
<a 'b c' b c> :: <x 'y z>' y z #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; auto t = uc.NewTransformer(); t.FromTo("a {txt} c", "<{@Self}>"); // Quoted text treated as 1 token t.FromTo("x {txt`} z", "<{@Self}>"); // Quotes treated as ordinary chars cout << t.Transform("a 'b c' b c :: x 'y z' y z") << endl; }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Dim t = uc.NewTransformer()
t.FromTo("a {txt} c", "<{@Self}>") '// Quoted text treated as 1 token
t.FromTo("x {txt`} z", "<{@Self}>") '// Quotes treated as ordinary chars
Console.WriteLine(t.Transform("a 'b c' b c :: x 'y z' y z"))
End Sub
End Module
<a 'b c' b c> :: <x 'y z>' y z Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Dim t = uc.NewTransformer() t.FromTo("a {txt} c", "<{@Self}>") '// Quoted text treated as 1 token t.FromTo("x {txt`} z", "<{@Self}>") '// Quotes treated as ordinary chars Console.WriteLine(t.Transform("a 'b c' b c :: x 'y z' y z")) End Sub End Module