ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/lib/cf/match.pm
(Generate patch)

Comparing deliantra/server/lib/cf/match.pm (file contents):
Revision 1.13 by root, Sun Oct 11 23:51:47 2009 UTC vs.
Revision 1.15 by root, Mon Oct 12 17:37:43 2009 UTC

110 110
111=item in env 111=item in env
112 112
113Replaces all objects by their containing object, if they have one. 113Replaces all objects by their containing object, if they have one.
114 114
115=item in arch
116
117Replaces all objects by their archetypes.
118
115=item in map 119=item in map
116 120
117Replaces all objects by the objects that are on the same mapspace as them. 121Replaces all objects by the objects that are on the same mapspace as them.
118 122
119=item in <cond> 123=item in <condition>
120 124
121Finds all context objects matching the condition, and then puts their 125Finds all context objects matching the condition, and then puts their
122inventories into the context set. 126inventories into the context set.
123 127
124Note that C<in inv> is simply a special case of an C<< in <cond> >> that 128Note that C<in inv> is simply a special case of an C<< in <condition> >> that
125matches any object. 129matches any object.
126 130
127Example: find all spells inside potions inside the inventory of the context 131Example: find all spells inside potions inside the inventory of the context
128object(s). 132object(s).
129 133
287=item match(match) 291=item match(match)
288 292
289An independent match - semantics like C<count>, except it only matters 293An independent match - semantics like C<count>, except it only matters
290whether the match finds any object (which is faster). 294whether the match finds any object (which is faster).
291 295
292=item dump 296=item dump()
293 297
294Dumps the object to the server log when executed, and evaluates to true. 298Dumps the object to the server log when executed, and evaluates to true.
295 299
296Note that logical operations are short-circuiting, so this only dumps 300Note that logical operations are short-circuiting, so this only dumps
297potions: 301potions:
298 302
299 type=POTION and dump 303 type=POTION and dump()
300 304
301=back 305=back
302 306
303=head2 GRAMMAR 307=head2 GRAMMAR
304 308
313 root = 'object' | 'self' | 'source' | 'originator' 317 root = 'object' | 'self' | 'source' | 'originator'
314 chain = condition 318 chain = condition
315 | chain also deep 'in' set 319 | chain also deep 'in' set
316 also = nothing | 'also' 320 also = nothing | 'also'
317 deep = nothing | 'deep' 321 deep = nothing | 'deep'
318 set = 'inv' | 'env' | 'map' 322 set = 'inv' | 'env' | 'arch' | 'map'
319 323
320 empty = 324 empty =
321 325
322 # boolean matching condition 326 # boolean matching condition
323 327
324 condition = factor 328 condition = factor
325 | factor 'and'? cond 329 | factor 'and'? condition
326 | factor 'or' cond 330 | factor 'or' condition
327 331
328 factor = 'not' factor 332 factor = 'not' factor
329 | '(' cond ')' 333 | '(' condition ')'
330 | expr 334 | expr
331 | expr operator constant 335 | expr operator constant
332 336
333 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>=' 337 operator = '=' | '==' | '!=' | '<' | '<=' | '>' | '>='
334 338
391 }, 395 },
392 match => sub { 396 match => sub {
393 local $all = 0; 397 local $all = 0;
394 '(scalar ' . &match ('$_') . ')' 398 '(scalar ' . &match ('$_') . ')'
395 }, 399 },
396 );
397
398 our %special = (
399 any => sub {
400 1
401 },
402 dump => sub { 400 dump => sub {
403 'do { 401 'do {
404 warn "cf::match::match dump:\n" 402 warn "cf::match::match dump:\n"
405 . "self: " . eval { $self->name } . "\n" 403 . "self: " . eval { $self->name } . "\n"
406 . $_->as_string; 404 . $_->as_string;
407 1 405 1
408 }'; 406 }';
409 }, 407 },
410 ); 408 );
411 409
410 our %special = (
411 any => sub {
412 1
413 },
414 );
415
412 sub constant { 416 sub constant {
413 ws; 417 ws;
414 418
415 return $1 if /\G([\-\+0-9\.]+)/gc; 419 return $1 if /\G([\-\+0-9\.]+)/gc;
416 return "cf::$1" if /\G([A-Z0-9_]+)/gc; 420 return "cf::$1" if /\G([A-Z0-9_]+)/gc;
527 531
528 while () { 532 while () {
529 ws; 533 ws;
530 534
531 # first check some stop-symbols, so we don't have to backtrack 535 # first check some stop-symbols, so we don't have to backtrack
532 if (/\G(?=also\b|deep\b|in\b|of\b\)|$)/gc) { 536 if (/\G(?=also\b|deep\b|in\b|of\b\)|\z)/gc) {
537 pos = pos; # argh. the misop hits again. again. again. again. you die.
533 last; 538 last;
534 539
535 } elsif (/\Gor\b/gc) { 540 } elsif (/\Gor\b/gc) {
536 $res .= " || "; 541 $res .= " || ";
537 542
557 my $deep = /\Gdeep\s+/gc + 0; 562 my $deep = /\Gdeep\s+/gc + 0;
558 563
559 if (/\Gin\s+/gc) { 564 if (/\Gin\s+/gc) {
560 my $expand; 565 my $expand;
561 566
562 if (/\G(inv|env|map)\b/gc) { 567 if (/\G(inv|env|map|arch)\b/gc) {
563 if ($1 eq "inv") { 568 if ($1 eq "inv") {
564 $expand = "map \$_->inv,"; 569 $expand = "map \$_->inv,";
565 } elsif ($1 eq "env") { 570 } elsif ($1 eq "env") {
566 $expand = "map \$_->env // (),"; 571 $expand = "map \$_->env // (),";
572 } elsif ($1 eq "arch") {
573 $expand = "map \$_->arch,";
567 } elsif ($1 eq "map") { 574 } elsif ($1 eq "map") {
568 $expand = "map \$_->map->at (\$_->x, \$_->y),"; 575 $expand = "map \$_->map->at (\$_->x, \$_->y),";
569 } 576 }
570 } else { 577 } else {
571 $expand = "map \$_->inv, grep { " . condition . " }"; 578 $expand = "map \$_->inv, grep { " . condition . " }";
610 my $res; 617 my $res;
611 618
612 eval { 619 eval {
613 $res = cf::match::parser::match "\$object"; 620 $res = cf::match::parser::match "\$object";
614 621
615 /\G\s*$/gc 622 /\G$/gc
616 or die "unexpected trailing characters after match\n"; 623 or die "unexpected trailing characters after match\n";
617 }; 624 };
618 625
619 if ($@) { 626 if ($@) {
620 my $ctx = 20; 627 my $ctx = 20;
627 634
628 $res 635 $res
629} 636}
630 637
631if (0) {#d# 638if (0) {#d#
632 die parse 'applied', 1; 639 die parse 'type=SPELL_EFFECT and match(name="bullet" in arch)', 1;
633 exit 0; 640 exit 0;
634} 641}
635 642
636=item cf::match::match $match, $object[, $self[, $source[, $originator]]] 643=item cf::match::match $match, $object[, $self[, $source[, $originator]]]
637 644

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines