The alternative operator (|) is used to specify an alternate pattern to match if the first pattern fails. This operator can be used in a series to create a list of alternatives. When a pattern in a list of alternatives matches, the remaining alternatives are not tested.

The alternative operator has the lowest level of precedence of all the pattern matching operators. Even the white space operator has a higher level of precedence.

Once an alternate matches, ASL does not back up to test other combinations. For example, if the input to an ASL script is:

abc

and the pattern matching is:

{"a"|"ab"} "c"

No match occurs because once “a” matches, “ab” is not tested. ASL compares the pattern “c” with the input character “b” and the pattern fails. In general, when constructing a series of alternates, it is better to place the more complex (or longer) patterns ahead of other patterns.

Note:

In the example, braces are used around the alternate expression to control how the pattern is evaluated because the alternate operator has the lowest level of precedence. Without the braces, the alternate to the pattern "a" is the pattern "ab" "c". “Grouping patterns” on page 51 provides additional information on controlling pattern evaluation.

The following script matches one of three numbers followed by an end-of-line. For the first number of the input file, the data matches the first alternative so nothing else is checked. The second number of the input file does not match any of the alternatives so the pattern fails. The third number does not match either the first or second alternative, but it does match the third.

ASL Script (alt_match.asl):
START {
 a:{
 "3400"|"4500"|"4127"} eol
}
do {
 print("Matched with ".a);
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (alt_match.txt):
3400
3908
4127
Output:
$ sm_adapter --file=alt_match.txt alt_match.asl
Matched with 3400
Failed match
Matched with 4127
$