1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.themis.lethe.analysis;
18
19 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20 import io.github.tonywasher.joceanus.themis.exc.ThemisDataException;
21
22 import java.util.Deque;
23 import java.util.Iterator;
24
25
26
27
28 public class ThemisAnalysisStatement
29 implements ThemisAnalysisProcessed {
30
31
32
33 public interface ThemisAnalysisStatementHolder {
34
35
36
37
38
39 Iterator<ThemisAnalysisStatement> statementIterator();
40 }
41
42
43
44
45 private final ThemisAnalysisKeyWord theControl;
46
47
48
49
50 private final ThemisAnalysisStack theLines;
51
52
53
54
55
56
57
58
59 ThemisAnalysisStatement(final ThemisAnalysisParser pParser,
60 final ThemisAnalysisLine pLine) throws OceanusException {
61 this(pParser, null, pLine);
62 }
63
64
65
66
67
68
69
70
71
72 ThemisAnalysisStatement(final ThemisAnalysisParser pParser,
73 final ThemisAnalysisKeyWord pControl,
74 final ThemisAnalysisLine pLine) throws OceanusException {
75 this(pControl, ThemisAnalysisBuilder.parseTrailers(pParser, pLine));
76 checkSeparator();
77 }
78
79
80
81
82
83
84
85 ThemisAnalysisStatement(final ThemisAnalysisEmbedded pEmbedded) throws OceanusException {
86 this(null, pEmbedded);
87 }
88
89
90
91
92
93
94
95
96 ThemisAnalysisStatement(final ThemisAnalysisKeyWord pControl,
97 final ThemisAnalysisEmbedded pEmbedded) throws OceanusException {
98 this(pControl, new ThemisAnalysisStack(pEmbedded));
99 pEmbedded.postProcessLines();
100 }
101
102
103
104
105
106
107 ThemisAnalysisStatement(final Deque<ThemisAnalysisElement> pParams) {
108 this(null, pParams);
109 }
110
111
112
113
114
115
116 ThemisAnalysisStatement(final ThemisAnalysisStack pStack) {
117 this(null, pStack);
118 }
119
120
121
122
123
124
125
126 ThemisAnalysisStatement(final ThemisAnalysisKeyWord pControl,
127 final Deque<ThemisAnalysisElement> pParams) {
128 theControl = pControl;
129 theLines = new ThemisAnalysisStack(pParams);
130 }
131
132
133
134
135
136
137
138 ThemisAnalysisStatement(final ThemisAnalysisKeyWord pControl,
139 final ThemisAnalysisStack pStack) {
140 theControl = pControl;
141 theLines = pStack;
142 }
143
144
145
146
147
148
149 void checkSeparator() throws OceanusException {
150 final ThemisAnalysisScanner myScanner = new ThemisAnalysisScanner(theLines);
151 final boolean isSep = myScanner.checkForSeparator(ThemisAnalysisChar.COMMA);
152 if (isSep) {
153 throw new ThemisDataException("Multi-statement");
154 }
155 }
156
157 @Override
158 public int getNumLines() {
159 return theLines.size();
160 }
161
162
163
164
165
166
167 public boolean nullParameters() {
168 return theLines.isEmpty();
169 }
170
171
172
173
174
175
176 public ThemisAnalysisElement getEmbedded() {
177 final ThemisAnalysisElement myLast = theLines.peekLastLine();
178 return myLast instanceof ThemisAnalysisEmbedded myEmbedded
179 ? myEmbedded.getContents().peekFirst()
180 : null;
181 }
182
183 @Override
184 public String toString() {
185 final String myParms = theLines.toString();
186 return theControl == null ? myParms : theControl + " " + myParms;
187 }
188 }