* It may be not very accurate working as JavaScript lexer.
*/
private static class DotSeparatedExpression extends DialogLogic.Expression {
static Optional<DialogLogic.Expression> parse(String string) {
if (string.length() == 0) {
return createErrorOptional(new Message(Messages.LogicImpl_ENTER_EXPRESSION,
MessagePriority.BLOCKING_PROBLEM));
}
List<String> parts = new ArrayList<String>();
int pos = 0;
while (true) {
if (pos >= string.length() || string.charAt(pos) != '.') {
return createErrorOptional(new Message(Messages.LogicImpl_DOT_EXPECTED,
MessagePriority.BLOCKING_PROBLEM));
}
pos++;
int partStartPos = pos;
if (pos >= string.length()) {
return createErrorOptional(
new Message(Messages.LogicImpl_ENTER_AFTER_DOT, MessagePriority.BLOCKING_INFO));
}
if (!Character.isJavaIdentifierStart(string.codePointAt(pos))) {
return createErrorOptional(new Message(Messages.LogicImpl_INVALID_COMPONENT_START,
MessagePriority.BLOCKING_PROBLEM));
}
pos = string.offsetByCodePoints(pos, 1);
while (pos < string.length() && string.charAt(pos) != '.') {
if (!Character.isJavaIdentifierPart(string.codePointAt(pos))) {
return createErrorOptional(new Message(Messages.LogicImpl_INVALID_COMPONENT_CHAR,
MessagePriority.BLOCKING_PROBLEM));
}
pos = string.offsetByCodePoints(pos, 1);
}
parts.add(string.substring(partStartPos, pos));