use of dyvilx.tools.compiler.ast.expression.StringInterpolationExpr in project Dyvil by Dyvil.
the class ProcessedText method resolve.
@Override
public IValue resolve(MarkerList markers, IContext context) {
final int startLine = this.position.startLine();
final int startColumn = this.position.startColumn();
final StringInterpolationExpr parts = new StringInterpolationExpr();
final String text = this.text;
final int length = text.length();
int prev = 0;
for (int startIndex = 0; startIndex < length; ) {
final int c = text.codePointAt(startIndex);
// advance to an identifier character
if (!Character.isJavaIdentifierStart(c)) {
startIndex += Character.charCount(c);
continue;
}
final int endIndex = identifierEnd(text, startIndex + 1, length);
final String key = text.substring(startIndex, endIndex);
final IDataMember field = context.resolveField(Name.fromRaw(key));
if (field != null && (field.isLocal() || field.hasModifier(Modifiers.PUBLIC))) {
// append contents before this identifier
parts.append(new StringValue(text.substring(prev, startIndex)));
final SourcePosition position = SourcePosition.apply(startLine, startColumn + startIndex, startColumn + endIndex);
parts.append(new FieldAccess(position, null, field));
// advance to the end of the identifier
prev = endIndex;
startIndex = endIndex;
continue;
}
startIndex += Character.charCount(c);
}
if (prev != length) {
parts.append(new StringValue(text.substring(prev, length)));
}
return new WriteCall(parts.resolve(markers, context));
}
Aggregations