Wildcards and ranges

<< Click to Display Table of Contents >>

Navigation:  Details >

Wildcards and ranges

Previous pageReturn to chapter overviewNext page

Wildcards in Gekko follow the convention like for instance a*b?c, meaning: a string that starts with a, is followed by any number of characters, then b, then exactly 1 character, and then c. Ranges can also be used, for instance a..d for the range of characters a, b, c, d.

Because * also means multiplication, in expressions where * is legal raw wildcards like a*b cannot be used, and {'a*b'} should be used instead (for instance prt {'a*b'}; to print all variables starting with a and ending with b, where prt a*b; would try to locate a and b and multiply them). Also, ['a*b'] returns a list of matching variables, and prt ['a*b']; would print out the strings, not the variables.

The logic of wildcard matching is explaned in the main Gekko help system, under "Gekko User Manual", "User manual introduction", "Wildcards". All the wildcard matching revolves around the method SearchFromTo() from Program.cs, which is a general method used for all wildcards and ranges, like for instance copy x*b to y*; (a wildcard), index x*; (a wildcard) or delete xya..xyk; (range). The method is the central hub regarding wildcards in commands like INDEX, DISP, COPY, RENAME, DELETE, WRITE/EXPORT, READ/IMPORT, and having a central hub assures the the wildcard logic is consistent.

SearchFromTo() can for instance handle copy x*b to y*;, where the wildcard x*b is matched (the "from" part), but where there is also something done with the result, because y is put on as prefix in the result (the "to" part). "From" and "to" can also be used with databank designators, so that objects can be moved from one databank to another.

The simpler method Search(), also from Program.cs, calls SearchFromTo() internally, but only uses the "from" part, that is, a simple wildcard search. SearchFromTo() has the following definition:

public static List<ToFrom> SearchFromTo(List names0, List names1, string frombank, string tobank, EWildcardSearchType type, SearchOptions options)  

{...}

 

So it accepts two lists names0 and names1 (these are Gekko lists of IVariable type), and in addition it accepts a frombank and tobank. The type enumeration can be Copy, Delete, Rename, Write, or Search, and reflects the calling command. Finally, there are options, which only contains a field .ignoreErrors (boolean), which can be set to ask Gekko to ignore any errors (for instance if copying a variable onto another variable that already exists).

The code inside SearchFromTo() is long but relatively straightforward, and there are also quite a lot of comments. The methods RangeInBank() and MatchInBank() takes care of the matching, and the latter calls MatchWildcard(), which performs the wildcard matching, which uses the Gekko Wildcard class to convert from a a*b?c type of wildcard into Regex style.

The SearchFromTo() method is basically in two parts, where the first part is the "from" part, for instance finding matching wildcards in a particular databank. After this is done, the "to" part can decorate the results from the "from" part (for instance putting a prefix or a suffix on the variables), and the results may also be redirected to a particular databank (for instance in the COPY command). At the very end of the method, a sanity check is performed to make sure that an object is not for instance copied onto itself.