perl-regexp-utils

Regexp::Visualize::Simple

Regular expression visualization using Graph::Easy

SYNOPSIS

  use Regexp::Visualize::Simple
  
  $parser = ... Regexp::Parser object ...;
  
  my $v = Regexp::Visualize::Simple->new;
  $v->push_regexp_node ($parser->root);
  
  while ($v->has_regexp_node) {
    my ($g, $index) = $v->next_graph;
    
    # $g is a Graph::Easy object
    print "$index:\n";
    print $g->as_svg;
  }

DESCRIPTION

The Regexp::Visualize::Simple generates a series of Graph::Easy objects, which as a whole represents a regular expression parsed by Regexp::Parser. Generated graphs can be exported to arbitrary image format, such as PNG and SVG, supported by Graph::Easy. As an input any regular expression dialect supported by Regexp::Parser or its subclasses can be used.

It is sometimes impossible or undesired to represents a regular expression as one complete graph. For example, if a regular expression containing (?!...) segment were represented as a graph, it would be difficult to understand. Therefore, the result visualization might sometimes be split into multiple graphs. This is why this module defines iterator methods has_regexp_node and next_graph.

METHODS

$v = Regexp::Visualize::Simple->new;

Creates a new instance of the regular expression visualizer.

$v->push_regexp_node ($node);

Push a regular expression node that represents a subgraph to be visualized.

$node = $v->shift_regexp_node ();

Shifts a regular expression node from the queue hold by the visualizer object, if any, or returns undef.

$boolean = $v->has_regexp_node ();

Returns whether the visualizer object contains one or more nodes in the queue of regular expression nodes to be graphized.

($g, $index) = $v->next_graph ();

Generates a graph from the first node in the queue o the regular expression node hold by the visualizer object.

If there is no node to be graphized in the queue, then a list of two undef values is returned.

Otherwise, a list of the Graph::Easy object generated from the regular expression node and the index number of the graph is returned. The first graph generated by the visualizer object has the index of zero (0), and the next graph has one (1).

DEPENDENCY

This module requires Perl 5.10.0 or later.

This module depends on the Graph::Easy module.

This module assumes the input regular expression nodes implementing Regexp::Parser-compatible interface. Such modules include Regexp::Parser::Perl58 and Regexp::Parser::JavaScript.

SEE ALSO

The latest version of this module is available at https://suika.suikawiki.org/regexp/.

Regular expression visualizer https://suika.suikawiki.org/regexp/visualizer/input. This is a Web interface for this module. Its source code is available at https://suika.suikawiki.org/regexp/visualizer/regexp.cgi,cvslog.

Regexp::Parser::Perl58 - A subclass of Regexp::Parser supporting Perl 5.8 regular expression syntax.

Regexp::Parser::JavaScript - A subclass of Regexp::Parser supporting JavaScript regular expression syntax.

These two modules above are available at https://suika.suikawiki.org/regexp/.

Graph::Easy. This module is available from CPAN.

DEVELOPMENT

CVS log: https://suika.suikawiki.org/regexp/lib/Regexp/Visualize/Simple.pm,cvslog.

Bug tracking system: http://manakai.g.hatena.ne.jp/task/7/.

TODO

Localization / customization support.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2008-2009 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.