Skip to content
Axes and tools

Axes and tools

Axes and tools

Read a property of every token, its scale here, and query it from a pattern; then rewrite what a pattern finds.

Read an axis

A token has a scale, a nesting depth, a texture and more; each is an axis, read on its own or from a pattern. Magnitude is the order of magnitude of a token’s value:

$ trex magnitude --text 'retries = 3 ; max_bytes = 5000000000'
trex magnitude: 36 bytes, 7 tokens, total energy 112.2, 3 scale-jump(s)
  peak magnitude: 9.70 at '5000000000'

Query it from a pattern

\M{>6} is a token more than six orders of magnitude big:

$ trex scan '\M{>6}' --text 'retries = 3 ; max_bytes = 5000000000'
[26..36] "5000000000"

Rewrite what a pattern finds

A template replaces each match: ${name} renders a register and ${name:acc} a slice of it:

$ trex rewrite '\E:e' '[${e:domain}]' --text 'mail bob@x.com now'
mail [x.com] now

Where next

  • Beyond regex covers the rest of the pattern language.
  • The how-to guides solve one task each: grammars, prefilters, records, rules.
  • The reference is the complete specification.
  • The explanation covers how the engine reads tokens in one pass.