4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
0
|
2 |
|
|
3 |
PPDelegateParser subclass:#PPCompositeParser
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'PetitParser-Tools'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!PPCompositeParser class methodsFor:'instance creation'!
|
|
12 |
|
|
13 |
new
|
|
14 |
"Answer a new parser starting at the default start symbol."
|
|
15 |
|
|
16 |
^ self newStartingAt: self startSymbol
|
|
17 |
!
|
|
18 |
|
|
19 |
newStartingAt: aSymbol
|
|
20 |
"Answer a new parser starting at aSymbol."
|
|
21 |
|
|
22 |
^ self basicNew initializeStartingAt: aSymbol
|
|
23 |
! !
|
|
24 |
|
|
25 |
!PPCompositeParser class methodsFor:'accessing'!
|
|
26 |
|
|
27 |
ignoredNames
|
|
28 |
"Answer a collection of instance-variables that should not be automatically initialized with productions, but that are used internal to the composite parser."
|
|
29 |
|
|
30 |
^ PPCompositeParser allInstVarNames
|
|
31 |
!
|
|
32 |
|
|
33 |
startSymbol
|
|
34 |
"Answer the method that represents the default start symbol."
|
|
35 |
|
|
36 |
^ #start
|
|
37 |
! !
|
|
38 |
|
|
39 |
!PPCompositeParser class methodsFor:'parsing'!
|
|
40 |
|
|
41 |
parse: anObject
|
|
42 |
^ self parse: anObject startingAt: self startSymbol
|
|
43 |
!
|
|
44 |
|
|
45 |
parse: anObject onError: aBlock
|
|
46 |
^ self parse: anObject startingAt: self startSymbol onError: aBlock
|
|
47 |
!
|
|
48 |
|
|
49 |
parse: anObject startingAt: aSymbol
|
|
50 |
^ (self newStartingAt: aSymbol) parse: anObject
|
|
51 |
!
|
|
52 |
|
|
53 |
parse: anObject startingAt: aSymbol onError: aBlock
|
|
54 |
^ (self newStartingAt: aSymbol) parse: anObject onError: aBlock
|
|
55 |
! !
|
|
56 |
|
|
57 |
!PPCompositeParser methodsFor:'accessing'!
|
|
58 |
|
|
59 |
start
|
|
60 |
"Answer the production to start this parser with."
|
28
|
61 |
|
0
|
62 |
self subclassResponsibility
|
|
63 |
! !
|
|
64 |
|
|
65 |
!PPCompositeParser methodsFor:'initialization'!
|
|
66 |
|
|
67 |
initializeStartingAt: aSymbol
|
|
68 |
| allVariableNames ignoredVariableNames productionIndexesAndNames |
|
28
|
69 |
self initialize.
|
0
|
70 |
|
|
71 |
"find all the productions that need to be initialized"
|
|
72 |
allVariableNames := self class allInstVarNames
|
|
73 |
collect: [ :each | each asSymbol ].
|
|
74 |
ignoredVariableNames := self class ignoredNames
|
|
75 |
collect: [ :each | each asSymbol ].
|
|
76 |
productionIndexesAndNames := ((1 to: self class instSize)
|
|
77 |
collect: [ :index | index -> (allVariableNames at: index) ])
|
|
78 |
reject: [ :assoc | ignoredVariableNames includes: assoc value ].
|
28
|
79 |
|
0
|
80 |
"initialize productions with an undefined parser to be replaced later"
|
|
81 |
parser := PPUnresolvedParser named: aSymbol.
|
|
82 |
productionIndexesAndNames do: [ :assoc |
|
|
83 |
self instVarAt: assoc key put: (PPUnresolvedParser named: assoc value) ].
|
|
84 |
parser def: (self perform: aSymbol).
|
28
|
85 |
|
0
|
86 |
"resolve unresolved parsers with their actual implementation"
|
|
87 |
productionIndexesAndNames do: [ :assoc |
|
|
88 |
(self respondsTo: assoc value)
|
|
89 |
ifFalse: [ self error: 'Unable to initialize ' , assoc value printString ]
|
|
90 |
ifTrue: [ (self instVarAt: assoc key) def: (self perform: assoc value) ] ]
|
|
91 |
! !
|
|
92 |
|
|
93 |
!PPCompositeParser methodsFor:'querying'!
|
|
94 |
|
|
95 |
productionAt: aSymbol
|
|
96 |
"Answer the production named aSymbol."
|
28
|
97 |
|
0
|
98 |
^ self productionAt: aSymbol ifAbsent: [ nil ]
|
|
99 |
!
|
|
100 |
|
|
101 |
productionAt: aSymbol ifAbsent: aBlock
|
|
102 |
"Answer the production named aSymbol, if there is no such production answer the result of evaluating aBlock."
|
28
|
103 |
|
0
|
104 |
(self class ignoredNames includes: aSymbol asString)
|
|
105 |
ifTrue: [ ^ aBlock value ].
|
|
106 |
(self class startSymbol = aSymbol)
|
|
107 |
ifTrue: [ ^ parser ].
|
|
108 |
^ self instVarAt: (self class allInstVarNames
|
|
109 |
indexOf: aSymbol asString
|
|
110 |
ifAbsent: [ ^ aBlock value ])
|
|
111 |
! !
|
|
112 |
|
|
113 |
!PPCompositeParser class methodsFor:'documentation'!
|
|
114 |
|
28
|
115 |
version
|
|
116 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPCompositeParser.st,v 1.3 2012-05-04 22:02:49 vrany Exp $'
|
|
117 |
!
|
|
118 |
|
|
119 |
version_CVS
|
|
120 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPCompositeParser.st,v 1.3 2012-05-04 22:02:49 vrany Exp $'
|
|
121 |
!
|
|
122 |
|
0
|
123 |
version_SVN
|
28
|
124 |
^ '§Id: PPCompositeParser.st 2 2010-12-17 18:44:23Z vranyj1 §'
|
0
|
125 |
! !
|