Changeset a3a9eb7
- Timestamp:
- Sep 30, 2009, 1:02:36 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 69c27e6
- Parents:
- 6035008
- git-author:
- David Benjamin <davidben@mit.edu> (09/23/09 00:55:19)
- git-committer:
- David Benjamin <davidben@mit.edu> (09/30/09 01:02:36)
- Location:
- perl/lib/BarnOwl/Complete
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl/Complete/Client.pm
r6035008 ra3a9eb7 7 7 8 8 use BarnOwl::Completion::Util qw(complete_flags); 9 use BarnOwl::Complete::Filter qw(complete_filter_name complete_filter_expr); 9 10 10 11 my @all_colors = qw(default … … 42 43 sub complete_command { return sort @BarnOwl::all_commands; } 43 44 sub complete_color { return @all_colors; } 44 sub complete_filter_name { return @{BarnOwl::all_filters()}; }45 45 sub complete_variable { return @{BarnOwl::all_variables()}; } 46 46 sub complete_style { return @{BarnOwl::all_styles()}; } 47 48 my %filter_cmds = (49 sender => \&BarnOwl::Complete::Zephyr::complete_user,50 recipient => \&BarnOwl::Complete::Zephyr::complete_user,51 class => \&BarnOwl::Complete::Zephyr::complete_class,52 instance => \&BarnOwl::Complete::Zephyr::complete_instance,53 opcode => \&BarnOwl::Complete::Zephyr::complete_opcode,54 realm => \&BarnOwl::Complete::Zephyr::complete_realm,55 body => undef,56 hostname => undef,57 type => sub { qw(zephyr aim admin); },58 direction => sub { qw(in out none); },59 login => sub { qw(login logout none); },60 filter => \&complete_filter_name,61 perl => undef,62 );63 64 # Returns:65 # - where to look next after pulling out an expression66 # - $INCOMPLETE if this cannot form a complete expression (or w/e)67 # - pushes to completion list as it finds valid completions68 69 my $INCOMPLETE = -1;70 sub _complete_filter_expr {71 # Takes as arguments context and the index into $ctx->words where the72 # filter expression starts73 my $ctx = shift;74 my $start = shift;75 my $o_comp = shift;76 my $end = $ctx->word;77 78 # Grab an expression; we don't allow empty79 my $i = $start;80 $i = _complete_filter_primitive_expr($ctx, $start, $o_comp);81 return $INCOMPLETE if $start == $INCOMPLETE;82 83 while ($i <= $end) {84 if ($i == $end) {85 # We could and/or another clause86 push @$o_comp, qw(and or);87 return $end; # Or we could let the parent do his thing88 }89 90 if ($ctx->words->[$i] ne 'and' && $ctx->words->[$i] ne 'or') {91 return $i; # We're done. Let the parent do his thing92 }93 94 # Eat the and/or95 $i++;96 97 # Grab an expression98 $i = _complete_filter_primitive_expr($ctx, $i, $o_comp);99 return $INCOMPLETE if $i == $INCOMPLETE;100 }101 102 return $i; # Well, it looks like we're happy103 # (Actually, I'm pretty sure this never happens...)104 }105 106 sub _complete_filter_primitive_expr {107 my $ctx = shift;108 my $start = shift;109 my $o_comp = shift;110 my $end = $ctx->word;111 112 if ($start >= $end) {113 push @$o_comp, "(";114 push @$o_comp, qw(true false not);115 push @$o_comp, keys %filter_cmds;116 return $INCOMPLETE;117 }118 119 my $word = $ctx->words->[$start];120 if ($word eq "(") {121 $start = _complete_filter_expr($ctx, $start+1, $o_comp);122 return $INCOMPLETE if $start == $INCOMPLETE;123 124 # Now, we expect a ")"125 if ($start >= $end) {126 push @$o_comp, ")";127 return $INCOMPLETE;128 }129 if ($ctx->words->[$start] ne ')') {130 # User is being confusing. Give up.131 return $INCOMPLETE;132 }133 return $start+1; # Eat the )134 } elsif ($word eq "not") {135 # We just want another primitive expression136 return _complete_filter_primitive_expr($ctx, $start+1, $o_comp);137 } elsif ($word eq "true" || $word eq "false") {138 # No arguments139 return $start+1; # Eat the boolean. Mmmm, tasty.140 } else {141 # It's of the form 'CMD ARG'142 return $start+2 if ($start+1 < $end); # The user supplied the argument143 144 # complete the argument145 my $arg_func = $filter_cmds{$word};146 push @$o_comp, ($arg_func ? ($arg_func->()) : ());147 return $INCOMPLETE;148 }149 }150 151 sub complete_filter_expr {152 my $ctx = shift;153 154 my @completions = ();155 _complete_filter_expr($ctx, 0, \@completions);156 # Get rid of duplicates and sort157 my %hash = ();158 @hash{@completions} = ();159 @completions = sort keys %hash;160 return @completions;161 }162 47 163 48 sub complete_help {
Note: See TracChangeset
for help on using the changeset viewer.