|
1 "{ Package: 'squeak:petitparser' }" |
|
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." |
|
26 |
|
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." |
|
37 |
|
38 | start elements element | |
|
39 start := aStream position. |
|
40 elements := Array new: parsers size. |
|
41 1 to: parsers size do: [ :index | |
|
42 element := (parsers at: index) |
|
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 |
|
54 ^ '$Id: PPSequenceParser.st,v 1.1 2011-08-18 18:56:17 cg Exp $' |
|
55 ! ! |