fix GT-K in %er_aliases.
[chise/perl.git] / CHISE_REG.pm
1 #
2 # CHISE_REG.pm
3 # $Id: CHISE_REG.pm,v 1.2 2003-10-08 13:30:29 moro Exp $
4 #
5
6 package CHISE_REG;
7
8 use strict;
9 use warnings;
10 use utf8;
11 use overload;
12
13 sub import {
14   overload::constant ( 'qr' => \&ChiseLikeRegex )
15 }
16
17 sub unimport {
18   overload::remove_constant
19 }
20
21 # データベースの場を指。いずれはlibchiseに...
22 # データベースの全ファイルをchownしないとえないかも
23 my $DB_HOME='';
24 if (-e '/usr/local/lib/chise/char-db') {
25   $DB_HOME = '/usr/local/lib/chise/char-db';
26 } elsif (-e '/sw/lib/xemacs-21.4.11/powerpc-apple-darwin6.6/char-db') {
27   $DB_HOME = '/sw/lib/xemacs-21.4.11/powerpc-apple-darwin6.6/char-db';
28 } elsif (-e '/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db') {
29   $DB_HOME = '/usr/local/lib/xemacs-21.4.11/i686-pc-linux/char-db';
30 } elsif (-e '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db') {
31   $DB_HOME = '/usr/local/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
32 } elsif (-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db'){
33   $DB_HOME = '/usr/local/xemacs-utf2000/lib/xemacs-21.4.11/powerpc-apple-darwin6.4/char-db';
34 } elsif (-e '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db') {
35   $DB_HOME = '/usr/local/lib/xemacs-21.4.10/i686-pc-linux/char-db';
36 } elsif (-e '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db') {
37   $DB_HOME = '/usr/local/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db';
38 } elsif (-e '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db'){
39   $DB_HOME = '/usr/local/xemacs-utf2000/lib/xemacs-21.4.10/powerpc-apple-darwin6.4/char-db';
40 } elsif (-e 'd:/work/chise/char-db'){
41   $DB_HOME = 'd:/work/chise/char-db';
42 } else {
43   print STDERR "CHISE_REG.pm: No database found.\n";
44   print STDERR "CHISE_REG.pm: Please set \$DB_HOME to CHISE.pm.\n";
45   exit 1;
46 }
47
48 #--- 正規表現のCHISE的拡張 ------------------------------------#
49
50 sub ChiseLikeRegex ($) {
51 # 正規表現のオーバーロード
52   my ($RegexLiteral) = @_;
53   #print STDERR "BEFORE: $RegexLiteral\n"; # for debug
54   $RegexLiteral
55     =~ s/\\same_([^_]+)_(\d)/(??{CHISE_REG->chise_backref(\$$2,'$1')})/g;
56   #print STDERR "AFTER:  $RegexLiteral\n"; # for debug
57   return $RegexLiteral;
58 }
59
60 sub chise_backref {
61   my $self = shift;
62   my ($backreference, $feature_name) = @_;
63   #print STDERR "backreference: $backreference\n"; # for debug
64   #print STDERR "feature name:  $feature_name\n";  # for debug
65   my $result = `./chisereg.pl $backreference $DB_HOME $feature_name`;
66   #print STDERR $result, "\n"; # for debug
67   return "[$result]";
68 }
69
70 1;