swirl
Guide to OmniMark 7   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
Prerequisite Concepts     Related Syntax  

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 stream 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 stream function spelled-out
     (value stream 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
     Functions
   Pattern matching
 
  Related Syntax
   define function
 
 

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

OmniMark 7.1.2 Documentation Generated: June 28, 2005 at 5:44:40 pm
If you have any comments about this section of the documentation, send email to [email protected]

Copyright © Stilo Corporation, 1988-2005.