Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.2 KiB

  1. package ActiveState::Rx;
  2. use strict;
  3. our $VERSION = '0.60';
  4. # <stolen from="re.pm">
  5. sub doit {
  6. my $on = shift;
  7. my $debug = shift || "";
  8. require XSLoader;
  9. XSLoader::load('ActiveState::Rx');
  10. set_debug($debug eq "debug" and $on);
  11. install() if $on;
  12. deinstall() unless $on || $debug;
  13. }
  14. sub import {
  15. shift;
  16. doit(1,@_);
  17. }
  18. sub unimport {
  19. shift;
  20. doit(0,@_);
  21. }
  22. # </stolen>
  23. # Translate a regex hash structure into a more tree-like structure
  24. # that is more easily traversed and analyzed.
  25. sub translate_tree {
  26. my %tree = %{shift()};
  27. my $node = shift; # Starting node.
  28. my @treeroots; # Array of top level tree nodes (roots).
  29. while(defined $node) {
  30. if(ref($tree{$node}) eq 'HASH') {
  31. my %nodeguts = %{$tree{$node}};
  32. # Add the node to the treeroots array only there
  33. # exists a handler function that could some day
  34. # "draw" it. We don't want to mess around with nodes we
  35. # can't handle...
  36. if(defined $nodeguts{TYPE}) {
  37. push @treeroots, _process_node(\%tree, \%nodeguts, $node);
  38. }
  39. else {
  40. print STDERR "Skipping node $node\n";
  41. }
  42. # If the current node didn't give us a next node to traverse to
  43. # then we must give up.
  44. unless($node = $nodeguts{NEXT}) {
  45. last;
  46. }
  47. }
  48. }
  49. return \@treeroots;
  50. }
  51. sub _process_node {
  52. my %tree = %{shift()};
  53. my %nodeguts = %{shift()};
  54. my $nodename = shift();
  55. # print Dumper($nodename);
  56. # print Dumper(\%nodeguts);
  57. $nodeguts{'__this__'} = $nodename;
  58. if($nodeguts{CHILD}) {
  59. # Now build another translated tree based on the child node of
  60. # this node.
  61. my $treerootsref = translate_tree(\%tree, $nodeguts{CHILD});
  62. $nodeguts{CHILD} = $treerootsref;
  63. }
  64. return \%nodeguts;
  65. }
  66. 1;
  67. __END__
  68. =head1 NAME
  69. ActiveState::Rx - Regular Expression Debugger
  70. =head1 DESCRIPTION
  71. Please see L<ActiveState::Rx::Info> for details on how to use Rx.
  72. =head1 AUTHOR
  73. Mark-Jason Dominus <[email protected]>
  74. Ken Simpson <[email protected]>
  75. Neil Watkiss <[email protected]>
  76. =head1 COPYRIGHT
  77. Copyright (c) 2001, ActiveState SRL.