/[suikacvs]/webroot/regexp/visualizer/regexp.cgi
Suika

Diff of /webroot/regexp/visualizer/regexp.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sun Dec 7 09:48:35 2008 UTC revision 1.2 by wakaba, Sun Dec 7 10:24:21 2008 UTC
# Line 5  use feature 'state'; Line 5  use feature 'state';
5  use CGI::Carp qw(fatalsToBrowser);  use CGI::Carp qw(fatalsToBrowser);
6    
7  use lib q[/home/wakaba/work/manakai2/lib];  use lib q[/home/wakaba/work/manakai2/lib];
8  use Message::CGI::Util qw/percent_decode/;  use Message::CGI::Util qw/percent_decode htescape/;
9    use Message::CGI::HTTP;
10    
11  use Regexp::Parser;  use Regexp::Parser;
12  use Graph::Easy;  use Graph::Easy;
# Line 25  my $assertion_map = { Line 26  my $assertion_map = {
26      '<unlessm' => '(?<!)',      '<unlessm' => '(?<!)',
27  };  };
28    
29  my $regexp = percent_decode $ENV{QUERY_STRING};  my $cgi = Message::CGI::HTTP->new;
30    
31    my $regexp = percent_decode $cgi->get_parameter ('s') // '';
32  $regexp = '(?:)' unless length $regexp;  $regexp = '(?:)' unless length $regexp;
33    
34  my $parser = Regexp::Parser->new;  my $parser = Regexp::Parser->new;
# Line 90  elsif ($ret == \$rhs) { Line 93  elsif ($ret == \$rhs) {
93  package main;  package main;
94    
95  $parser->parse ($regexp);  $parser->parse ($regexp);
96    my $eregexp = htescape $regexp;
97    
98    if ($parser->errnum) {
99      binmode STDOUT, ':encoding(utf-8)';
100      print "Content-Type: text/html; charset=utf-8\n\n";
101      print q[<!DOCTYPE HTML><html lang=en>
102    <title>Regular expression visualizer: $eregexp</title>
103    <link rel="stylesheet" href="/www/style/html/xhtml"/>
104    </head>
105    <body>
106    <h1>Regular expression visualizer</h1>
107    
108    <p>Input: <code>], $eregexp, q[</code></p>
109    
110    <p>Error: ], htescape ($parser->errmsg);
111      exit;
112    }
113    
114  binmode STDOUT, ':encoding(utf-8)';  binmode STDOUT, ':encoding(utf-8)';
115  print "Content-Type: application/xhtml+xml; charset=utf-8\n\n";  print "Content-Type: application/xhtml+xml; charset=utf-8\n\n";
116    
 print $parser->errnum, $parser->errmsg;  
   
117  add_regexp ($parser->root);  add_regexp ($parser->root);
118    
119  print q[<html xmlns="http://www.w3.org/1999/xhtml">  print q[<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
120  <head><title></title>  <head><title>Regular expression visualizer: $eregexp</title>
121    <link rel="stylesheet" href="/www/style/html/xhtml"/>
122  </head>  </head>
123  <body>];  <body>
124    <h1>Regular expression visualizer</h1>
125    
126    <p>Input: <code>], $eregexp, q[</code></p>];
127    
128  my @regexp;  my @regexp;
129  while (@regexp) {  while (@regexp) {
130    my $nodes = shift @regexp;    my $nodes = shift @regexp;
131    
132    my $index = get_graph_index ($nodes);    my $index = get_graph_index ($nodes);
133    print "<section><h1>Regexp #$index</h1>\n\n";    print "<section><h2>Regexp #$index</h2>\n\n";
134    
135    my $g = generate_graph ($nodes);    my $g = generate_graph ($nodes);
136    print $g->as_svg;    print $g->as_svg;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24