SimpleNode lastFunction = null;
AtomicBoolean startSingle = new AtomicBoolean(false);
AtomicBoolean startDouble = new AtomicBoolean(false);
AtomicBoolean startFunction = new AtomicBoolean(false);
LiteralNode imageToken = null;
for (SimpleToken token : tokens) {
// break if eol
if (token.getType().isEol()) {
break;
}
// create a node from the token
SimpleNode node = createNode(token, startSingle, startDouble, startFunction);
if (node != null) {
// keep state of last single/double
if (node instanceof SingleQuoteStart) {
lastSingle = node;
} else if (node instanceof DoubleQuoteStart) {
lastDouble = node;
} else if (node instanceof SimpleFunctionStart) {
lastFunction = node;
}
// a new token was created so the current image token need to be added first
if (imageToken != null) {
nodes.add(imageToken);
imageToken = null;
}
// and then add the created node
nodes.add(node);
// continue to next
continue;
}
// if no token was created then its a character/whitespace/escaped symbol
// which we need to add together in the same image
if (imageToken == null) {
imageToken = new LiteralExpression(token);
}
imageToken.addText(token.getText());
}
// append any leftover image tokens (when we reached eol)
if (imageToken != null) {
nodes.add(imageToken);