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.

Token Category Operators

Product: 

Class: 

Explains the operators used within pattern syntax to match tokens by their category (@) or to exclude tokens by category (!).

Remarks

🎯 Token Category Operators: The @ and ! Prefixes

[not implemented yet]

The @ and ! operators are powerful prefixes used inside pattern variable syntax ({...}) to match tokens based on their lexical category rather than their literal text. This is the core mechanism that makes uCalc's Transformer token-aware, giving it a structural understanding of text that traditional regular expressions lack.


The @ Operator: Matching by Category

The @ operator is the standard way to match a token based on its type. Instead of looking for a specific word like "if", you can look for any alphanumeric identifier using {@Alphanumeric}.

Syntax

  • {@Category}: Matches any token belonging to Category but does not capture its value.
  • {@Category:varName}: Matches any token belonging to Category and captures its text into the variable {varName}.

This makes patterns both readable and robust. A pattern to find a number is simply {@Number}, which is far clearer than a complex regex like [-+]?[0-9]*\.?[0-9]+.

For a complete list of categories, see the Matching by token category topic.


The ! Operator: Negating a Category

The ! operator is the logical inverse of @. It matches any token that does not belong to the specified category. This is extremely useful for capturing 'everything else' or for defining boundaries in a pattern.

Syntax

  • {!Category}: Matches any token that is not in Category.
  • {!Category:varName}: Matches and captures any token that is not in Category.

For example, the pattern {!Bracket:content} will capture any token as long as it isn't an opening or closing bracket. This is a simple and powerful way to capture the content between delimiters.


⚖️ Comparative Analysis

FeatureuCalc Category OperatorsRegular Expressions
MatchingToken-based. {@Alphanumeric} matches a whole word.Character-based. \w+ matches a sequence of word characters.
SafetyHigh. {@Alphanumeric} will not match inside a string literal like "my_variable_name" by default.Low. \w+ can easily and incorrectly match text inside strings or comments.
ReadabilityHigh. {@Number} is self-documenting.Low. [-+]?\d*\.?\d+ is cryptic.
NegationSimple. {!Whitespace} clearly means 'not whitespace'.Complex. Requires negative lookarounds like (?!\s) which are less intuitive.

Summary Table

OperatorNameSyntaxPurpose
@Category Matcher{@Category:var}Matches a token that is a member of Category.
!Negation Operator{!Category:var}Matches any token that is not a member of Category.

Examples