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