By default, a rule returns the characters it matches. A patternless rule returns an empty string. Like other patterns, the returned value from a rule can be assigned to a variable.

a:RULE_A

The return statement overrides values returned by a rule. The syntax is:

return <value>;

ASL exits a rule immediately after a return statement. It does not execute any statements that follow a return statement.

The next script reads input that consists of a person’s name followed by a field-separator and an address. Both the name and address are corrected for capitalization: an uppercase letter at the beginning of a word, followed with lowercase letters for the rest of the word.

In the START rule, two variables are assigned values returned from the READWORDS rule. Every time the pattern in the START rule matches, the two variables are printed.

The READWORDS rule is a repetition of pattern matching followed by an action block. The action block converts the data so that the first letter of a word is capitalized and the rest of the letters are lowercase. The word is added to a string called tempstr.

At the end of the READWORDS rule, the return statement returns the correctly capitalized string. If there was no return statement, the READWORDS rule would return the string as it was read during the pattern matching.

ASL Script (return_do.asl):
START {
 fullname:READWORDS fs
 address:READWORDS eol
}
do {
 print(fullname.address);
}
READWORDS {
 do {tempstr = "";}
 rep(READ_FIX)
do {return tempstr;
 }
}
READ_FIX {
 initial:char.rest:word?
}
do {
 initial = toUpper(initial);
 rest = toLower(rest);
 fixed=initial.rest;
 tempstr = tempstr.fixed." ";
}
DEFAULT {
 ..eol
}
do {
 print("Failed match");
}
Input (return_do.txt):
John Q Doe:11 MAin St.
JANE PUblic:387 OAK DR.
HENry HUDSON:9 ELM rd. 
Output:
$ sm_adapter --field-separator=: --file=return_do.txt return_do.asl
John Q Doe 11 Main St. 
Jane Public 387 Oak Dr. 
Henry Hudson 92 Elm Rd. 
$