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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Mon Dec 8 12:21:26 2008 UTC (15 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.3: +15 -10 lines
++ swe/visualizer/ChangeLog	8 Dec 2008 12:21:06 -0000
2008-12-08  Wakaba  <wakaba@suika.fam.cx>

	* input.html: Added |select| for language selection.

	* regexp.cgi: Don't percent-decode query parameter values decoded
	by Message::CGI::HTTP twice.  Added JavaScript regular expression
	support.  Regular expression input was not expanded in |title|
	elements.

++ swe/lib/Regexp/Parser/ChangeLog	8 Dec 2008 12:17:06 -0000
2008-12-08  Wakaba  <wakaba@suika.fam.cx>

	* JavaScript.pm: New module.

++ swe/lib/Regexp/Visualize/ChangeLog	8 Dec 2008 12:19:40 -0000
2008-12-08  Wakaba  <wakaba@suika.fam.cx>

	* Simple.pm (next_graph): Plot "FAIL" node if necessary.  Don't
	plot "SUCCESS" node if not necessary.
	(add_to_graph): Support for empty []/[^] character classes allowed
	in JavaScript regular expressions.

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

	* Simple.pm (push_regexp_node): Invoke |get_graph_index| to return
	the index of the pushed regexp.  This invocation is necessary such
	that the order the regexps are pushed is reflected to the index.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24