Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classpath import type #32

Merged
merged 8 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ lazy val tests = project
libraryDependencies ++= http4sDependencies :+ http4sBlazeClient,
skip in publish := true,
mimaPreviousArtifacts := Set.empty,
unmanagedResourceDirectories.in(Test) += (ThisBuild / baseDirectory).value / "dhall-lang",
fork in Test := true,
baseDirectory in Test := (ThisBuild / baseDirectory).value,
testOptions.in(Test) += Tests.Argument("--exclude-tags=Slow"),
unmanagedResourceDirectories.in(Test) += (ThisBuild / baseDirectory).value / "dhall-lang",
inConfig(Slow)(Defaults.testTasks),
testOptions.in(Slow) -= Tests.Argument("--exclude-tags=Slow"),
testOptions.in(Slow) += Tests.Argument("--include-tags=Slow")
Expand Down
3 changes: 3 additions & 0 deletions modules/cats/src/main/scala/org/dhallj/cats/LiftVisitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ class LiftVisitor[F[_] <: AnyRef](
def onLocalImport(path: Path, mode: Expr.ImportMode, hash: Array[Byte]): F[Expr] =
F.pure(Expr.makeLocalImport(path, mode, hash))

def onClasspathImport(path: Path, mode: Expr.ImportMode, hash: Array[Byte]): F[Expr] =
F.pure(Expr.makeClasspathImport(path, mode, hash))

def onRemoteImport(url: URI, headers: F[Expr], mode: Expr.ImportMode, hash: Array[Byte]): F[Expr] =
if (headers.eq(null)) {
F.pure(Expr.makeRemoteImport(url, null, mode, hash))
Expand Down
12 changes: 12 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/Expr.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ public static final Expr makeLocalImport(Path path, ImportMode mode, byte[] hash
return new Constructors.LocalImport(path, mode, hash);
}

public static final Expr makeClasspathImport(Path path, ImportMode mode, byte[] hash) {
return new Constructors.ClasspathImport(path, mode, hash);
}

public static final Expr makeRemoteImport(URI url, Expr using, ImportMode mode, byte[] hash) {
return new Constructors.RemoteImport(url, using, mode, hash);
}
Expand Down Expand Up @@ -1512,6 +1516,14 @@ public final <A> A accept(Visitor<A> visitor) {
break;
}
break;
case Tags.CLASSPATH_IMPORT:
Constructors.ClasspathImport tmpClasspathImport =
(Constructors.ClasspathImport) current.expr;

valueStack.push(
visitor.onClasspathImport(
tmpClasspathImport.path, tmpClasspathImport.mode, tmpClasspathImport.hash));
break;
}
current = stack.poll();
}
Expand Down
36 changes: 36 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/ExternalVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public interface ExternalVisitor<A> {

A onLocalImport(Path path, Expr.ImportMode mode, byte[] hash);

A onClasspathImport(Path path, Expr.ImportMode mode, byte[] hash);

A onRemoteImport(URI url, Expr using, Expr.ImportMode mode, byte[] hash);

/**
Expand All @@ -90,118 +92,152 @@ public Constant(A value) {
this.returnValue = value;
}

@Override
public A onNote(Expr base, Source source) {
return base.accept(this);
}

@Override
public A onNatural(BigInteger value) {
return this.getReturnValue();
}

@Override
public A onInteger(BigInteger value) {
return this.getReturnValue();
}

@Override
public A onDouble(double value) {
return this.getReturnValue();
}

@Override
public A onBuiltIn(String name) {
return this.getReturnValue();
}

@Override
public A onIdentifier(String name, long index) {
return this.getReturnValue();
}

@Override
public A onLambda(String name, Expr input, Expr result) {
return this.getReturnValue();
}

@Override
public A onPi(String name, Expr input, Expr result) {
return this.getReturnValue();
}

@Override
public A onLet(String name, Expr type, Expr value, Expr body) {
return this.getReturnValue();
}

@Override
public A onText(String[] parts, Iterable<Expr> interpolated) {
return this.getReturnValue();
}

@Override
public A onNonEmptyList(Iterable<Expr> values, int size) {
return this.getReturnValue();
}

@Override
public A onEmptyList(Expr tpe) {
return this.getReturnValue();
}

@Override
public A onRecord(Iterable<Entry<String, Expr>> fields, int size) {
return this.getReturnValue();
}

@Override
public A onRecordType(Iterable<Entry<String, Expr>> fields, int size) {
return this.getReturnValue();
}

@Override
public A onUnionType(Iterable<Entry<String, Expr>> fields, int size) {
return this.getReturnValue();
}

@Override
public A onFieldAccess(Expr base, String fieldName) {
return this.getReturnValue();
}

@Override
public A onProjection(Expr base, String[] fieldNames) {
return this.getReturnValue();
}

@Override
public A onProjectionByType(Expr base, Expr tpe) {
return this.getReturnValue();
}

@Override
public A onApplication(Expr base, Expr arg) {
return this.getReturnValue();
}

@Override
public A onOperatorApplication(Operator operator, Expr lhs, Expr rhs) {
return this.getReturnValue();
}

@Override
public A onIf(Expr predicate, Expr thenValue, Expr elseValue) {
return this.getReturnValue();
}

@Override
public A onAnnotated(Expr base, Expr tpe) {
return this.getReturnValue();
}

@Override
public A onAssert(Expr base) {
return this.getReturnValue();
}

@Override
public A onMerge(Expr handlers, Expr union, Expr tpe) {
return this.getReturnValue();
}

@Override
public A onToMap(Expr base, Expr type) {
return this.getReturnValue();
}

@Override
public A onMissingImport(Expr.ImportMode mode, byte[] hash) {
return this.getReturnValue();
}

@Override
public A onEnvImport(String value, Expr.ImportMode mode, byte[] hash) {
return this.getReturnValue();
}

@Override
public A onLocalImport(Path path, Expr.ImportMode mode, byte[] hash) {
return this.getReturnValue();
}

@Override
public A onClasspathImport(Path path, Expr.ImportMode mode, byte[] hash) {
return this.getReturnValue();
}

@Override
public A onRemoteImport(URI url, Expr using, Expr.ImportMode mode, byte[] hash) {
return this.getReturnValue();
}
Expand Down
5 changes: 5 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/IsResolved.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public Boolean onLocalImport(Path path, Expr.ImportMode mode, byte[] hash) {
return false;
}

@Override
public Boolean onClasspathImport(Path path, Expr.ImportMode mode, byte[] hash) {
return false;
}

@Override
public Boolean onRemoteImport(URI url, Boolean using, Expr.ImportMode mode, byte[] hash) {
return false;
Expand Down
1 change: 1 addition & 0 deletions modules/core/src/main/java/org/dhallj/core/Tags.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ final class Tags {
static final int ENV_IMPORT = 26;
static final int LOCAL_IMPORT = 27;
static final int REMOTE_IMPORT = 28;
static final int CLASSPATH_IMPORT = 29;
}
19 changes: 19 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/ToStringVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,25 @@ public ToStringState onLocalImport(Path path, Expr.ImportMode mode, byte[] hash)
return new ToStringState(builder.toString(), ToStringState.BASE);
}

@Override
public ToStringState onClasspathImport(Path path, Expr.ImportMode mode, byte[] hash) {
StringBuilder builder = new StringBuilder("classpath:");

builder.append(path.toString());

if (hash != null) {
builder.append(" ");
builder.append(Expr.Util.encodeHashBytes(hash));
}

if (mode != Expr.ImportMode.CODE) {
builder.append(" as ");
builder.append(mode);
}

return new ToStringState(builder.toString(), ToStringState.BASE);
}

public ToStringState onRemoteImport(
URI url, ToStringState using, Expr.ImportMode mode, byte[] hash) {
StringBuilder builder = new StringBuilder(url.toString());
Expand Down
Loading