You are here: Wiki>SE Web>PatternMatcherPlugin (29 Jun 2004, precheltPCPOOL.MI.FU-BERLIN.DE)Edit

PatternMatcherPlugin

This is a design document for a plugin yet to be written.

The pattern matcher plugin does three things:
  1. Perform search-and-replace within some subsection of a topic.
  2. Perform search-extract-replace within some subsection of a topic, i.e. the original patterns remain where they are and the modifed copies are collected and printed in one spot.
  3. Collect all occurrences of a pattern and pass them via http to a script for processing; insert the output of the script in the rendered text.

Syntax Rules

  • %REWRITE{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}% Works on the section of the topic from the first occurrence of from to the last occurrence of to, which are Perl regular expressions. In that section, applies something like s/// (the Perl search-and-replace operator) to the topic text. searchfor and replaceby are required; from defaults to "^", to defaults to "$".
  • %GREPREWRITE{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}% As before, but the replacements are not made in the text, but rather all searcgfir matches are extraced, replacements done, and the results inserted in place of the GREPREWRITE call.
  • %CALLALL{searchfor="pattern" from="fpattern" to="tpattern" url="url" argname="name"}% As before, but instead of doing the replacement, the matches are passed to a script and the output is included in place of the CALLALL. The script i
  • %CALLEACH{searchfor="pattern" replaceby="pattern" from="fpattern" to="tpattern"}%
  • %CALLALL{}%

Examples

See the perlre manual page for further possiblities. Perl regular expressions are incredibly powerful!

Plugin Settings

Plugin settings are stored as preferences variables. To reference a plugin setting write %<plugin>_<setting>%, i.e. %INTERWIKIPLUGIN_SHORTDESCRIPTION%

  • One line description, is shown in the TextFormattingRules topic:
    • Set SHORTDESCRIPTION = one line description here

  • Debug plugin: (See output in data/debug.txt)
    • Set DEBUG = 0

  • My own setting:
    • Set HOWTO = got it!

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.

  • Download the ZIP file from the Plugin web (see below)
  • Unzip PatternMatcherPlugin.zip in your twiki installation directory. Content:
    File: Description:
    data/TWiki/PatternMatcherPlugin.txt Plugin topic
    data/TWiki/PatternMatcherPlugin.txt,v Plugin topic repository
    lib/TWiki/Plugins/PatternMatcherPlugin.pm Plugin Perl module
  • Test if the installation was successful:
    • enter samples here

Plugin Info

Plugin Author: TWiki:Main/LutzPrechelt
Plugin Version: 29 Jun 2004 (V1.000)
Change History:  
29 Jun 2004: Initial version
CPAN Dependencies: none
Other Dependencies: none
Perl Version: 5.005
TWiki:Plugins/Benchmark: GoodStyle nn%, FormattedSearch nn%, PatternMatcherPlugin nn%
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/PatternMatcherPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/PatternMatcherPluginDev

Related Topics: DefaultPreferences, System.Plugins, TWiki:Plugins/PhantomPlugin

-- TWiki:Main/LutzPrechelt - 29 Jun 2004
Topic revision: r2 - 29 Jun 2004, precheltPCPOOL.MI.FU-BERLIN.DE
 
  • Printable version of this topic (p) Printable version of this topic (p)