Skip to content

Commit

Permalink
fixed bugs with tuples and nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Dec 18, 2024
1 parent 91fcd88 commit e5d3b2a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.usethesource.vallang.IMapWriter;
import io.usethesource.vallang.ISetWriter;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IString;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextReader;
Expand Down Expand Up @@ -726,9 +727,16 @@ public IValue visitNode(Type type) throws IOException {

Map<String,IValue> kws = new HashMap<>();
Map<String,IValue> args = new HashMap<>();
String name = "object";

while (in.hasNext()) {
String kwName = nextName();

if (kwName.equals("_name")) {
name = ((IString) read(in, TF.stringType())).getValue();
continue;
}

boolean positioned = kwName.startsWith("arg");

if (!isNull()) { // lookahead for null to give default parameters the preference.
Expand Down Expand Up @@ -761,7 +769,7 @@ public IValue visitNode(Type type) throws IOException {
.map(e -> e.getValue())
.toArray(IValue[]::new);

return vf.node("object", argArray, kws);
return vf.node(name, argArray, kws);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ public Void visitTuple(ITuple o) throws IOException {
@Override
public Void visitNode(INode o) throws IOException {
out.beginObject();
out.name("_name");
out.value(o.getName());

int i = 0;
for (IValue arg : o) {
out.name("arg" + i++);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ test bool originTracking() {
@synopsis{Normalizer used to create lists out of other containers}
value allContainersToLists(set[value] x) = [*x];
value allContainersToLists(value tup) = [] when \tuple(_) := typeOf(tup), "<tup>" == "\<\>";
value allContainersToList(<x>) = [x];
value allContainersToList(<x,y>) = [x,y];
value allContainersToList(<x,y,z>) = [x,y,z];
default value allContainersToLists(value x) = x;
test bool accurateParseErrors() {
Expand Down

0 comments on commit e5d3b2a

Please sign in to comment.