analyzer/PPSearcher.st
changeset 205 0aa4e27a9bfc
child 293 064fd167c58a
equal deleted inserted replaced
204:223004340c43 205:0aa4e27a9bfc
       
     1 "{ Package: 'stx:goodies/petitparser/analyzer' }"
       
     2 
       
     3 PPProcessor subclass:#PPSearcher
       
     4 	instanceVariableNames:'answer'
       
     5 	classVariableNames:''
       
     6 	poolDictionaries:''
       
     7 	category:'PetitAnalyzer-Core'
       
     8 !
       
     9 
       
    10 
       
    11 !PPSearcher methodsFor:'initialization'!
       
    12 
       
    13 setAnswer: anObject
       
    14 	answer := anObject
       
    15 ! !
       
    16 
       
    17 !PPSearcher methodsFor:'private'!
       
    18 
       
    19 answer
       
    20 	^ answer
       
    21 ! !
       
    22 
       
    23 !PPSearcher methodsFor:'public'!
       
    24 
       
    25 execute: aParser
       
    26 	"Perform the search rules of the receiver on aParser. Answer the result of the search."
       
    27 
       
    28 	^ self execute: aParser initialAnswer: nil
       
    29 !
       
    30 
       
    31 execute: aParser initialAnswer: anObject
       
    32 	"Perform the search rules of the receiver on aParser. Inject anObject into the matches and answer the result."
       
    33 
       
    34 	| previous |
       
    35 	previous := context.
       
    36 	answer := anObject.
       
    37 	context := Dictionary new.
       
    38 	aParser allParsersDo: [ :each | 
       
    39 		self performRulesOn: each ].
       
    40 	context := previous.
       
    41 	^ answer
       
    42 ! !
       
    43 
       
    44 !PPSearcher methodsFor:'rules'!
       
    45 
       
    46 matches: aParser do: anAnswerBlock
       
    47 	"Add a search expression aParser, evaluate anAnswerBlock with the matched node and the previous answer."
       
    48 
       
    49 	self addRule: (PPSearchRule searchFor: aParser thenDo: anAnswerBlock)
       
    50 !
       
    51 
       
    52 matchesAnyOf: aCollectionOfParsers do: anAnswerBlock
       
    53 	"Add a collection of search expressions aCollectionOfParsers, evaluate anAnswerBlock with the matched node and the previous answer."
       
    54 	
       
    55 	aCollectionOfParsers
       
    56 		do: [ :each | self matches: each do: anAnswerBlock ]
       
    57 ! !
       
    58 
       
    59 !PPSearcher class methodsFor:'documentation'!
       
    60 
       
    61 version
       
    62     ^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPSearcher.st,v 1.1 2014-03-04 15:42:25 cg Exp $'
       
    63 !
       
    64 
       
    65 version_CVS
       
    66     ^ '$Header: /cvs/stx/stx/goodies/petitparser/analyzer/PPSearcher.st,v 1.1 2014-03-04 15:42:25 cg Exp $'
       
    67 ! !
       
    68