Skip to content

Commit

Permalink
Merge pull request #297 from travisbrown/topic/21.0.0
Browse files Browse the repository at this point in the history
Prepare for 21.0.0
  • Loading branch information
travisbrown authored Jul 28, 2021
2 parents ef5926f + c750678 commit 6f06c4f
Show file tree
Hide file tree
Showing 22 changed files with 648 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dhall-lang
Submodule dhall-lang updated 83 files
+189 −1 standard/Parser.hs
+39 −0 standard/alpha-normalization.md
+44 −0 standard/beta-normalization.md
+104 −0 standard/binary.md
+64 −2 standard/dhall.abnf
+39 −0 standard/shift.md
+1 −0 standard/standard.cabal
+39 −0 standard/substitution.md
+14 −0 standard/syntax.md
+39 −0 standard/type-inference.md
+1 −0 tests/binary-decode/success/unit/DateA.dhallb
+1 −0 tests/binary-decode/success/unit/DateA.diag
+1 −0 tests/binary-decode/success/unit/DateB.dhall
+ tests/binary-decode/success/unit/TimeA.dhallb
+1 −0 tests/binary-decode/success/unit/TimeA.diag
+1 −0 tests/binary-decode/success/unit/TimeB.dhall
+ tests/binary-decode/success/unit/TimeZoneA.dhallb
+1 −0 tests/binary-decode/success/unit/TimeZoneA.diag
+1 −0 tests/binary-decode/success/unit/TimeZoneB.dhall
+2 −0 tests/normalization/success/unit/TimeAsRecordA.dhall
+1 −0 tests/normalization/success/unit/TimeAsRecordB.dhall
+2 −0 tests/parser/failure/time/DateTimeZone.dhall
+2 −0 tests/parser/failure/time/InvalidDayOfMonth.dhall
+2 −0 tests/parser/failure/time/InvalidHour.dhall
+3 −0 tests/parser/failure/time/InvalidLeapSecond.dhall
+2 −0 tests/parser/failure/time/InvalidMinute.dhall
+2 −0 tests/parser/failure/time/InvalidMonth.dhall
+2 −0 tests/parser/failure/time/InvalidSecond.dhall
+2 −0 tests/parser/failure/time/NegativeYear.dhall
+2 −0 tests/parser/failure/time/YearTooLarge.dhall
+1 −0 tests/parser/success/time/DateTimeA.dhall
+ tests/parser/success/time/DateTimeB.dhallb
+1 −0 tests/parser/success/time/DateTimeB.diag
+1 −0 tests/parser/success/time/DateTimeTimeZoneA.dhall
+ tests/parser/success/time/DateTimeTimeZoneB.dhallb
+1 −0 tests/parser/success/time/DateTimeTimeZoneB.diag
+2 −0 tests/parser/success/time/LowercaseTA.dhall
+ tests/parser/success/time/LowercaseTB.dhallb
+1 −0 tests/parser/success/time/LowercaseTB.diag
+1 −0 tests/parser/success/time/TimeTimeZoneA.dhall
+ tests/parser/success/time/TimeTimeZoneB.dhallb
+1 −0 tests/parser/success/time/TimeTimeZoneB.diag
+5 −0 tests/parser/success/time/TimeTimeZoneZA.dhall
+ tests/parser/success/time/TimeTimeZoneZB.dhallb
+1 −0 tests/parser/success/time/TimeTimeZoneZB.diag
+1 −0 tests/parser/success/unit/DateA.dhall
+1 −0 tests/parser/success/unit/DateB.dhallb
+1 −0 tests/parser/success/unit/DateB.diag
+1 −0 tests/parser/success/unit/DateLiteralA.dhall
+1 −0 tests/parser/success/unit/DateLiteralB.dhallb
+1 −0 tests/parser/success/unit/DateLiteralB.diag
+1 −0 tests/parser/success/unit/TimeA.dhall
+1 −0 tests/parser/success/unit/TimeB.dhallb
+1 −0 tests/parser/success/unit/TimeB.diag
+1 −0 tests/parser/success/unit/TimeLiteralA.dhall
+ tests/parser/success/unit/TimeLiteralB.dhallb
+1 −0 tests/parser/success/unit/TimeLiteralB.diag
+1 −0 tests/parser/success/unit/TimeZoneA.dhall
+1 −0 tests/parser/success/unit/TimeZoneB.dhallb
+1 −0 tests/parser/success/unit/TimeZoneB.diag
+1 −0 tests/parser/success/unit/TimeZoneLiteralA.dhall
+ tests/parser/success/unit/TimeZoneLiteralB.dhallb
+1 −0 tests/parser/success/unit/TimeZoneLiteralB.diag
+3 −0 tests/type-inference/failure/DateApplyTime.dhall
+4 −0 tests/type-inference/failure/unit/Z.dhall
+1 −0 tests/type-inference/success/unit/time/DateA.dhall
+1 −0 tests/type-inference/success/unit/time/DateB.dhall
+1 −0 tests/type-inference/success/unit/time/DateLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/DateLiteralB.dhall
+1 −0 tests/type-inference/success/unit/time/DateTimeLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/DateTimeLiteralB.dhall
+1 −0 tests/type-inference/success/unit/time/DateTimeTimeZoneLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/DateTimeTimeZoneLiteralB.dhall
+1 −0 tests/type-inference/success/unit/time/TimeA.dhall
+1 −0 tests/type-inference/success/unit/time/TimeB.dhall
+1 −0 tests/type-inference/success/unit/time/TimeLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/TimeLiteralB.dhall
+1 −0 tests/type-inference/success/unit/time/TimeTimeZoneLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/TimeTimeZoneLiteralB.dhall
+1 −0 tests/type-inference/success/unit/time/TimeZoneA.dhall
+1 −0 tests/type-inference/success/unit/time/TimeZoneB.dhall
+1 −0 tests/type-inference/success/unit/time/TimeZoneLiteralA.dhall
+1 −0 tests/type-inference/success/unit/time/TimeZoneLiteralB.dhall
4 changes: 4 additions & 0 deletions modules/cats/src/main/scala/org/dhallj/cats/LiftVisitor.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.dhallj.cats

