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

Input functions and the markup parser

You can use an input function to generate or pre-process markup that is to be sent to a parser. When an input function is called in a parse context, the input function and the parser run as co-routines. That is, the input function is executed incrementally and streams its output to the parser incrementally. Execution passes back and forth between the parser and the input function until the entire input has been processed. This avoids buffering the entire output of the input function before the parser starts. This saves computer resources and improves performance. You can process very large amounts of data without running into resource problems.

In the following example, the input function parser-feeder generates an XML document by submitting a source. The markup is generated partly in the function itself and partly by find rules fired as a result of the submit statement. The output of the function and the find rules becomes the input to the parser. Element rules then transform the XML into HTML.

  define input function parser-feeder as
     output "<greeting>"
     submit "Hello world."
     output "</greeting>"

  find "world" => planet-name
     output "<planet>"
         || planet-name
         || "</planet>"

  process
     do xml-parse
      scan parser-feeder
        output "<html><body>%c"
            || "</body></html>"
     done

  element "greeting"
     output "<P>%c</P>"

  element "planet"
     output "<B>%c</B>"

Other advantages of using input functions include:

The aided translation types up-translate and context-translate both involve the use of implicit input functions to feed data generated by find rules to the parser.

Debugging input functions in a parser context

In rare cases you may experience problems with the use of input functions in a parser context because of the way OmniMark coordinates the activities of the parser and the input function.

When you use an input function to feed the parser, you have two processes running cooperatively within a single program. OmniMark runs each process in a separate processing domain. Some resources are owned by one domain or the other, while others are shared between the two domains.

If you experience an error in a program that uses input functions, the answer may be found in the following:

Note that it may not always be obvious which co-routine a certain piece of code is running in. For instance, a find rule could be fired either by a submit in an input function or by a submit in an element rule. That rule would be running in one domain in the first case and in the other domain in the second case.

If you write code that depends on the timing of the switching between the input function and the parser, you may need to be aware of the rules OmniMark uses when switching domains.

The old form of input function

In versions of OmniMark prior to version 7, an input function was an action function which was called as an input function by adding the keyword input to the parser invocation:

  define function parser-feeder as
     output "<greeting>"
     submit "Hello world."
     output "</greeting>"

  find "world" => planet-name
     output "<planet>"
         || planet-name
         || "</planet>"

  process
     do xml-parse
      scan input parser-feeder
        output "<html><body>%c"
            || "</body></html>"
     done

  element "greeting"
     output "<P>%c</P>"

  element "planet"
     output "<B>%c</B>"

This form is deprecated but is supported for backward compatibility.

Prerequisite Concepts
     Data types
   Functions
 
  Related Syntax
   do markup-parse
   do sgml-parse
   do xml-parse
 
 

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

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

Copyright © Stilo Corporation, 1988-2005.