Language reference
A Texomy spec is a YAML file of types. This is the complete syntax. Your agent reads the same reference through the MCP guide tool.
A specification is a YAML module. A top-level key declares a type or introduces a directive when it starts with $.
Types And Hierarchy
A type can declare one pattern or a list of alternatives. A child can satisfy references to its parent.
A: '[0-9]+'
B: [ 'x', 'y' ]
C:
D: 'd'
C::E: 'e'
D and E are both children of C. Nested and qualified declarations express the same relationship. A named
pattern such as D: 'd' produces C::D. Alternatives under the same $patterns produce the same type. Use
a named pattern when the result needs to identify the matched variant.
When the patterns of one type can match from the same start, the longer match wins. This holds for module-level
and $local types alike, so N: [ '\d+', '\d+,\d+' ] reads 281,724 whole. In a local type the containing
pattern still decides: the longer form gives way when the text after it does not fit. Alternatives written with |
inside one pattern are regex: the first that matches wins.
Between different types, $before decides first, then the longer match, and declaration order only last.
Module-level types compare their actual matches. The forms of local types compile into one alternation instead,
ordered when the spec is compiled from the forms alone: each form is an alternative of a pattern's top-level |,
and a form that can extend another one comes first, so with A: 'a|bc' and B: 'ab|b' a local reference takes
ab as a B and bc as an A. The forms of one pattern keep their order, so a type offers what its own regex
gives first: with A: 'a|abc' and B: 'ab', A offers a and B wins with ab, while with A: 'a|[ab]c' and
B: 'b', A wins with bc. As the order depends on how the forms are written, a local type can lose a span to a
shorter one where the analysis cannot decide, beyond 32 forms or 4 KB per form; $before states the order
explicitly.
Local Types
A type declared at the module level participates in independent recognition. A type declared inside $local
defines a local type, visible to the declaring type and its descendants. Local types work in the context of their declaring type and are compiled into its patterns.
A:
$local:
B: '[^|]+'
$fields: { x: B }
$patterns: '\|#{x}\|'
B runs as part of A. A local leaf with its own pattern shadows an equal global name. A local container without its own pattern can extend a global hierarchy with local subtypes.
For example, $local: { B: { C: 'c' } } adds B::C to the matches of references to B in that scope.
Bound broad fields with the actual delimiters. If a pipe ends a field, [^|\r\n]+ limits the span. Several
unbounded fields can force a regex to try many ways to split a long input. check may report UNBOUNDED_FIELDS.
Patterns And Fields
Every field refers to a declared type and belongs under $fields.
B: '[a-z]+'
A:
$fields: { x: B }
$patterns: '@#{x}'
${Type}composes a type for recognition.#{field}exposes the value through a declared field.#{field:Subtype}narrows a declared field for that occurrence. For example,#{x:B::C}restricts a field declared asBtoB::Cand its compatible subtypes.#{=field}matches the exact text captured by an earlier occurrence of that field.
Subtypes inherit fields, can redeclare a field with a subtype of its original type and can declare fields of
their own. A subtype without $patterns of its own also inherits the patterns of its nearest ancestor that has
some; a subtype with its own patterns inherits none. Inherited patterns are compiled in the subtype's scope, so a
${Type} or a field type in them resolves to the subtype's own $local first.
Reference:
$fields: { code: Code }
$patterns: '${Label}:? #{code}'
Order: { $local: { Label: [ 'PO', 'Purchase order' ] } }
Contract: { $local: { Label: 'Contract' } }
Reference takes Label, which only its subtypes declare: it is a frame. A frame is not matched on its own and
yields no node of its own type; its subtypes match, each with its own words, and a reference to Reference
takes them. check reports a frame pattern whose type neither the frame nor any subtype declares, and a subtype
that inherits a frame without declaring the type.
When the parent's patterns resolve on their own, the parent and its subtypes all match and compete as other
types do: the longer match wins, and on one span the subtype wins over its parent. A subtype that only changes
$local words then matches its words and the parent the rest; a subtype whose words include the parent's takes
every span the parent could. The same holds for a subtype with patterns of its own under a parent with patterns.
A single-value field takes one value in a match. It can stand in several places of a pattern and inside a repetition, so facts stated in any order are one pattern:
Header:
$local: { Other: '[^\n:]+:[^\n]*' }
$fields: { student: StudentName, id: StudentId }
$patterns: '((#{student}|#{id}|${Other})\n)+'
A match where the field would take a second value is dropped, and the run warns with REPEATED_FIELD. A pattern
that names fields matches only where it fills at least one of them, so the pattern above gives no Header over
lines that hold none of its facts. Use Type[] for a field the text can state more than once, as for a period
stated both before and after a figure. Collection items retain match order.
An optional group can make a field and the syntax around it optional. In 'a:#{x}(;#{y})?', the delimiter
and the field y occur together.
Literal Regex Syntax
Patterns use regex. Escape literal metacharacters. For example, '\[#{x}\]' matches surrounding brackets.
Lazy quantifiers such as *? and +? take as little as the rest of the pattern allows. Lookaround expressions
(?=, (?!, (?<= and (?<! are unsupported. Use context in the containing
pattern, narrower patterns or matching order. User-authored named capture groups are unsupported. Declare a field
for a captured result value. A single-quoted YAML scalar preserves a regex backslash. An enclosing JSON string
requires its own escaping.
A simple local helper in ${Type} may expand to a raw regex fragment. Group its alternatives when
surrounding syntax or a quantifier should apply to the whole fragment. For a fragment a|b,
prefix(${Fragment})suffix gives both alternatives the same prefix and suffix.
Fields With Narrower Patterns
A field declared with $type and $match uses that type and adds a constraint to the local occurrence.
Here x accepts a two-letter B.
B: '[a-z]+'
A:
$fields:
x: { $type: B, $match: '[a-z]{2}' }
$patterns: '@#{x}'
The compact declaration x: B supplies the type without an additional constraint. A type declared as B: {}
has no independent pattern. A field can supply its recognition through $match.
Lists With A Separator
A collection field can declare a pattern between its items. One occurrence of #{x} then matches one or more
items. A surrounding optional group permits an empty list.
B: '[a-z]+'
A:
$fields:
x: { $type: 'B[]', $separator: ',' }
$patterns: '\[(#{x})?\]'
$separator is available on collection fields. It can reference types and uses the containing type's whitespace
flags. With no separator declaration, a field reference matches a single item and repetition is written in the pattern.
Tables
$tables recognizes a type as the rows of a table whose header names its columns. $columns gives each column's
field and the type of its header, resolved as ${Type} is: the row type's $local first, then the module types.
A header type is usually local, and a list gives its alternatives:
LineItem:
$local:
ItemHeader: [ 'School', 'Item' ]
QuantityHeader: [ 'Hours', 'Weeks', 'Qty' ]
RateHeader: [ 'Rate', '(Hourly|Weekly) rate' ]
$fields: { description: Text, quantity: Number, rate: Money }
$tables:
$columns: { description: ItemHeader, quantity: QuantityHeader, rate: RateHeader }
Tables are laid out before any type is matched, from the header types and the separator alone, so a header type
matches text only: its patterns, those of its concrete subtypes and the types it takes with ${Type} make one
regex, each with its own flags. A header type cannot have fields. Header nodes are not kept in the result. A
module-level header type is also an ordinary type: outside header lines it matches and its nodes are kept, so a
type that only names headers belongs in $local.
A line in which at least two cells are headers of different declared columns is a header; the columns may stand
in any order. A header is found inside a header cell, at word boundaries, so 'Amount' takes Amount (USD). A
cell that several columns match goes to the longest match: 'No-show rate' takes No-show rate before 'Rate'
does. ^ and $ stand for the edges of the cell, so '^Rate$' takes only Rate. A column heads one cell of a
header line, the first it matches. The lines below the header that fit its structure are its rows, and the table
ends at the first line that does not fit, such as a blank line.
The types a row's fields need are matched first, in every cell of the header and of the rows, each as a record
of its own: no match of these types crosses a cell boundary, so a row is never read across its columns. A row
then becomes a node of the type when each of its non-empty declared cells yields its field. The field's type
takes the whole cell when it can, otherwise its first match inside the cell, so in ($1,705.43) a Money
without parentheses takes $1,705.43. An empty cell leaves its field unmatched. A row that does not yield its
fields keeps the nodes found in its cells. Cells under a column the spec does not declare, such as Balance,
fill no field.
The subtypes of a type with $tables share its table: its header, its columns and its separator. A subtype
declares no $tables of its own; it narrows fields, and a row becomes a node of the narrowest subtype whose fields
its non-empty declared cells all yield, otherwise of the type itself. A totals line is so told apart from the
items above it:
LineItem:
$local:
ItemHeader: 'Item'
AmountHeader: 'Amount'
Name: '\p{L}[\p{L} ]*'
$fields: { name: Name, amount: Money }
$tables:
$columns: { name: ItemHeader, amount: AmountHeader }
Total:
$local: { Name: 'Total' }
Here Total $95.00 is a LineItem::Total and the lines above it are LineItem. A reference to LineItem
takes its subtypes too, so LineItem[] takes the whole table.
The types that take the table's type are matched after its rows, over the whole text, where each row is one node
at its line. The header line belongs to the rows: the first row stands for the header line and its own line, so a
list of rows covers the whole table. A pattern can so compose rows, as a section with its caption (see $caption
below), its items and a line under them:
Section:
$flags: [ MULTILINE ]
$fields:
name: Heading
items: { $type: 'LineItem[]', $separator: '\n' }
total: Total
$patterns: '^#{name}\n#{items}(\n#{total})?'
$caption names a field that the line directly above the header fills, in every row of that table. That line is
the caption when it is not blank and belongs to no other table; it is matched as one cell, and its field takes
the whole line when it can, otherwise its first match inside it. A table without a caption line leaves the
field unmatched. To the types matched after the rows, the caption is the node of its field, so Section above
takes it as name: Heading with its value. A caption node that no pattern takes is left out of the result, since
its rows already hold it.
LineItem:
$local:
ItemHeader: [ 'School', 'Item' ]
QuantityHeader: [ 'Hours', 'Weeks', 'Qty' ]
RateHeader: [ 'Rate', 'Weekly rate' ]
$fields: { section: Heading, description: Text, quantity: Number, rate: Money }
$tables:
$caption: section
$columns: { description: ItemHeader, quantity: QuantityHeader, rate: RateHeader }
A column in the long form, value: { $type: Period, $header: period }, takes $header, a declared field that
the header cell fills. Such a column heads every cell of the header line that its type matches, and each of them
gives a copy of the row's node: the copy has the row's other fields, the cell under its header and that header in
the $header field, matched with the field's type. Without $header, the long form is the same as the short one.
Period:
Year: '(19|20)\d{2}'
Total: 'Total'
Figure:
$local: { MetricHeader: 'Metric' }
$fields: { metric: Metric, period: Period, value: Money }
$tables:
$columns:
metric: MetricHeader
value: { $type: Period, $header: period }
Metric 2023 2024 Total
Revenue $4.8bn $5.2bn $10.0bn
This gives three Figure nodes for Revenue, with period as !Period::Year '2023', !Period::Year '2024' and
!Period::Total 'Total'. A header line counts such a column once toward its two declared columns, so 2023 2024
alone is no header. A table has one column with $header at most. A row with no cell under that column gives one
node without it. To the types matched after the rows, the copies of a row are one node at its line: a list field
takes each copy, and a single field cannot take them.
Transaction:
$local:
DateHeader: 'Date'
DescriptionHeader: [ 'Description', 'Details' ]
DebitHeader: [ 'Debit', 'Withdrawals?', 'Money out' ]
CreditHeader: [ 'Credit', 'Deposits?', 'Money in' ]
$fields: { date: Date, description: Description, debit: Money, credit: Money }
$tables:
$columns: { date: DateHeader, description: DescriptionHeader, debit: DebitHeader, credit: CreditHeader }
$value:
date: '#{date}'
amount: '[-#{debit.amount}][#{credit.amount}]'
$separatoris the pattern between cells,'\s{2,}'by default. When two separators in a row also match as one, as with'\s{2,}', an empty cell cannot be seen, and cells are placed by alignment: a column runs from the start of its header to the start of the next one, the first from the line start and the last to the line end. A line fits when it has two pieces at least and more than half of each piece lies under one column; pieces under one column are one cell. A prose line rarely fits, as its long pieces run across columns.- Otherwise, as with
'\t'or'\|', the cells go in the order of the headers. A line fits when it has as many cells as the header, and empty text between two separators is an empty cell. - Of two tables whose headers fit one line, the one declared first takes it.
- The node of a row, or of a copy, spans its fields in the result: from its first field to its last, so a row with a caption starts at its caption and a copy at its column header. Such spans may overlap. The nodes that the types after the rows compose from them span the rows' lines and do not overlap.
$tablesis one table or a list of them. A type can have$patternstoo, for the text outside tables. Only a module-level type can have$tables. A field fills one place: a column, the caption or the$headerof a column.- The rows of all tables are assembled at one stage, so a type whose pattern takes rows cannot be needed by the cells of a table.
Progressive Recognition
Recognizing a span turns it into a node. Later raw regex in the pattern of a module-level type cannot read the
characters inside that node. Use ${Type} or a typed field to consume that span as a unit. For example, after B
recognizes digits, 'a:${B}' can match the recognized node. 'a:\d+' expects raw digits. In such a pattern a
class that lists characters, such as [\p{L} ], stops at a node. A negated class such as [^\n] and . pass
over a node as a whole, whatever its text; the node is then part of the text the pattern skips, and it and its
fields leave the result. To keep the values between two points, take them as a field, such as a list of their type.
A local type reads the source text as written, including the text inside recognized nodes, so a local class
stops only where the text has a character it does not list: Code: '[A-Z]+-\d+' in $local takes INV-2041
although 2041 is a recognized number. Global references in the same pattern still consume recognized nodes as
units.
Matching-only composition can leave the enclosing result atomic. A field keeps the child in the result. Use the representation required by the current task.
Matching Order
Types usually match after their references. $before and $after add explicit ordering, and an ordered type
includes its subtypes. The patterns of a type and its subtypes that take a node of the same type match
together, as they compete for it: For #{goods}, #{limit} and a bare #{limit} meet over the same limit, and
the longer match wins. For example, A: { $after: B, $patterns: 'a:${B}' } places A after B.
Overlaps are resolved by matching rules, including explicit order, recursive operand relationships, length,
position, specificity and fixed text. Declaration order resolves the remaining ties. Those ties can produce
AMBIGUOUS_MATCH. Adjust the pattern or ordering to express the intended match.
When two recursive matches share an operand, the declared operand types affect which can contain the other. Use the operand types that represent the required grouping.
Values
$patterns describes how a type is written in the text. $value describes what a consumer receives. Without
$value, a node has no separate value, and its text is what consumers use.
Currency:
Usd: { $patterns: [ 'USD', '\$' ], $value: 'USD' }
Eur: { $patterns: [ 'EUR', '€' ], $value: 'EUR' }
Amount:
$local: { Group: '\d{1,3}', Fraction: '\d+' }
$fields:
groups: { $type: 'Group[]', $separator: ',' }
fraction: Fraction
$patterns: '#{groups}(\.#{fraction})?'
$value: '#{groups}[.#{fraction}]'
Money:
$fields: { amount: Amount, currency: Currency }
$patterns: '#{currency} ?#{amount}'
$value: { amount: '#{amount}', currency: '#{currency}' }
Here $1,705.43 has the value { amount: '1705.43', currency: 'USD' }, and €1,705 has
{ amount: '1705', currency: 'EUR' }.
- A number, boolean, list or object in
$valueis returned as written:6gives6,'06'gives"06". - Every string in
$value, also inside a list or an object, is a template and yields a string. A template that includes neither text nor a matched field, such as'[#{currency}]'without a currency, yieldsnull. #{field}inserts the field's value when its type has$value, otherwise the field's matched text. A collection field inserts its items one after another, without separators. A field whose value isnullcounts as unmatched. Other text is literal.- A section in
[...]is included only when every field referenced directly in it was matched. Sections can nest. A backslash makes the next[,],#or\literal, as in'\[#{code}\]'. - A path inserts a part of a field's value:
'#{debit.amount}'takesamountfrom the value ofdebit, and'#{amounts.0.amount}'takes it from the first item of a collection field. The part must be a scalar. A missing ornullpart counts as an unmatched field, so'[-#{debit.amount}][#{credit.amount}]'gives the amount of whichever field matched, with its sign. - A template references declared fields. A field whose value is an object or a list needs a path to a scalar
part of it. The path must exist in the
$valueof at least one type that can fill the field; for a type whose value lacks it, the part counts as unmatched, as#{rate.per}for a rate given without a unit.checkreports others. - A subtype inherits
$valueunless it declares its own.
A template inserts the matched text as is. It does not compute, pad or reorder. Give a form that needs a
different value a subtype with its own $value, such as a single-digit day with $value: '0#{digit}'.
Flags
Flags are off by default. A file or type sets flags with $flags. Inline patterns use the letters in the table.
A descendant can disable an inherited flag with -FLAG. Inline i, m and s can also be scoped to a group.
A field reference is recognized with the flags of its own type: (?i:#{x}) does not change how x matches.
$flags: [ CASE_INSENSITIVE, FLEXIBLE_WHITESPACE ]
Code:
$flags: [ -CASE_INSENSITIVE ]
$patterns: '[A-Z]{3}'
| Flag | Inline | Effect |
|---|---|---|
CASE_INSENSITIVE | i | Letters match in either case. |
FLEXIBLE_WHITESPACE | f | A run of literal spaces matches whitespace with at most one line break. |
OPTIONAL_WHITESPACE | o | A run of literal spaces can also match zero characters. |
CHARS | c | A match can start or end inside a word. |
MULTILINE | m | ^ and $ apply to line boundaries; without it they mark the start and end of the record. |
DOTALL | s | . can consume a line break. |
Whitespace flags act on spaces written in the pattern. For example, 'a b' with OPTIONAL_WHITESPACE
can match both ab and a b. A pattern without the space has no such whitespace slot. Character classes and
escaped spaces keep their own meaning.
A line break is \n or \r\n. With MULTILINE, $ matches before either one. Without DOTALL, . matches
neither \r nor \n.
Without CHARS, adjacent letters or adjacent digits form a word. A letter next to a digit is a boundary.
A match starts and ends at word boundaries. Matching backtracks past alternatives that would end inside a
word, so in '\d+ Main( Fl)?' the text 12 Main Flagstaff yields 12 Main. Inside a match, literal text and
local fields can meet in the middle of a word: with '(per|an?) ?#{unit}' and a local unit d, the text and
reads as an and d. Write the space or delimiter that the text has between them.
Unicode is enabled for character classes and case matching.
Imports
An import is a module name. types.a resolves to types/a.yml from the current package root. A prefix
such as lib:b resolves to b.yml in the dependency named lib in texomy.json.
$imports: [ 'types.a', 'lib:b' ]
Declare exact dependency versions in the manifest. CLI roots supply the folders and ZIPs to search. The API
runs the package contained in the submitted files. A subfolder with its own texomy.json is a separate package.
Pass the root module by name when parsing a multi-file package.
Specification Style
A type with only a pattern can use the scalar or list form. Use a mapping for directives, fields, local types
or subtype declarations. Prefer single quotes for regex strings. Ordinary groups (a|b) are enough for grouping.
Testing a spec
A *.test.yml file imports an existing module and declares named cases. Each case provides input and the
expected output: what a consumer receives, in the same form as a test failure prints it. Given A: 'a' in
a.yml, this test expects one node and one nonmatch.
$imports: 'a'
matches:
input: 'a'
output:
- !A 'a'
skips:
input: 'b'
output: []
output lists every top-level node in order; an extra or missing node fails the case. Each node is tagged with
its matched type, fully qualified: !Money::Positive, not the declared field type Money. A local type is
tagged with its name in the $local that declares it, such as !Text or !Figure::Opening. Its content is:
- its
$value, if its type has one: a string, number, list or object, exactly as produced; - otherwise, if its type has fields, a mapping of the matched fields; a field that did not match is left out;
- otherwise, its matched text.
A collection field is a list of tagged items. Matches inside a node with $value do not appear, and positions are
not part of the output. Values compare exactly: '06' is not 6. Given this module:
N: '\d+'
Point:
$fields: { x: N, y: N }
$patterns: '\(#{x}, #{y}\)'
Path:
$fields:
points: { $type: 'Point[]', $separator: ' -> ' }
$patterns: 'path #{points}'
Version:
$fields: { major: N, minor: N }
$patterns: 'v#{major}.#{minor}'
$value: '#{major}.#{minor}'
all:
input: 'path (1, 2) -> (3, 4) at v2.10, 7'
output:
- !Path
points:
- !Point { x: !N '1', y: !N '2' }
- !Point { x: !N '3', y: !N '4' }
- !Version '2.10'
- !N '7'
A case can set records to split its input as the CLI --records option does: paragraphs (the default),
lines, whole or start=REGEX. Each record is parsed separately, and output lists the nodes of all records.
Given Name: '[A-Za-z]+', Price: '\d+\.\d{2}' and Item with pattern '#{name}\s+#{price}', line records keep
Tea and 2.50 apart:
one_item_per_line:
input: |
Tea
2.50 Coffee 3.10
records: 'lines'
output:
- !Name 'Tea'
- !Price '2.50'
- !Item { name: !Name 'Coffee', price: !Price '3.10' }
!file reads input or output from a file of the package. A path is relative to the test file, or to the
package root when it starts with /. A path that leads outside the package is an error. An output file holds
the list of nodes. Give it the .yaml extension: every .yml file of the package is a spec.
menu:
input: !file '../samples/menu.txt'
output: !file 'expected/menu.yaml'
See the syntax in action in the examples, or open any of them in Studio.