import cats.Applicative
import java.math.BigDecimal
import java.math.BigInteger
import java.net.URI
import java.nio.file.Path
Expand All @@ -23,6 +24,9 @@ class LiftVisitor[F[_] <: AnyRef](
def onNatural(self: Expr, value: BigInteger): F[Expr] = F.pure(self)
def onInteger(self: Expr, value: BigInteger): F[Expr] = F.pure(self)
def onDouble(self: Expr, value: Double): F[Expr] = F.pure(self)
def onDate(self: Expr, year: Int, month: Int, day: Int): F[Expr] = F.pure(self)
def onTime(self: Expr, hour: Int, minute: Int, second: Int, fractional: BigDecimal): F[Expr] = F.pure(self)
def onTimeZone(self: Expr, seconds: Int): F[Expr] = F.pure(self)
def onBuiltIn(self: Expr, name: String): F[Expr] = F.pure(self)
def onIdentifier(self: Expr, value: String, index: Long): F[Expr] = F.pure(self)

Expand Down
15 changes: 13 additions & 2 deletions modules/core/src/main/java/org/dhallj/cbor/Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
Expand Down Expand Up @@ -102,8 +103,11 @@ public final void writeBoolean(boolean value) {
}

public final void writeLong(long value) {
this.writeTypeAndLength(
(value >= 0) ? MajorType.UNSIGNED_INTEGER.value : MajorType.NEGATIVE_INTEGER.value, value);
if (value >= 0) {
this.writeTypeAndLength(MajorType.UNSIGNED_INTEGER.value, value);
} else {
this.writeTypeAndLength(MajorType.NEGATIVE_INTEGER.value, -(value + 1));
}
}

public final void writeBigInteger(BigInteger value) {
Expand All @@ -114,6 +118,13 @@ public final void writeBigInteger(BigInteger value) {
}
}

public final void writeBigDecimal(BigDecimal value) {
this.writeTypeAndLength(MajorType.SEMANTIC_TAG.value, 4);
this.writeTypeAndLength(MajorType.ARRAY.value, 2);
this.writeLong(-((long) value.scale()));
this.writeBigInteger(value.unscaledValue());
}

public final void writeString(String value) {
byte[] bytes = value.getBytes(UTF_8);
this.writeTypeAndLength(MajorType.TEXT_STRING.value, bytes.length);
Expand Down
63 changes: 63 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/Constructors.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhallj.core;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Path;
Expand Down Expand Up @@ -71,6 +72,68 @@ final <A> void advance(VisitState<A> state) {
}
}

static final class DateLiteral extends Expr {
final int year;
final int month;
final int day;

DateLiteral(int year, int month, int day) {
super(Tags.DATE);
this.year = year;
this.month = month;
this.day = day;
}

public final <A> A accept(ExternalVisitor<A> visitor) {
return visitor.onDate(this.year, this.month, this.day);
}

final <A> void advance(VisitState<A> state) {
state.valueStack.push(state.visitor.onDate(this, this.year, this.month, this.day));
}
}

static final class TimeLiteral extends Expr {
final int hour;
final int minute;
final int second;
final BigDecimal fractional;

TimeLiteral(int hour, int minute, int second, BigDecimal fractional) {
super(Tags.TIME);
this.hour = hour;
this.minute = minute;
this.second = second;
this.fractional = fractional;
}

public final <A> A accept(ExternalVisitor<A> visitor) {
return visitor.onTime(this.hour, this.minute, this.second, this.fractional);
}

final <A> void advance(VisitState<A> state) {
state.valueStack.push(
state.visitor.onTime(this, this.hour, this.minute, this.second, this.fractional));
}
}

static final class TimeZoneLiteral extends Expr {
final int minutes;

TimeZoneLiteral(int minutes) {
super(Tags.TIME_ZONE);
this.minutes = minutes;
}

public final <A> A accept(ExternalVisitor<A> visitor) {
return visitor.onTimeZone(this.minutes);
}

final <A> void advance(VisitState<A> state) {
state.valueStack.push(state.visitor.onTimeZone(this, this.minutes));
}
}

static final class TextLiteral extends Expr {
final String[] parts;
final Expr[] interpolated;
Expand Down
20 changes: 18 additions & 2 deletions modules/core/src/main/java/org/dhallj/core/DhallException.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,34 @@ public ParsingFailure(String message) {
}

public static final class ResolutionFailure extends DhallException {
private boolean isAbsentImport;

@Override
public Throwable fillInStackTrace() {
// This is a failure type; stack traces aren't useful.
return this;
}

public ResolutionFailure(String message, Throwable cause) {
public ResolutionFailure(String message, Throwable cause, boolean isAbsentImport) {
super(message, cause);
this.isAbsentImport = isAbsentImport;
}

public ResolutionFailure(String message) {
public ResolutionFailure(String message, boolean isAbsentImport) {
super(message);
this.isAbsentImport = isAbsentImport;
}

public ResolutionFailure(String message, Throwable cause) {
this(message, cause, false);
}

public ResolutionFailure(String message) {
this(message, false);
}

public boolean isAbsentImport() {
return this.isAbsentImport;
}
}
}
22 changes: 22 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 @@ -2,6 +2,7 @@

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Path;
Expand Down Expand Up @@ -583,6 +584,11 @@ public static final class Constants {
public static final Expr TEXT = new Constructors.BuiltIn("Text");
public static final Expr NONE = new Constructors.BuiltIn("None");
public static final Expr SOME = new Constructors.BuiltIn("Some");

public static final Expr DATE = new Constructors.BuiltIn("Date");
public static final Expr TIME = new Constructors.BuiltIn("Time");
public static final Expr TIME_ZONE = new Constructors.BuiltIn("TimeZone");

public static final Expr NATURAL_FOLD = new Constructors.BuiltIn("Natural/fold");
public static final Expr LIST_FOLD = new Constructors.BuiltIn("List/fold");
public static final Expr ZERO = makeNaturalLiteral(BigInteger.ZERO);
Expand All @@ -605,6 +611,7 @@ public static final class Constants {

static {
builtIns.put("Bool", BOOL);
builtIns.put("Date", DATE);
builtIns.put("Double", DOUBLE);
builtIns.put("Double/show", new Constructors.BuiltIn("Double/show"));
builtIns.put("False", FALSE);
Expand Down Expand Up @@ -638,6 +645,8 @@ public static final class Constants {
builtIns.put("Text", TEXT);
builtIns.put("Text/replace", new Constructors.BuiltIn("Text/replace"));
builtIns.put("Text/show", new Constructors.BuiltIn("Text/show"));
builtIns.put("Time", TIME);
builtIns.put("TimeZone", TIME_ZONE);
builtIns.put("True", TRUE);
builtIns.put("Type", TYPE);

Expand Down Expand Up @@ -708,6 +717,19 @@ public static final Expr makeIntegerLiteral(BigInteger value) {
return new Constructors.IntegerLiteral(value);
}

public static final Expr makeDateLiteral(int year, int month, int day) {
return new Constructors.DateLiteral(year, month, day);
}

public static final Expr makeTimeLiteral(
int hour, int minute, int second, BigDecimal fractional) {
return new Constructors.TimeLiteral(hour, minute, second, fractional);
}

public static final Expr makeTimeZoneLiteral(int seconds) {
return new Constructors.TimeZoneLiteral(seconds);
}

public static final Expr makeTextLiteral(String[] parts, Expr[] interpolated) {
return new Constructors.TextLiteral(parts, interpolated);
}
Expand Down
22 changes: 22 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/ExternalVisitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhallj.core;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Path;
Expand All @@ -19,6 +20,12 @@ public interface ExternalVisitor<A> {

A onDouble(double value);

A onDate(int year, int month, int day);

A onTime(int hour, int minute, int second, BigDecimal fractional);

A onTimeZone(int minutes);

A onBuiltIn(String name);

A onIdentifier(String name, long index);
Expand Down Expand Up @@ -114,6 +121,21 @@ public A onDouble(double value) {
return this.getReturnValue();
}

@Override
public A onDate(int year, int month, int day) {
return this.getReturnValue();
}

@Override
public A onTime(int hour, int minute, int second, BigDecimal fractional) {
return this.getReturnValue();
}

@Override
public A onTimeZone(int minutes) {
return this.getReturnValue();
}

@Override
public A onBuiltIn(String name) {
return this.getReturnValue();
Expand Down
4 changes: 4 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/Tags.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhallj.core;

// Note that these are internal identifiers only.
final class Tags {
static final int NOTE = 0;

Expand All @@ -9,6 +10,9 @@ final class Tags {
static final int DOUBLE = 3;
static final int BUILT_IN = 4;
static final int IDENTIFIER = 5;
static final int DATE = 31;
static final int TIME = 32;
static final int TIME_ZONE = 33;

// Binding constructors.
static final int LAMBDA = 6;
Expand Down
40 changes: 40 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/ToStringVisitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhallj.core;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.charset.Charset;
Expand Down Expand Up @@ -77,6 +78,45 @@ public ToStringState onDouble(Expr self, double value) {
return new ToStringState(Double.toString(value));
}

private static String pad2(int input) {
String asString = Integer.toString(input);
if (asString.length() == 1) {
return "0" + asString;
} else {
return asString;
}
}

private static String pad4(int input) {
String asString = Integer.toString(input);
for (int i = 0; i < asString.length() - 4; i += 1) {
asString = "0" + asString;
}
return asString;
}

public ToStringState onDate(Expr self, int year, int month, int day) {
return new ToStringState(pad4(year) + "-" + pad2(month) + "-" + pad2(day));
}

public ToStringState onTime(Expr self, int hour, int minute, int second, BigDecimal fractional) {
String result = pad2(hour) + ":" + pad2(minute) + ":" + pad2(second);

if (!fractional.equals(BigDecimal.ZERO)) {
result = result + fractional.toString().substring(1);
}

return new ToStringState(result);
}

public ToStringState onTimeZone(Expr self, int minutes) {
if (Long.signum(minutes) < 0) {
return new ToStringState("-" + pad2(-minutes / 60) + pad2(-minutes % 60));
} else {
return new ToStringState("+" + pad2(minutes / 60) + pad2(minutes % 60));
}
}

public ToStringState onBuiltIn(Expr self, String name) {
return new ToStringState(name);
}
Expand Down
34 changes: 34 additions & 0 deletions modules/core/src/main/java/org/dhallj/core/Visitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.dhallj.core;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.nio.file.Path;
Expand All @@ -23,6 +24,12 @@ public interface Visitor<A> {

A onDouble(Expr self, double value);

A onDate(Expr self, int year, int month, int day);

A onTime(Expr self, int hour, int minute, int second, BigDecimal fractional);

A onTimeZone(Expr self, int minutes);

A onBuiltIn(Expr self, String value);

A onIdentifier(Expr self, String value, long index);
Expand Down Expand Up @@ -340,6 +347,21 @@ public A onDouble(Expr self, double value) {
return this.getReturnValue();
}

@Override
public A onDate(Expr self, int year, int month, int day) {
return this.getReturnValue();
}

@Override
public A onTime(Expr self, int hour, int minute, int second, BigDecimal fractional) {
return this.getReturnValue();
}

@Override
public A onTimeZone(Expr self, int minutes) {
return this.getReturnValue();
}

@Override
public A onBuiltIn(Expr self, String value) {
return this.getReturnValue();
Expand Down Expand Up @@ -649,6 +671,18 @@ public Expr onDouble(Expr self, double value) {
return self;
}

public Expr onDate(Expr self, int year, int month, int day) {
return self;
}

public Expr onTime(Expr self, int hour, int minute, int second, BigDecimal fractional) {
return self;
}

public Expr onTimeZone(Expr self, int minutes) {
return self;
}

public Expr onBuiltIn(Expr self, String name) {
return self;
}
Expand Down
Loading

0 comments on commit 6f06c4f

Please sign in to comment.