-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
111 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.syntax.core; | ||
|
||
import org.aya.tyck.TyckTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class PrettierTest { | ||
@Test public void clauses() { | ||
var result = TyckTest.tyck(""" | ||
open inductive Nat | O | S Nat | ||
def plus (a : Nat) (b : Nat) : Nat | ||
| 0 , c => b | ||
| S c, 0 => S (plus c b) | ||
| S c, S d => S (plus c b) | ||
"""); | ||
|
||
var fnPlus = result.defs() | ||
.findFirst(x -> x.ref().name().equals("plus")) | ||
.get(); | ||
|
||
assertEquals(""" | ||
def plus (a b : Nat) : Nat | ||
| 0, c => c | ||
| S c, 0 => S (plus c 0) | ||
| S c, S d => S (plus c (S d))""", // no new line here!! | ||
fnPlus.debuggerOnlyToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2020-2024 Tesla (Yinsen) Zhang. | ||
// Use of this source code is governed by the MIT license that can be found in the LICENSE.md file. | ||
package org.aya.syntax.core; | ||
|
||
import org.aya.generic.term.ParamLike; | ||
import org.aya.syntax.core.term.FreeTerm; | ||
import org.aya.syntax.core.term.Param; | ||
import org.aya.syntax.core.term.Term; | ||
import org.aya.syntax.ref.LocalVar; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A enriched {@link org.aya.syntax.core.term.Param}, which is usually used for prettier. | ||
*/ | ||
public record RichParam( | ||
@Override @NotNull LocalVar ref, | ||
@Override @NotNull Term type, | ||
@Override boolean explicit | ||
) implements ParamLike<Term> { | ||
public static @NotNull RichParam ofExplicit(@NotNull LocalVar ref, @NotNull Term type) { | ||
return new RichParam(ref, type, true); | ||
} | ||
|
||
public @NotNull FreeTerm toTerm() { return new FreeTerm(ref); } | ||
@Contract("-> new") public @NotNull Param degenerate() { | ||
return new Param(ref.name(), type, explicit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters