Show/Hide Toolbars

XSharp

Match Pattern

The <matchPattern> portion of a translation directive is the pattern the input text must match.  A match pattern is made from one or more of the following components, which the preprocessor tries to match against input text in a specific way:

 

Literal values are actual characters that appear in the match pattern.  These characters must appear in the input text, exactly as specified to activate the translation directive.

 

Words are keywords and valid identifiers that are compared according to the dBASE convention (case-insensitive, first four letters mandatory, etc.).  The match pattern must start with a Word.

 

#xcommand and #xtranslate can recognize keywords of more than four significant letters.

 

Match markers are label and optional symbols delimited by angle brackets (<>) that provide a substitute (idMarker) to be used in the <resultPattern> and identify the clause for which it is a substitute.  Marker names are identifiers and must, therefore, follow the xBase identifier naming conventions.  In short, the name must start with an alphabetic or underscore character, which may be followed by alphanumeric or underscore characters.

 

This table describes all match marker forms:

 

Match Marker

Name

<idMarker>

Regular match marker

<idMarker,...>

List match marker

<idMarker:word list>

Restricted match marker

<*idMarker*>

Wild match marker

<(idMarker)>

Extended Expression match marker

<#idMarker>

Single match marker.

<%idMarker%>

Wildcard match marker

 

Regular match marker: Matches the next legal expression in the input text.  The regular match marker, a simple label, is the most general and, therefore, the most likely match marker to use for a command argument.  Because of its generality, it is used with the regular result marker, all of the stringify result markers, and the blockify result marker.

 

List match marker: Matches a comma-separated list of legal expressions.  If no input text matches the match marker, the specified marker name contains nothing.  You must take care in making list specifications because extra commas will cause unpredictable and unexpected results.
 
The list match marker defines command clauses that have lists as arguments.  Typically these are FIELDS clauses or expression lists used by database commands.  When there is a match for a list match marker, the list is usually written to the result text using either the normal or smart stringify result marker.  Often, lists are written as literal arrays by enclosing the result marker in curly ({ }) braces.

 

Restricted match marker: Matches input text to one of the words in a comma-separated list.  If the input text does not match at least one of the words, the match fails and the marker name contains nothing.
 
A restricted match marker is generally used with the logify result marker to write a logical value into the result text.  If there is a match for the restricted match marker, the corresponding logify result marker writes true (.T.) to the result text; otherwise, it writes false (.F.).  This is particularly useful when defining optional clauses that consist of a command keyword with no accompanying argument.  Std.ch implements the REST clause of database commands using this form.

 

Wild match marker: Matches any input text from the current position to the end of a statement.  Wild match markers generally match input that may not be a legal expression, such as
#command NOTE <*x*> in Clippers Std.ch, gather the input text to the end of thestatement, and write it to the result text using one of the stringify result markers.

 

Single match marker. Matches all consecutive tokens until a whitespace token.

 

Wildcard match marker: Matches a list of tokens that are an Id, Comma, ? or *. This can be used in commands such as SAVE ALL LIKE a*,b*

 

Extended expression match marker: Matches a regular orextended expression, including a file name or path specification. It is used with the smart stringify result marker to ensure that extended expressions will not get stringified, while normal, unquoted string file specifications will.

 

Optional match clauses are portions of the match pattern enclosed in square brackets ([ ]).  They specify a portion of the match pattern that may be absent from the input text.  An optional clause may contain any of the components allowed within a <matchPattern>, including other optional clauses.
 
Optional match clauses may appear anywhere and in any order in the match pattern and still match input text.  Each match clause may appear only once in the input text.  There are two types of optional match clauses: one is a keyword followed by match marker, and the other is a keyword by itself.  These two types of optional match clauses can match all of the traditional command clauses typical ofthe xBase command set.
 
Optional match clauses are defined with a regular or list match marker to match input text if the clause consists of an argument or a keyword followed by an argument (see the INDEX clause of the USE command in Std.ch).  If the optional match clause consists of a keyword by itself, it is matched with a restricted match marker (see the EXCLUSIVE or SHARED clause of the USE command in Std.ch).
 
In any match pattern, you may not specify adjacent optional match clauses consisting solely of match markers, without generating a compiler error.  You may repeat an optional clause any number of times in the input text, as long as it is not adjacent to any other optional clause.  To write a repeated match clause to the result text, use repeating result clauses in the <resultPattern> definition.