Skip to content

Commit

Permalink
ERROR: parameterize Problem.describe
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Oct 10, 2021
1 parent 55f7e7c commit 1d1980f
Show file tree
Hide file tree
Showing 37 changed files with 125 additions and 99 deletions.
7 changes: 4 additions & 3 deletions api/src/main/java/org/aya/api/error/Problem.java
Expand Up @@ -6,6 +6,7 @@
import kala.collection.SeqLike;
import kala.collection.immutable.ImmutableSeq;
import kala.tuple.Tuple;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.util.WithPos;
import org.aya.pretty.doc.Doc;
import org.aya.pretty.error.PrettyError;
Expand Down Expand Up @@ -34,7 +35,7 @@ enum Stage {
}

@NotNull SourcePos sourcePos();
@NotNull Doc describe();
@NotNull Doc describe(DistillerOptions options);
@NotNull Severity level();
default @NotNull Stage stage() {
return Stage.OTHER;
Expand Down Expand Up @@ -74,7 +75,7 @@ default boolean isError() {
case INFO -> Doc.plain("Info:");
case ERROR -> Doc.plain("Error:");
};
var doc = Doc.sep(tag, Doc.align(describe()));
var doc = Doc.sep(tag, Doc.align(describe(DistillerOptions.DEFAULT)));
var hint = hint();
return hint instanceof Doc.Empty ? doc : Doc.vcat(
doc,
Expand All @@ -83,7 +84,7 @@ default boolean isError() {
}

default @NotNull String computeFullErrorMessage() {
if (sourcePos() == SourcePos.NONE) return describe().commonRender();
if (sourcePos() == SourcePos.NONE) return describe(DistillerOptions.DEFAULT).commonRender();
return toPrettyError().toDoc().commonRender();
}

Expand Down
3 changes: 2 additions & 1 deletion api/src/main/java/org/aya/api/error/Reporter.java
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.api.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.pretty.doc.Doc;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -28,7 +29,7 @@ default void reportString(@NotNull String s) {
return Severity.INFO;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.plain(s);
}
});
Expand Down
Expand Up @@ -18,14 +18,14 @@ public sealed interface LevelProblem extends ExprProblem {

record BadTypeExpr(@Override @NotNull Expr.AppExpr expr, int expected)
implements LevelProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.english("Expected " + expected + " level(s)");
}
}

record BadLevelExpr(@Override @NotNull Expr expr) implements LevelProblem {
@Override public @NotNull Doc describe() {
return Doc.sep(Doc.english("Expected level expression, got:"), expr.toDoc(DistillerOptions.DEFAULT));
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(Doc.english("Expected level expression, got:"), expr.toDoc(options));
}
}
}
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.desugar.error;

import kala.collection.mutable.Buffer;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.Problem;
import org.aya.api.error.SourcePos;
import org.aya.concrete.desugar.BinOpSet;
Expand All @@ -23,7 +24,7 @@ public record AmbiguousPredError(
return Severity.ERROR;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("Ambiguous operator precedence detected between"),
Doc.styled(Style.code(), Doc.plain(op1)),
Expand All @@ -44,7 +45,7 @@ public record BindSelfError(@Override @NotNull SourcePos sourcePos) implements P
return Severity.ERROR;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.english("Self bind is not allowed");
}
}
Expand All @@ -57,11 +58,10 @@ public record CircleError(
.max(Comparator.comparingInt(SourcePos::endLine));
}

@Override public @NotNull Doc describe() {
return Doc.cat(
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("Precedence circle found between"),
Doc.ONE_WS,
Doc.plain(items.view().map(BinOpSet.Elem::name).sorted().joinToString(", "))
Doc.commaList(items.view().map(BinOpSet.Elem::name).map(Doc::plain).sorted())
);
}

Expand Down
3 changes: 2 additions & 1 deletion base/src/main/java/org/aya/concrete/parse/ParseError.java
Expand Up @@ -2,13 +2,14 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.parse;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.Problem;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
import org.jetbrains.annotations.NotNull;

public record ParseError(@Override @NotNull SourcePos sourcePos, @NotNull String message) implements Problem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.plain("Parser error: " + message);
}

Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.remark;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.Problem;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
Expand All @@ -18,7 +19,7 @@ public record UnsupportedMarkdown(
return Severity.WARN;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.english("Unsupported markdown syntax: " + nodeName + ".");
}
}
Expand Up @@ -4,6 +4,7 @@

