• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revisionc9396e41e82d6d68468b9a42820aac6ecc961281 (tree)
Time2022-01-15 00:05:17
Authormiyakawataku
Commitermiyakawataku

Log Message

add lhsRepr() to opt-vec-assignment itree

Change Summary

Incremental Difference

diff -r d8e7982c64f5 -r c9396e41e82d src/main/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItree.java
--- a/src/main/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItree.java Fri Jan 14 23:59:56 2022 +0900
+++ b/src/main/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItree.java Sat Jan 15 00:05:17 2022 +0900
@@ -1,6 +1,8 @@
11 package org.kink_lang.kink.internal.program.itree;
22
33 import java.util.List;
4+import java.util.stream.Collectors;
5+import java.util.stream.Stream;
46
57 /**
68 * Assignment in the form {@code [:A :B :C.opt :D.opt] <- xxx}.
@@ -27,6 +29,18 @@
2729 optSyms = List.copyOf(optSyms);
2830 }
2931
32+ /**
33+ * Returns the string representation of the left hand side.
34+ *
35+ * @return the string representation of the left hand side.
36+ */
37+ public String lhsRepr() {
38+ return Stream.concat(
39+ mandatorySyms.stream().map(s -> ":" + s),
40+ optSyms.stream().map(s -> ":" + s + ".opt"))
41+ .collect(Collectors.joining(" ", "[", "]"));
42+ }
43+
3044 @Override
3145 public <T> T accept(ItreeVisitor<T> visitor) {
3246 return visitor.visit(this);
diff -r d8e7982c64f5 -r c9396e41e82d src/test/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItreeTest.java
--- a/src/test/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItreeTest.java Fri Jan 14 23:59:56 2022 +0900
+++ b/src/test/java/org/kink_lang/kink/internal/program/itree/OptVecAssignmentItreeTest.java Sat Jan 15 00:05:17 2022 +0900
@@ -27,6 +27,16 @@
2727 }
2828
2929 @Test
30+ public void test_lhsRepr() {
31+ Itree rhs = new StrItree("Rhs", 20);
32+ OptVecAssignmentItree itree = new OptVecAssignmentItree(
33+ List.of("A", "B"),
34+ List.of("C", "D"),
35+ rhs, 99);
36+ assertThat(itree.lhsRepr()).isEqualTo("[:A :B :C.opt :D.opt]");
37+ }
38+
39+ @Test
3040 public void test_accept() {
3141 Itree rhs = new StrItree("Rhs", 20);
3242 OptVecAssignmentItree itree = new OptVecAssignmentItree(
Show on old repository browser