Skip to content

Commit

Permalink
Parse simple text literal
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Sep 20, 2022
1 parent 8612d25 commit 0354a6e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions engine/runtime/src/main/java/org/enso/compiler/TreeToIr.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.enso.compiler.core.IR$Expression$Binding;
import org.enso.compiler.core.IR$Expression$Block;
import org.enso.compiler.core.IR$Literal$Number;
import org.enso.compiler.core.IR$Literal$Text;
import org.enso.compiler.core.IR$Module$Scope$Definition;
import org.enso.compiler.core.IR$Module$Scope$Definition$Data;
import org.enso.compiler.core.IR$Module$Scope$Definition$Method$Binding;
Expand Down Expand Up @@ -690,6 +691,11 @@ yield switch (op.codeRepr()) {
case Tree.Group group -> {
yield translateExpression(group.getBody(), moreArgs, insideTypeSignature, isMethod);
}
case Tree.TextLiteral txt -> {
var fullTxt = txt.codeRepr().trim();
var t = fullTxt.substring(1, fullTxt.length() - 1);
yield new IR$Literal$Text(t, getIdentifiedLocation(txt), meta(), diag());
}
default -> throw new UnhandledEntity(tree, "translateExpression");
};
/*
Expand Down Expand Up @@ -859,8 +865,8 @@ IR.Expression translateDecimalLiteral(
*
* @param literal the literal to translate
* @return the [[IR]] representation of `literal`
def translateLiteral(literal: AST.Literal): Expression =
*
IR.Expression translateLiteral(Tree.TextLiteral literal) {
literal match {
case AST.Literal.Number(base, number) =>
if (base.isDefined) {
Expand Down Expand Up @@ -926,7 +932,7 @@ case TextUnclosed(_) =>
}
case _ => throw new UnhandledEntity(literal, "processLiteral")
}
/*
private def parseFmtSegments(
literal: AST,
segments: Seq[AST.Literal.Text.Segment[AST]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ public void testExportFromAsExport() throws Exception {
parseTest("from prj.Data.Foo as Bar export Baz, Quux");
}

@Test
public void testTextLiteral() throws Exception {
parseTest("""
main = "I'm an inline raw text!"
""");
}

@SuppressWarnings("unchecked")
private void parseTest(String code) throws UnsupportedSyntaxException, IOException {
var src = Source.newBuilder("enso", code, "test-" + Integer.toHexString(code.hashCode()) + ".enso").build();
Expand Down

0 comments on commit 0354a6e

Please sign in to comment.