uCalc API Version: 5.7.0-preview.1 Released: 7/30/2026
Warning
uCalc API Preview Release Notice:This preview documentation describes the intended behavior of the API. It is not fully accurate or complete.The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.Use of the preview version in your production code is not recommended.
Description: A structural anchor directive that restricts a pattern match to the very beginning of the source text.
The {@Beginning} directive is used within a uCalc::Transformer to ensure that a specific pattern only triggers if it is found at the absolute start of the input string. It is a zero-width anchor, meaning it does not "consume" any tokens itself; it simply validates that the parser's current position is at index zero.
In many transformation tasks, the first few tokens of a file contain metadata, headers, or unique identifiers (like a "shebang" in scripts). {@Beginning} allows you to target these elements safely without accidentally matching similar patterns elsewhere in the document.
{@Beginning} is functionally equivalent to the ^ anchor in standard Regular Expressions when used at the start of a pattern.{@Beginning} refers to the start of the entire source string, unless the engine is configured to skip those tokens during the initial anchor check.Replacing a specific keyword only if it appears at the very start of the document.
New(uCalc::Transformer, t)// Match 'ID' only if it's the first thing in the stringt.FromTo("{@Beginning} ID", "IDENTIFIER:")wl(t.Transform("ID 12345"))wl(t.Transform("User ID 123"))[Expected Output]IDENTIFIER: 12345User ID 123 (No change, since 'ID' was not at the beginning)
Using {@Beginning} to find a script indicator and convert it to a standardized header, while ignoring similar text in the body.
New(uCalc::Transformer, t)// Match a '#' followed by a word only at the startt.FromTo("{@Beginning} # {@Alpha:lang}", "--- Language: {lang} ---")var(string, script) = "#uCalc\nprint \"Hello\"; #Note: comments"wl(t.Transform(script))[Expected Output]--- Language: uCalc ---print "Hello"; #Note: comments
Verifying that {@Beginning} respects the absolute start, even when adjacent to other tokens.
New(uCalc::Transformer, t)t.FromTo("{@Beginning}", "[START]")// Note: If the engine doesn't auto-skip leading spaces, // this will insert [START] at the very front.wl(t.Transform("Data"))[Expected Output][START]Data
{@Beginning}, it can immediately skip the rule if the current match attempt is not at the start of the string, saving significant processing time in large documents.{@Start}. Using {@Beginning} aligns with a more descriptive, semantic approach to structural anchors.{@End}) for anchoring to the conclusion of the source string.