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

Contents of /webroot/regexp/visualizer/regexp.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Sun Dec 7 11:46:05 2008 UTC (15 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +13 -398 lines
++ swe/visualizer/ChangeLog	7 Dec 2008 11:45:48 -0000
	* regexp.cgi: Parser patch and graph constructor codes moved into
	their own modules.

2008-12-07  Wakaba  <wakaba@suika.fam.cx>

++ swe/lib/Regexp/Parser/ChangeLog	7 Dec 2008 11:45:06 -0000
2008-12-07  Wakaba  <wakaba@suika.fam.cx>

	* Perl58.pm: New module.

	* ChangeLog: New file.

++ swe/lib/Regexp/ChangeLog	7 Dec 2008 11:01:48 -0000
2008-12-07  Wakaba  <wakaba@suika.fam.cx>

	* ChangeLog: New file.

	* Parser/: New directory.

++ swe/lib/Regexp/Visualize/ChangeLog	7 Dec 2008 11:44:58 -0000
2008-12-07  Wakaba  <wakaba@suika.fam.cx>

	* Simple.pm: New module.

	* ChangeLog: New file.


++ swe/lib/ChangeLog	7 Dec 2008 11:01:35 -0000
2008-12-07  Wakaba  <wakaba@suika.fam.cx>

	* ChangeLog: New file.

	* Regexp/: New directory.


++ ChangeLog	7 Dec 2008 11:01:21 -0000
	* lib/: New directory.

2008-12-07  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use warnings;
4     use feature 'state';
5     use CGI::Carp qw(fatalsToBrowser);
6    
7 wakaba 1.3 use FindBin;
8     use lib qq[$FindBin::Bin/../lib];
9 wakaba 1.1 use lib q[/home/wakaba/work/manakai2/lib];
10 wakaba 1.2 use Message::CGI::Util qw/percent_decode htescape/;
11     use Message::CGI::HTTP;
12 wakaba 1.1
13 wakaba 1.3 use Regexp::Parser::Perl58;
14 wakaba 1.1
15 wakaba 1.2 my $cgi = Message::CGI::HTTP->new;
16    
17     my $regexp = percent_decode $cgi->get_parameter ('s') // '';
18 wakaba 1.1 $regexp = '(?:)' unless length $regexp;
19    
20 wakaba 1.3 my $parser = Regexp::Parser::Perl58->new;
21 wakaba 1.1
22 wakaba 1.3 eval {
23     $parser->parse ($regexp);
24     };
25 wakaba 1.2 my $eregexp = htescape $regexp;
26    
27     if ($parser->errnum) {
28     binmode STDOUT, ':encoding(utf-8)';
29     print "Content-Type: text/html; charset=utf-8\n\n";
30     print q[<!DOCTYPE HTML><html lang=en>
31     <title>Regular expression visualizer: $eregexp</title>
32     <link rel="stylesheet" href="/www/style/html/xhtml"/>
33     </head>
34     <body>
35     <h1>Regular expression visualizer</h1>
36    
37     <p>Input: <code>], $eregexp, q[</code></p>
38    
39     <p>Error: ], htescape ($parser->errmsg);
40     exit;
41     }
42 wakaba 1.1
43 wakaba 1.3 require Regexp::Visualize::Simple;
44     my $v = Regexp::Visualize::Simple->new;
45     $v->push_regexp_node ($parser->root);
46    
47 wakaba 1.1 binmode STDOUT, ':encoding(utf-8)';
48     print "Content-Type: application/xhtml+xml; charset=utf-8\n\n";
49    
50 wakaba 1.2 print q[<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
51     <head><title>Regular expression visualizer: $eregexp</title>
52     <link rel="stylesheet" href="/www/style/html/xhtml"/>
53 wakaba 1.1 </head>
54 wakaba 1.2 <body>
55     <h1>Regular expression visualizer</h1>
56    
57     <p>Input: <code>], $eregexp, q[</code></p>];
58 wakaba 1.1
59 wakaba 1.3 while ($v->has_regexp_node) {
60     my ($g, $index) = $v->next_graph;
61 wakaba 1.1
62 wakaba 1.2 print "<section><h2>Regexp #$index</h2>\n\n";
63 wakaba 1.1 print $g->as_svg;
64     print "</section>\n";
65     }
66    
67     print q[</body></html>];
68    

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24