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 |
|
180
|
11 |
!PPSequenceParser methodsFor:'*petitanalyzer-private'!
|
|
12 |
|
|
13 |
cycleSet: aDictionary
|
|
14 |
| firstSet |
|
|
15 |
1 to: parsers size do: [ :index |
|
|
16 |
firstSet := aDictionary at: (parsers at: index).
|
|
17 |
(firstSet anySatisfy: [ :each | each isNullable ])
|
|
18 |
ifFalse: [ ^ parsers copyFrom: 1 to: index ] ].
|
|
19 |
^ parsers
|
|
20 |
!
|
|
21 |
|
|
22 |
firstSets: aFirstDictionary into: aSet
|
|
23 |
| nullable |
|
|
24 |
parsers do: [ :parser |
|
|
25 |
nullable := false.
|
|
26 |
(aFirstDictionary at: parser) do: [ :each |
|
|
27 |
each isNullable
|
|
28 |
ifTrue: [ nullable := true ]
|
|
29 |
ifFalse: [ aSet add: each ] ].
|
|
30 |
nullable
|
|
31 |
ifFalse: [ ^ self ] ].
|
|
32 |
aSet add: PPSentinel instance
|
|
33 |
!
|
|
34 |
|
|
35 |
followSets: aFollowDictionary firstSets: aFirstDictionary into: aSet
|
|
36 |
parsers keysAndValuesDo: [ :index :parser |
|
|
37 |
| followSet firstSet |
|
|
38 |
followSet := aFollowDictionary at: parser.
|
|
39 |
index = parsers size
|
|
40 |
ifTrue: [ followSet addAll: aSet ]
|
|
41 |
ifFalse: [
|
|
42 |
(self class withAll: (parsers
|
|
43 |
copyFrom: index + 1 to: parsers size))
|
|
44 |
firstSets: aFirstDictionary
|
|
45 |
into: (firstSet := IdentitySet new).
|
|
46 |
(firstSet anySatisfy: [ :each | each isNullable ])
|
|
47 |
ifTrue: [ followSet addAll: aSet ].
|
|
48 |
followSet addAll: (firstSet
|
|
49 |
reject: [ :each | each isNullable ]) ] ]
|
|
50 |
! !
|
|
51 |
|
0
|
52 |
!PPSequenceParser methodsFor:'operations'!
|
|
53 |
|
|
54 |
, aRule
|
|
55 |
^ self copyWith: aRule
|
|
56 |
!
|
|
57 |
|
|
58 |
permutation: anArrayOfIntegers
|
|
59 |
"Answer a permutation of the receivers sequence."
|
12
|
60 |
|
0
|
61 |
anArrayOfIntegers do: [ :index |
|
|
62 |
(index isInteger and: [ index between: 1 and: parsers size ])
|
|
63 |
ifFalse: [ self error: 'Invalid permutation index: ' , index printString ] ].
|
|
64 |
^ self ==> [ :nodes | anArrayOfIntegers collect: [ :index | nodes at: index ] ]
|
|
65 |
! !
|
|
66 |
|
180
|
67 |
!PPSequenceParser methodsFor:'operators-mapping'!
|
|
68 |
|
|
69 |
map: aBlock
|
|
70 |
^ aBlock numArgs = self children size
|
|
71 |
ifTrue: [ self ==> [ :nodes | aBlock valueWithArguments: nodes ] ]
|
|
72 |
ifFalse: [ self error: aBlock numArgs asString , ' arguments expected.' ]
|
|
73 |
! !
|
|
74 |
|
0
|
75 |
!PPSequenceParser methodsFor:'parsing'!
|
|
76 |
|
|
77 |
parseOn: aStream
|
|
78 |
"This is optimized code that avoids unnecessary block activations, do not change."
|
12
|
79 |
|
0
|
80 |
| start elements element |
|
|
81 |
start := aStream position.
|
|
82 |
elements := Array new: parsers size.
|
|
83 |
1 to: parsers size do: [ :index |
|
12
|
84 |
element := (parsers at: index)
|
0
|
85 |
parseOn: aStream.
|
|
86 |
element isPetitFailure ifTrue: [
|
|
87 |
aStream position: start.
|
|
88 |
^ element ].
|
|
89 |
elements at: index put: element ].
|
|
90 |
^ elements
|
|
91 |
! !
|
|
92 |
|
|
93 |
!PPSequenceParser class methodsFor:'documentation'!
|
|
94 |
|
12
|
95 |
version
|
180
|
96 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
|
12
|
97 |
!
|
|
98 |
|
|
99 |
version_CVS
|
180
|
100 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
|
12
|
101 |
!
|
|
102 |
|
0
|
103 |
version_SVN
|
180
|
104 |
^ '$Id: PPSequenceParser.st,v 1.4 2014-03-04 14:33:25 cg Exp $'
|
0
|
105 |
! !
|
180
|
106 |
|