MCPcopy Create free account
hub / github.com/PCGen/pcgen / toTree

Method toTree

code/src/java/pcgen/util/ParameterTree.java:185–263  ·  view source on GitHub ↗
(final String source, final boolean operatorNeeded)

Source from the content-addressed store, hash-verified

183 }
184
185 private static ParameterTree toTree(final String source, final boolean operatorNeeded) throws ParseException
186 {
187 String s = source;
188 // the opertor matcher
189 Matcher oM = OPERATOR_PATTERN.matcher(s);
190 ParameterTree cT = new ParameterTree(""); //current Tree
191
192 boolean hasO = oM.find();
193
194 // this is for operators, obviously
195 if (hasO && operatorNeeded)
196 {
197 if (oM.start() != 0)
198 {
199 throw new ParseException("expected \"" + s + "\" to begin with an operator");
200 }
201 else
202 {
203 cT = new ParameterTree(oM.group());
204 final int end = oM.end();
205 s = s.substring(end);
206 oM = OPERATOR_PATTERN.matcher(s);
207 hasO = oM.find();
208 }
209 }
210
211 int start = 0;
212
213 while (hasO)
214 {
215
216 final String pre = s.substring(start, oM.start());
217
218 final ParameterTree P = new ParameterTree(pre); // pre Tree
219 final ParameterTree R = new ParameterTree(oM.group()); // root Tree - must be an operator (it matched)
220
221 // is the "root" of the current tree an operator
222 final Matcher cM = OPERATOR_PATTERN.matcher(cT.getContents());
223
224 if (cM.find())
225 {
226 cT.setRightTree(P);
227 R.setLeftTree(cT);
228 // right branch of R is null
229 }
230 else
231 {
232 R.setLeftTree(P);
233 // can discard current tree, it's empty (first iteration)
234 }
235
236 // root becomes new current tree
237 cT = R;
238
239 start = oM.end();
240 hasO = oM.find();
241 }
242

Callers 1

makeTreeMethod · 0.95

Calls 4

getContentsMethod · 0.95
setRightTreeMethod · 0.95
setLeftTreeMethod · 0.95
startMethod · 0.65

Tested by

no test coverage detected