A filter determines whether the action block of a rule executes. When a filter fails, the subsequent action block does not execute. Unlike a pattern, if a filter fails, the rule it is called from does not fail.

A filter has the form:

filter {
{<filter-list>}
}

The <filter-list> must be a single Boolean expression. ASL evaluates this expression from left to right. If it is TRUE, ASL executes the actions in the do block. If it is FALSE, ASL does not execute the actions in the do block.

Filter operators are listed in Filter operators.

  • Parentheses have the highest level of precedence.

  • The logical operators && and || have the lowest level of precedence.

    Although the filter-list must be a single Boolean expression, you can use the logical AND and logical OR to test for more than one condition.

Table 1. Filter operators

Operator

Definition

()

Grouping operators

+ - * / %

Arithmetic operators

==

Equal to

!=

Not equal to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

&&

Logical AND

||

Logical OR

In the following script example, the filter controls whether an action is performed. The script matches a word and an eol. The value of the word is assigned to x.

The filter is true when x has the value “switch”. For the input file, this occurs in the first line and the fourth line. The action block is executed twice. The DEFAULT rule is never executed because the pattern always matches.

ASL Script (simple_filter.asl):
START {
 x:word eol
}
filter {
 x=="switch"
}
do {
 print("Filter match: ".x);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (simple_filter.txt):
switch
router
card
switch
Output:
$ sm_adapter --file=simple_filter.txt simple_filter.asl
Filter match: switch
Filter match: switch
$

In the next example, the script matches a word and an eol. The value of the word is assigned to x. The filter is true when x has the value “switch,” or when it has the value “router.”

ASL Script (other_filter.asl):
START {
 x:word eol
}
filter {
 x=="switch" || x=="router"
}
do {
 print("Filter match: ".x);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (other_filter.txt):
switch
router
card
switch
Output:
$ sm_adapter --file=simple_filter.txt simple_filter.asl
Filter match: switch
Filter match: router
Filter match: switch
$ 

Filters can be useful for debugging. Setting a single variable at the beginning of a script can affect the actions that a script performs.

debug = TRUE;
START {
x:word eol
}
filter {
debug==TRUE
}