Parse masks are used for testing input strings after they have been scanned using the system function scan(), and they are used to parse commands. In all cases, parser masks are surrounded in single-quotes and evaluate to a zero value (false) on mismatch and a non-zero value (true) on a positive match.

See Also...

Warning: Since parse masks use the single-quote delimeters, just like character literals, a parse mask cannot have exactly one character, as in 'A', or it will be interpreted as a character literal (i.e. the ASCII value of the supplied character). If you want to test for single character commands, you must throw at least 1 extra space or punctuation symbol into the parse mask, as in ' A ', 'A ', or ' A'.

Sentence Masks

'look rock'

A sentence mask tests an entire command. It will evaluate to true on a positive match, and false on a mismatch. If the words "at" and "the" were ignored, then the parse masks 'look rock' and 'look at the rock' would both match the same command.

Phrase Masks

'rock?'

'...rock...'

A phrase mask has two styles, which you can see above, and you can use whichever you prefer. It will evaluate to the position that the phrase occurs in the current command, starting with 1, or 0 if the sub phrase is not found.

Prefix Masks

'look...'

A prefix mask returns true only if the command begins with a certain phrase.

Suffix Masks

'...rock'

A suffix mask returns true only if the command ends with a certain pharse.

Empty Masks

''

Evaluates to true only if the current command is empty, and false otherwise.

Input Masks

Masks can contain special symbols to recognize input numbers (#), strings ($), and undecided words (*). Each special symbol may be followed by a digit that tells which slot to store it in. If no digit is given, then '0' is assumed. These input slots can then be consulted later in your program. The input slots are reset to 0 or empty whenever you call the scan function.

These examples show how to recognize unknown words, which means words that were never declared or used in a parse mask. All of these are equivalent, and simply match the first unkown word and store it in string slot zero.

'...$0...'

'...$...'

'$?'

'$0?'

The string can then be retrieved using the ScannedString() function.

To read numbers, you can use the '#' symbol. Here's an example that will set the position of your character, assuming there is some infrastructure to handle parser input that calls this parse function.

script parse { if 'pos #1 #2' { SetPosition(ScannedNumber(1), ScannedNumber(2)); finish; } }

The '*' will match any recognized word. There must usually then be further testing to find out which word.