More on Bindings

Content Bindings and Binding Insertion

Index bindings were briefly covered in the first section of this guide, but there are more types of bindings. For now, we will discuss symbol and sequence bindings, which rather than storing the position inside a class or alternative store what was matched.

Most matchers we have discussed so far will produce such content bindings. Content bindings can be inserted as either a matcher or replacer by placing the name in angle brackets:

rule merge_doubles = .@s -> () in _ <s>;

This will merge any double symbols. First, it matches any symbol and binds the matched symbol to s with .@s. the binding is then used in the environment to make the rule only apply if the same symbol is just after the main match.

Using binding insertion replacers, metathesis can be implemented:

rule metathesis = (cons)@c (vow)@v -> <v> <c>;

This rule will swap the order of any consonant-vowel pair.

Forcing Content Bindings

Note that the class matchers are placed in parentheses. Not doing this would create an index binding, which cannot be used as an inserter. You can think of the parentheses as preventing the binding from seeing what is inside, and therefore falling back to the default content binding.

You may remember that alternative matchers still produce index bindings even when they are in parentheses. This is a special case because otherwise the precedence of alternatives would prevent them from getting any bindings as the bindings would bind to the matchers inside the alternative. To force a content binding with alternatives, use an extra pair of parentheses:

rule alt_content_bind = (('a' | 'b'))@s -> 'c' in <s> _;

A Note on Matching Sequence

Due to the details of how matching is implemented internally, the order in which bindings are created (and therefore become available to use as insertions) can be unintuitive. Tadpole constructs matches in the following order:

  1. The main match is constructed left to right
  2. The pre (left) environment match is constructed right to left
  3. The post (right) environment match is constructed left to right

Or, put succinctly, environments match outwards. To illustrate, the example below shows the order of bindings:

rule binding_order = .@_1 .@_2 .@_3 -> () in .@_6 .@_5 .@_4 _ .@_7 .@_8 .@_9;

This also applies to exceptions, but obviously bindings from exception environments can only be used within the exception environment since no replacement is done.

With multiple environments, each constructs a separate binding table starting from that produced by the main match. If multiple environments match, only bindings produced in the first matching environment are available in replacers.