swirl
Guide to OmniMark 9   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
Prerequisite Concepts     Related Topics  

Patterns: dynamically defined

An OmniMark pattern includes string expressions. While static strings are the most common form of string expressions used in patterns, any form of string expression is allowed. This means you can dynamically define a pattern using an operator or function to supply a string expression in a pattern. The following code dynamically defines a pattern using the date operator:

  find "Authorized on: " date("=xY-=M-=D") 

This code does the same thing using a function:

  define string function today
     as
     return date("=xY-=M-=D")
     
  find "Authorized on: " today  

You can pass variables to a function used to dynamically define a pattern, including pattern variables from earlier in the pattern. The following code uses a function to match a pattern in which a digit is followed by the spelled-out version of the number:

  define string function spelled-out 
     (value string the-digit)
     as
     do scan the-digit
        match "1" return "one"
        match "2" return "two"
        match "3" return "three"
     done  
     return ""
  
  process
     submit "Please submit 3 (three) copies"
     
  find digit => the-digit blank "(" spelled-out(the-digit) ")"

Note that this function returns an empty string if the digit passed does not match any of the cases it deals with. This empty string becomes part of the pattern, which means that the rule given would match the string "Please submit 5 () copies" though not the string "Please submit 5 (five) copies". Every stream function must return a value, so make sure you correctly anticipate the impact of all possible return values on your pattern matching.

Prerequisite Concepts
 
  Related Topics
 
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 9.1.0 Documentation Generated: September 2, 2010 at 1:35:14 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2010.