Configuration

Tokenizer has two configuration surfaces: TokenizerOptions (set at construction time) and YAML front matter (set per-template). Front matter overrides constructor options, which override defaults.

Options Reference

Pass a TokenizerOptions instance to the Tokenizer or TemplateMatcher constructor:

C#
var tokenizer = new Tokenizer(new TokenizerOptions
{
    OutOfOrderTokens = true,
    TrimTrailingWhiteSpace = false,
    EnableDiagnostics = true
});
Matching Behaviour
OptionDefaultDescription
OutOfOrderTokensfalseAllow tokens to match in any order rather than strictly left-to-right
TerminateOnNewLinefalseExtract token values up to the first newline only
TokenStringComparisonInvariantCultureString comparison used when matching token names to object properties
IgnoreMissingPropertiesfalseSilently ignore tokens that don't map to a property on the target object
Whitespace
OptionDefaultDescription
TrimTrailingWhiteSpacetrueTrim trailing whitespace from each extracted token value
TrimLeadingWhitespaceInTokenPreambletrueTrim leading whitespace in the static text before a token
TrimPreambleBeforeNewLinefalseDiscard preamble text that appears before a newline
Safety Limits
OptionDefaultDescription
MaxInputLength1,048,576 (1 MB)Maximum input text length in characters (0 to disable)
MaxTemplateLength65,536 (64 KB)Maximum template pattern length (0 to disable)
MaxTokenCount500Maximum tokens per template (0 to disable)
MaxIterations0 (auto)Maximum tokenization loop iterations. Auto-calculated as input length × 2
MaxRegexTimeout1 secondMaximum time for a single regex evaluation in user-supplied patterns
Date/Time
OptionDefaultDescription
Culturenull (invariant)Culture for parsing date/time values (month names, day names)
DefaultOffsetnullStatic UTC offset for date/time values with no offset info. Takes precedence over DefaultTimezone
DefaultTimezonenullIANA or Windows timezone ID (e.g. "Europe/Berlin") for DST-aware offset resolution
Other
OptionDefaultDescription
EnableDiagnosticsfalseInclude structured diagnostic trace in results. No performance impact when disabled
AllowStreamBufferingfalseBuffer non-seekable streams for multi-template matching

Front Matter

You can override options per-template using YAML front matter between --- markers at the start of the template. Lines starting with # are comments.

C#
var pattern = @"---
# Template-level configuration
name: my-template
OutOfOrder: true
TrimTrailingWhitespace: false
CaseSensitive: false
TerminateOnNewLine: true
culture: en-GB
defaultOffset: +00:00
---
First Name: {FirstName}
Last Name: {LastName}";
Available Directives
DirectiveMaps To
OutOfOrderOutOfOrderTokens
TrimLeadingWhitespaceTrimLeadingWhitespaceInTokenPreamble
TrimTrailingWhitespaceTrimTrailingWhiteSpace
TrimPreambleBeforeNewLineTrimPreambleBeforeNewLine
TerminateOnNewLineTerminateOnNewLine
IgnoreMissingPropertiesIgnoreMissingProperties
CaseSensitiveTokenStringComparison (true = InvariantCulture, false = InvariantCultureIgnoreCase)
cultureCulture
defaultOffsetDefaultOffset
defaultTimezoneDefaultTimezone
nameTemplate name (for TemplateMatcher)
tagTemplate tag (repeatable)
hint / hint?Matching hint (required / optional)

Boolean directives accept true/false, yes/no, or on/off (case-insensitive).

Precedence

When the same option is set in multiple places, the most specific value wins:

  1. Front matter (per-template) — highest priority
  2. Constructor options (TokenizerOptions) — instance-level defaults
  3. Built-in defaults — the values shown in the tables above

This means you can set sensible defaults on the Tokenizer instance and override them for specific templates using front matter.