diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-11-14 14:30:50 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-11-14 14:30:50 +0000 |
| commit | 8a7cb643ac9b0e895123c176803af15b75f90cf1 (patch) | |
| tree | 046f0b48f76734451fb0c8a39236212e6108bf6f /src/main/java/org/zwobble/couscous/ast/WhileNode.java | |
| parent | f398933835e7fa7a80b0abd7feda6790370804c8 (diff) | |
Parse while loops
Diffstat (limited to 'src/main/java/org/zwobble/couscous/ast/WhileNode.java')
| -rw-r--r-- | src/main/java/org/zwobble/couscous/ast/WhileNode.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/couscous/ast/WhileNode.java b/src/main/java/org/zwobble/couscous/ast/WhileNode.java new file mode 100644 index 0000000..0a67aef --- /dev/null +++ b/src/main/java/org/zwobble/couscous/ast/WhileNode.java @@ -0,0 +1,55 @@ +package org.zwobble.couscous.ast; + +import com.google.common.base.Objects; +import org.zwobble.couscous.ast.visitors.StatementNodeMapper; + +import java.util.List; + +public class WhileNode implements StatementNode { + public static WhileNode whileLoop(ExpressionNode condition, List<StatementNode> body) { + return new WhileNode(condition, body); + } + + private final ExpressionNode condition; + private final List<StatementNode> body; + + public WhileNode(ExpressionNode condition, List<StatementNode> body) { + this.condition = condition; + this.body = body; + } + + public ExpressionNode getCondition() { + return condition; + } + + public List<StatementNode> getBody() { + return body; + } + + @Override + public <T> T accept(StatementNodeMapper<T> visitor) { + return visitor.visit(this); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + WhileNode whileNode = (WhileNode) o; + return Objects.equal(condition, whileNode.condition) && + Objects.equal(body, whileNode.body); + } + + @Override + public int hashCode() { + return Objects.hashCode(condition, body); + } + + @Override + public String toString() { + return "WhileNode(" + + "condition=" + condition + + ", body=" + body + + ')'; + } +} |
