compiler/PPCTrimNode.st
changeset 452 9f4558b3be66
parent 438 20598d7ce9fa
child 515 b5316ef15274
equal deleted inserted replaced
438:20598d7ce9fa 452:9f4558b3be66
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
     1 "{ Package: 'stx:goodies/petitparser/compiler' }"
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 PPCDelegateNode subclass:#PPCTrimNode
     5 PPCSequenceNode subclass:#PPCTrimNode
     6 	instanceVariableNames:''
     6 	instanceVariableNames:''
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Nodes'
     9 	category:'PetitCompiler-Nodes'
    10 !
    10 !
    11 
    11 
    12 !PPCTrimNode methodsFor:'accessing'!
    12 !PPCTrimNode methodsFor:'accessing'!
    13 
    13 
       
    14 child
       
    15     
       
    16     ^ children at: 2
       
    17 !
       
    18 
       
    19 child: anObject
       
    20     
       
    21     children at: 2 put: anObject
       
    22 !
       
    23 
    14 prefix
    24 prefix
    15 	^ #trim
    25     ^ #trim
       
    26 !
       
    27 
       
    28 trimmer
       
    29     ^ children at: 1
       
    30 !
       
    31 
       
    32 trimmer: anObject
       
    33     children at: 1 put: anObject
       
    34 ! !
       
    35 
       
    36 !PPCTrimNode methodsFor:'analysis'!
       
    37 
       
    38 acceptsEpsilon
       
    39     ^ self child acceptsEpsilonOpenSet: (IdentitySet with: self).
       
    40 !
       
    41 
       
    42 acceptsEpsilonOpenSet: set
       
    43     (set includes: self child) ifFalse: [ 
       
    44         set add: self child.
       
    45         ^ self child acceptsEpsilonOpenSet: set 
       
    46     ].
       
    47     ^ false
       
    48 ! !
       
    49 
       
    50 !PPCTrimNode methodsFor:'initialization'!
       
    51 
       
    52 defaultTrimmer
       
    53     | message |
       
    54     message := PPCMessagePredicateNode new 
       
    55             message: #isSeparator;
       
    56             yourself.
       
    57     ^ PPCStarNode new
       
    58         child: message;
       
    59         yourself.
       
    60 !
       
    61 
       
    62 initialize
       
    63     super initialize.
       
    64     children := Array new: 2.
       
    65     children at: 1 put: self defaultTrimmer.
    16 ! !
    66 ! !
    17 
    67 
    18 !PPCTrimNode methodsFor:'visiting'!
    68 !PPCTrimNode methodsFor:'visiting'!
    19 
    69 
    20 accept: visitor
    70 accept: visitor
    21 	^ visitor visitTrimNode: self
    71     ^ visitor visitTrimNode: self
    22 ! !
    72 ! !
    23 
    73