package scotch.compiler.syntax.pattern;
import static lombok.AccessLevel.PACKAGE;
import static scotch.compiler.syntax.builder.BuilderUtil.require;
import java.util.Optional;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import scotch.compiler.analyzer.DependencyAccumulator;
import scotch.compiler.analyzer.NameAccumulator;
import scotch.compiler.analyzer.NameQualifier;
import scotch.compiler.analyzer.TypeChecker;
import scotch.compiler.syntax.builder.SyntaxBuilder;
import scotch.compiler.syntax.scope.Scope;
import scotch.compiler.syntax.value.Value;
import scotch.compiler.text.SourceLocation;
import scotch.compiler.syntax.type.Type;
@AllArgsConstructor(access = PACKAGE)
@EqualsAndHashCode(callSuper = false)
@ToString(exclude = "sourceLocation")
public class IgnorePattern extends PatternMatch {
public static Builder builder() {
return new Builder();
}
private final SourceLocation sourceLocation;
private final Type type;
@Override
public PatternMatch accumulateDependencies(DependencyAccumulator state) {
return this;
}
@Override
public PatternMatch accumulateNames(NameAccumulator state) {
return this;
}
@Override
public PatternMatch bind(Value argument, Scope scope) {
return this;
}
@Override
public PatternMatch bindMethods(TypeChecker state) {
return this;
}
@Override
public PatternMatch bindTypes(TypeChecker state) {
return withType(state.generate(type));
}
@Override
public PatternMatch checkTypes(TypeChecker state) {
return this;
}
@Override
public SourceLocation getSourceLocation() {
return sourceLocation;
}
@Override
public Type getType() {
return type;
}
@Override
public PatternMatch qualifyNames(NameQualifier state) {
return this;
}
@Override
public void reducePatterns(PatternReducer reducer) {
// intentionally empty
}
@Override
public PatternMatch withType(Type type) {
return new IgnorePattern(sourceLocation, type);
}
public static class Builder implements SyntaxBuilder<IgnorePattern> {
private Optional<SourceLocation> sourceLocation = Optional.empty();
private Optional<Type> type = Optional.empty();
private Builder() {
// intentionally empty
}
@Override
public IgnorePattern build() {
return new IgnorePattern(
require(sourceLocation, "Source location"),
require(type, "Type")
);
}
@Override
public Builder withSourceLocation(SourceLocation sourceLocation) {
this.sourceLocation = Optional.of(sourceLocation);
return this;
}
public Builder withType(Type type) {
this.type = Optional.of(type);
return this;
}
}
}