4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
0
|
2 |
|
|
3 |
PPListParser subclass:#PPSequenceParser
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'PetitParser-Parsers'
|
|
8 |
!
|
|
9 |
|
|
10 |
PPSequenceParser comment:'A parser that parses a sequence of parsers.'
|
|
11 |
!
|
|
12 |
|
|
13 |
|
|
14 |
!PPSequenceParser methodsFor:'operations'!
|
|
15 |
|
|
16 |
, aRule
|
|
17 |
^ self copyWith: aRule
|
|
18 |
!
|
|
19 |
|
|
20 |
map: aBlock
|
|
21 |
^ self ==> [ :nodes | aBlock valueWithArguments: nodes ]
|
|
22 |
!
|
|
23 |
|
|
24 |
permutation: anArrayOfIntegers
|
|
25 |
"Answer a permutation of the receivers sequence."
|
4
|
26 |
|
0
|
27 |
anArrayOfIntegers do: [ :index |
|
|
28 |
(index isInteger and: [ index between: 1 and: parsers size ])
|
|
29 |
ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ].
|
|
30 |
^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ]
|
|
31 |
! !
|
|
32 |
|
|
33 |
!PPSequenceParser methodsFor:'parsing'!
|
|
34 |
|
|
35 |
parseOn: aStream
|
|
36 |
"This is optimized code that avoids unnecessary block activations, do not change."
|
4
|
37 |
|
0
|
38 |
| start elements element |
|
|
39 |
start := aStream position.
|
|
40 |
elements := Array new: parsers size.
|
|
41 |
1 to: parsers size do: [ :index |
|
4
|
42 |
element := (parsers at: index)
|
0
|
43 |
parseOn: aStream.
|
|
44 |
element isPetitFailure ifTrue: [
|
|
45 |
aStream position: start.
|
|
46 |
^ element ].
|
|
47 |
elements at: index put: element ].
|
|
48 |
^ elements
|
|
49 |
! !
|
|
50 |
|
|
51 |
!PPSequenceParser class methodsFor:'documentation'!
|
|
52 |
|
|
53 |
version_SVN
|
4
|
54 |
^ '$Id: PPSequenceParser.st,v 1.2 2012-01-13 11:22:50 cg Exp $'
|
0
|
55 |
! !
|