|
1 "{ Package: 'stx:goodies/xmlsuite/relaxng' }" |
|
2 |
|
3 "{ NameSpace: RNG }" |
|
4 |
|
5 Object subclass:#ContentModelAutomaton |
|
6 instanceVariableNames:'transitions terminalPatterns initialTransitions canBeEmpty' |
|
7 classVariableNames:'' |
|
8 poolDictionaries:'' |
|
9 category:'Relax NG-Patterns' |
|
10 ! |
|
11 |
|
12 |
|
13 !ContentModelAutomaton class methodsFor:'instance creation'! |
|
14 |
|
15 new |
|
16 ^ self basicNew initialize. |
|
17 |
|
18 "Created: / 30-04-2005 / 20:21:10 / janfrog" |
|
19 ! ! |
|
20 |
|
21 !ContentModelAutomaton methodsFor:'accessing'! |
|
22 |
|
23 newContext |
|
24 |
|
25 ^ContentModelAutomaton for:self |
|
26 |
|
27 "Created: / 01-05-2005 / 12:49:54 / janfrog" |
|
28 ! ! |
|
29 |
|
30 !ContentModelAutomaton methodsFor:'initialization'! |
|
31 |
|
32 initialize |
|
33 |
|
34 transitions := Dictionary new. |
|
35 initialTransitions := Dictionary new. |
|
36 terminalPatterns := Set new. |
|
37 |
|
38 "Created: / 30-04-2005 / 20:21:10 / janfrog" |
|
39 "Modified: / 30-04-2005 / 22:19:31 / janfrog" |
|
40 ! |
|
41 |
|
42 initializeFor:aPattern |
|
43 |
|
44 | node | |
|
45 node := aPattern node. |
|
46 canBeEmpty := node canBeEmpty. |
|
47 |
|
48 node contentModelInitialPatterns do:[:pattern| |
|
49 initialTransitions at:pattern name put:pattern |
|
50 ]. |
|
51 |
|
52 terminalPatterns := |
|
53 node contentModelFinalPatterns asSet. |
|
54 |
|
55 node generateTransitionsIn:self. |
|
56 node children do:[:child| |
|
57 self |
|
58 makeTransitionsFrom:child patternsThatCanBeLast |
|
59 to:child patternsThatCanBeNext |
|
60 ] |
|
61 |
|
62 "Created: / 30-04-2005 / 20:50:40 / janfrog" |
|
63 "Modified: / 02-05-2005 / 12:07:21 / janfrog" |
|
64 ! ! |
|
65 |
|
66 !ContentModelAutomaton methodsFor:'printing'! |
|
67 |
|
68 printOn:aStream |
|
69 |
|
70 self |
|
71 printTransitions:initialTransitions |
|
72 stateName:'#initialState' |
|
73 final:(initialTransitions isEmpty) |
|
74 on:aStream. |
|
75 |
|
76 |
|
77 transitions keysAndValuesDo:[:key :value| |
|
78 aStream cr. |
|
79 self |
|
80 printTransitions:value |
|
81 stateName:key nameForPrint |
|
82 final:(terminalPatterns includes:key) |
|
83 on:aStream. |
|
84 |
|
85 ] |
|
86 |
|
87 "Created: / 30-04-2005 / 21:50:28 / janfrog" |
|
88 "Modified: / 01-05-2005 / 12:43:56 / janfrog" |
|
89 ! |
|
90 |
|
91 printTransitions:aDictionary stateName:aString final:aBoolean on:aStream |
|
92 |
|
93 aStream nextPut:$[ ; nextPutAll:aString ; nextPut:$]. |
|
94 aBoolean ifTrue:[aStream nextPutAll:' (final)']. |
|
95 aStream cr. |
|
96 aDictionary values do:[:pattern| |
|
97 aStream nextPutAll:' -> [',pattern nameForPrint,']'; cr |
|
98 ]. |
|
99 |
|
100 "Created: / 30-04-2005 / 21:22:29 / janfrog" |
|
101 "Modified: / 01-05-2005 / 12:43:26 / janfrog" |
|
102 ! ! |
|
103 |
|
104 !ContentModelAutomaton methodsFor:'queries'! |
|
105 |
|
106 isTerminalPattern:aPatternOrNil |
|
107 |
|
108 "nil is special value for initial state" |
|
109 |
|
110 ^aPatternOrNil ifNil:[ |
|
111 canBeEmpty or:[initialTransitions isEmpty]. |
|
112 ] ifNotNil:[ |
|
113 terminalPatterns includes:aPatternOrNil |
|
114 ] |
|
115 |
|
116 "Created: / 01-05-2005 / 12:55:33 / janfrog" |
|
117 "Modified: / 02-05-2005 / 12:06:49 / janfrog" |
|
118 ! ! |
|
119 |
|
120 !ContentModelAutomaton methodsFor:'states'! |
|
121 |
|
122 makeTransitionsFrom:sourcePatterns to:targetPatterns |
|
123 |
|
124 sourcePatterns asCollection do:[:source| |
|
125 | dict | |
|
126 "/source isPatternNode ifTrue:[self halt]. |
|
127 dict := transitions at:source ifAbsentPut:[Dictionary new]. |
|
128 targetPatterns asCollection do:[:target| |
|
129 dict at:target name put:target |
|
130 ] |
|
131 ] |
|
132 |
|
133 "Created: / 30-04-2005 / 20:23:36 / janfrog" |
|
134 "Modified: / 01-05-2005 / 12:24:59 / janfrog" |
|
135 ! |
|
136 |
|
137 nextStateFrom:aPatternOrNil forTerminal:aString |
|
138 |
|
139 "if aPatternOrNil is nil, initialTransitions is used" |
|
140 "returns next pattern or nil if none found" |
|
141 |
|
142 aPatternOrNil ifNil:[ |
|
143 ^initialTransitions |
|
144 at:aString ifAbsent:[nil] |
|
145 ]. |
|
146 |
|
147 ^(transitions at:aPatternOrNil ifAbsent:[^nil]) |
|
148 at:aString |
|
149 ifAbsent:[nil] |
|
150 |
|
151 "Created: / 30-04-2005 / 20:44:28 / janfrog" |
|
152 "Modified: / 01-05-2005 / 12:57:48 / janfrog" |
|
153 ! ! |
|
154 |
|
155 !ContentModelAutomaton class methodsFor:'documentation'! |
|
156 |
|
157 version |
|
158 ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/relaxng/RNG__ContentModelAutomaton.st,v 1.1.1.1 2005-11-01 22:07:13 vranyj1 Exp $' |
|
159 ! ! |