PPSequenceParser.st
changeset 12 ace2bacc5f6a
parent 4 90de244a7fa2
child 180 48a6757d5f01
equal deleted inserted replaced
11:e6e33e8fe655 12:ace2bacc5f6a
     3 PPListParser subclass:#PPSequenceParser
     3 PPListParser subclass:#PPSequenceParser
     4 	instanceVariableNames:''
     4 	instanceVariableNames:''
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'PetitParser-Parsers'
     7 	category:'PetitParser-Parsers'
     8 !
       
     9 
       
    10 PPSequenceParser comment:'A parser that parses a sequence of parsers.'
       
    11 !
     8 !
    12 
     9 
    13 
    10 
    14 !PPSequenceParser methodsFor:'operations'!
    11 !PPSequenceParser methodsFor:'operations'!
    15 
    12 
    21 	^ self ==> [ :nodes | aBlock valueWithArguments: nodes ]
    18 	^ self ==> [ :nodes | aBlock valueWithArguments: nodes ]
    22 !
    19 !
    23 
    20 
    24 permutation: anArrayOfIntegers
    21 permutation: anArrayOfIntegers
    25 	"Answer a permutation of the receivers sequence."
    22 	"Answer a permutation of the receivers sequence."
    26 
    23 	
    27 	anArrayOfIntegers do: [ :index |
    24 	anArrayOfIntegers do: [ :index |
    28 		(index isInteger and: [ index between: 1 and: parsers size ])
    25 		(index isInteger and: [ index between: 1 and: parsers size ])
    29 			ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ].
    26 			ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ].
    30 	^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ]
    27 	^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ]
    31 ! !
    28 ! !
    32 
    29 
    33 !PPSequenceParser methodsFor:'parsing'!
    30 !PPSequenceParser methodsFor:'parsing'!
    34 
    31 
    35 parseOn: aStream
    32 parseOn: aStream
    36 	"This is optimized code that avoids unnecessary block activations, do not change."
    33 	"This is optimized code that avoids unnecessary block activations, do not change."
    37 
    34 	
    38 	| start elements element |
    35 	| start elements element |
    39 	start := aStream position.
    36 	start := aStream position.
    40 	elements := Array new: parsers size.
    37 	elements := Array new: parsers size.
    41 	1 to: parsers size do: [ :index |
    38 	1 to: parsers size do: [ :index |
    42 		element := (parsers at: index)
    39 		element := (parsers at: index) 
    43 			parseOn: aStream.
    40 			parseOn: aStream.
    44 		element isPetitFailure ifTrue: [
    41 		element isPetitFailure ifTrue: [
    45 			aStream position: start.
    42 			aStream position: start.
    46 			^ element ].
    43 			^ element ].
    47 		elements at: index put: element ].
    44 		elements at: index put: element ].
    48 	^ elements
    45 	^ elements
    49 ! !
    46 ! !
    50 
    47 
    51 !PPSequenceParser class methodsFor:'documentation'!
    48 !PPSequenceParser class methodsFor:'documentation'!
    52 
    49 
       
    50 version
       
    51     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.3 2012-05-04 21:59:14 vrany Exp $'
       
    52 !
       
    53 
       
    54 version_CVS
       
    55     ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.3 2012-05-04 21:59:14 vrany Exp $'
       
    56 !
       
    57 
    53 version_SVN
    58 version_SVN
    54     ^ '$Id: PPSequenceParser.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
    59     ^ '§Id: PPSequenceParser.st 2 2010-12-17 18:44:23Z vranyj1 §'
    55 ! !
    60 ! !