import kala.collection.Seq;
import kala.collection.immutable.ImmutableSeq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -19,7 +20,7 @@ public record AmbiguousNameError(
return Severity.ERROR;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.vcat(Doc.cat(
Doc.english("The unqualified name"),
Doc.styled(Style.code(), Doc.plain(name)),
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
import org.aya.pretty.doc.Style;
Expand All @@ -15,7 +16,7 @@ public record AmbiguousNameWarn(
return Severity.WARN;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.vcat(Doc.sep(
Doc.english("The name"),
Doc.styled(Style.code(), Doc.plain(name)),
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
import org.aya.pretty.doc.Style;
Expand All @@ -11,7 +12,7 @@ public record DuplicateExportError(
@NotNull String name,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The name"),
Doc.styled(Style.code(), Doc.plain(name)),
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.Seq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -13,7 +14,7 @@ public record DuplicateModNameError(
@NotNull Seq<String> modName,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The module name"),
Doc.styled(Style.code(), Doc.plain(QualifiedID.join(modName))),
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.api.ref.Var;
import org.aya.distill.BaseDistiller;
Expand All @@ -13,7 +14,7 @@ public record DuplicateNameError(
@NotNull String name, @NotNull Var ref,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The name"),
Doc.plain(name),
Expand Down
Expand Up @@ -10,10 +10,10 @@
import org.jetbrains.annotations.NotNull;

public record GeneralizedNotAvailableError(@Override @NotNull Expr expr) implements ExprProblem, ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The generalized variable"),
Doc.styled(Style.code(), expr.toDoc(DistillerOptions.DEFAULT)),
Doc.styled(Style.code(), expr.toDoc(options)),
Doc.english("is not available here")
);
}
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.Seq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -13,7 +14,7 @@ public record ModNameNotFoundError(
@NotNull Seq<String> modName,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The module name"),
Doc.styled(Style.code(), Doc.plain(QualifiedID.join(modName))),
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.Seq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -13,7 +14,7 @@ public record ModNotFoundError(
@NotNull Seq<String> modName,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The module name"),
Doc.styled(Style.code(), Doc.plain(QualifiedID.join(modName))),
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.Seq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -17,7 +18,7 @@ public record ModShadowingWarn(
return Severity.WARN;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The module name"),
Doc.styled(Style.code(), Doc.plain(QualifiedID.join(modName))),
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.immutable.ImmutableSeq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.core.def.PrimDef;
import org.aya.pretty.doc.Doc;
Expand All @@ -17,7 +18,7 @@ public record PrimDependencyError(
@NotNull ImmutableSeq<PrimDef.ID> lack,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
assert lack.isNotEmpty();
return Doc.sep(
Doc.plain("The prim"), Doc.styled(Style.code(), Doc.plain(name)),
Expand Down
Expand Up @@ -3,6 +3,7 @@
package org.aya.concrete.resolve.error;

import kala.collection.Seq;
import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.concrete.stmt.QualifiedID;
import org.aya.pretty.doc.Doc;
Expand All @@ -15,7 +16,7 @@ public record QualifiedNameNotFoundError(
@NotNull String name,
@Override @NotNull SourcePos sourcePos
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("The qualified name"),
Doc.styled(Style.code(),
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.Problem;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
Expand All @@ -13,7 +14,7 @@ public record RedefinitionError(
@NotNull String name,
@Override @NotNull SourcePos sourcePos
) implements Problem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(Doc.plain("Redefinition of"), Doc.plain(kind.prettyName),
Doc.styled(Style.code(), Doc.plain(name)));
}
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
import org.aya.pretty.doc.Style;
Expand All @@ -15,7 +16,7 @@ public record ShadowingWarn(
return Severity.WARN;
}

@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(Doc.english("The name"),
Doc.styled(Style.code(), Doc.plain(name)),
Doc.english("shadows a previous local definition from outer scope")
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
import org.aya.pretty.doc.Style;
Expand All @@ -11,7 +12,7 @@ public record UnknownOperatorError(
@Override @NotNull SourcePos sourcePos,
@NotNull String name
) implements ResolveProblem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.english("Unknown operator"),
Doc.styled(Style.code(), Doc.plain(name)),
Expand Down
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file.
package org.aya.concrete.resolve.error;

import org.aya.api.distill.DistillerOptions;
import org.aya.api.error.Problem;
import org.aya.api.error.SourcePos;
import org.aya.pretty.doc.Doc;
Expand All @@ -12,7 +13,7 @@ public record UnknownPrimError(
@Override @NotNull SourcePos sourcePos,
@NotNull String name
) implements Problem {
@Override public @NotNull Doc describe() {
@Override public @NotNull Doc describe(DistillerOptions options) {
return Doc.sep(
Doc.plain("Unknown primitive"),
Doc.styled(Style.code(), Doc.plain(name)));
Expand Down

0 comments on commit 1d1980f

Please sign in to comment.