This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows to destructure a object to assign to several values at the same time. E.g.: let a, b = [1, 2] require(a == 1 and b == 2, "failed") Any object with a `destruct` method returning a tuple can be used. Vararg can be used as the last value, e.g. let a, b... = [1, 2, 3, 4] require(a == 1 and b == [2, 3, 4], "failed") Some built-in objects and augmentation are added to be compliant.
- Loading branch information
Showing
9 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/fr/insalyon/citi/golo/compiler/parser/ASTDestructuringAssignment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2012-2015 Institut National des Sciences Appliquées de Lyon (INSA-Lyon) | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package fr.insalyon.citi.golo.compiler.parser; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
import static java.util.Collections.unmodifiableList; | ||
|
||
public class ASTDestructuringAssignment extends GoloASTNode { | ||
|
||
private ASTLetOrVar.Type type; | ||
private List<String> names; | ||
private boolean isVarargs = false; | ||
|
||
public ASTDestructuringAssignment(int id) { | ||
super(id); | ||
} | ||
|
||
public ASTDestructuringAssignment(GoloParser p, int id) { | ||
super(p, id); | ||
} | ||
|
||
public ASTLetOrVar.Type getType() { | ||
return type; | ||
} | ||
|
||
public void setType(ASTLetOrVar.Type type) { | ||
this.type = type; | ||
} | ||
|
||
public List<String> getNames() { | ||
return unmodifiableList(names); | ||
} | ||
|
||
public void setNames(List<String> names) { | ||
this.names = new ArrayList<>(); | ||
this.names.addAll(names); | ||
} | ||
|
||
public void setVarargs(boolean b) { | ||
this.isVarargs = b; | ||
} | ||
|
||
public boolean isVarargs() { | ||
return this.isVarargs; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ASTDestructuringAssignment{" + | ||
"type=" + type + | ||
", names=" + names + | ||
", varargs=" + isVarargs + | ||
"}"; | ||
} | ||
|
||
@Override | ||
public Object jjtAccept(GoloParserVisitor visitor, Object data) { | ||
return visitor.visit(this, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters