Next: Backend construction   Previous: Set up Active Contents handling   Contents: Contents

The parser call

And now, the parser can be called. Because it is implemented by a class, we first need to build an object, which is simple.


  # build parser
  my $parser=new PerlPoint::Parser;

The objects method run() invokes the parser to process all document sources. Various parameters control how this task is performed and need to be set according to the converter options. It should be sufficient to simply copy this call and to slightly adapt it.


  # call parser
  $parser->run(
               stream          => \@streamData,
               files           => \@ARGV,

               filter          => 'perl|sdf|html',

               safe            => exists $options{activeContents} ? $safe : undef,

               activeBaseData  => {
                                   targetLanguage => 'SDF',
                                   userSettings   => {map {$_=>1} exists $options{set} ? @{$options{set}} : ()},
                                  },

               predeclaredVars => {
                                   CONVERTER_NAME    => basename($0),
                                   CONVERTER_VERSION => do {no strict 'refs'; ${join('::', __PACKAGE__, 'VERSION')}},
                                  },

               vispro          => 1,

               cache           =>   (exists $options{cache} ? CACHE_ON : CACHE_OFF)
                                  + (exists $options{cacheCleanup} ? CACHE_CLEANUP : 0),

               display         =>   DISPLAY_ALL
                                  + (exists $options{noinfo} ? DISPLAY_NOINFO : 0)
                                  + (exists $options{nowarn} ? DISPLAY_NOWARN : 0),

               trace           =>   TRACE_NOTHING
                                  + ((exists $options{trace} and $options{trace} &  1) ? TRACE_PARAGRAPHS : 0)
                                  + ((exists $options{trace} and $options{trace} &  2) ? TRACE_LEXER      : 0)
                                  + ((exists $options{trace} and $options{trace} &  4) ? TRACE_PARSER     : 0)
                                  + ((exists $options{trace} and $options{trace} &  8) ? TRACE_SEMANTIC   : 0)
                                  + ((exists $options{trace} and $options{trace} & 16) ? TRACE_ACTIVE     : 0),
              ) or exit(1);

So what happens here?

stream
passes a reference to an array which will be used to store the stream element in. It is suggested to pass an empty array (but currently new fields will be added, so existing entries will not be damaged).
files
passes an array of document source files to parse.
filter
declares which formats are allowed to be embedded or included. You can accept all formats which can be processed by the software which has to deal with the converter product, and "perl" to provide the full power of Active Contents. All formats not matching the filter will be ignored.
safe
pass the prepared variable $safe.
activeBaseData
sets up a hash reference which is made accessible to Active Contents as $main::PerlPoint. The keys targetLanguage and userSettings are provided by convention, but you may add whatever keys you need.
vispro
if set to a true value, the parser will display runtime informations.
cache
used to pass the cache settings. Please copy this code.
display
used to pass the display settings. Please copy this code.
trace
used to pass the trace settings. Please copy this code.

run() returns a true value if parsing was successful. It is recommended to evaluate this code and to stop processing in case of an error.


  # call parser
  $parser->run(...) or exit(1);
Next: Backend construction   Previous: Set up Active Contents handling   Contents: Contents