1 package org.simantics.scl.compiler.elaboration.expressions;
3 import org.simantics.scl.compiler.common.names.Names;
4 import org.simantics.scl.compiler.constants.StringInterpolation;
5 import org.simantics.scl.compiler.elaboration.contexts.TranslationContext;
6 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
7 import org.simantics.scl.compiler.errors.Locations;
9 public class EStringLiteral extends ASTExpression {
11 public String[] strings;
12 public Expression[] expressions;
14 public EStringLiteral(String[] strings, Expression[] expressions) {
15 this.strings = strings;
16 this.expressions = expressions;
20 public Expression resolve(TranslationContext context) {
21 Expression[] components = new Expression[expressions.length];
22 SCLValue showForPrinting = context.getEnvironment().getValue(Names.Prelude_showForPrinting);
23 for(int i=0;i<expressions.length;++i)
24 components[i] = new EApply(new EConstant(showForPrinting), expressions[i]);
25 return new EApply(new ELiteral(new StringInterpolation(strings)), components).resolve(context);
29 public void setLocationDeep(long loc) {
30 if(location == Locations.NO_LOCATION) {
32 for(Expression expression : expressions)
33 expression.setLocationDeep(loc);
38 public Expression accept(ExpressionTransformer transformer) {
39 return transformer.transform(this);
43 public Expression resolveAsPattern(TranslationContext context) {
44 for(int i=0;i<expressions.length;++i)
45 expressions[i] = expressions[i].resolveAsPattern(context);
46 if(expressions.length > 1) {
47 context.getErrorLog().log(location, "String interpolation can be a pattern only if has one hole.");
50 return new EApply(new ELiteral(new StringInterpolation(strings)), expressions);
54 public void accept(ExpressionVisitor visitor) {