1
1
mirror of https://github.com/anoma/juvix.git synced 2024-10-26 17:52:17 +03:00

Fix: format juvix files in test/positive (#1978)

This PR fixes a formatting issue that drops blank lines between axiom
declarations.

It goes after:

- #1980
- Closes https://github.com/anoma/juvix/issues/1986
This commit is contained in:
Jonathan Cubides 2023-04-12 10:07:01 +02:00 committed by GitHub
parent b14a81a81d
commit 4d0267ebb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
54 changed files with 241 additions and 293 deletions

View File

@ -23,7 +23,7 @@ concurrency:
cancel-in-progress: true
env:
SKIP: ormolu,format-juvix-examples,typecheck-juvix-examples
SKIP: ormolu,format-juvix-files,typecheck-juvix-examples
jobs:
pre-commit:
@ -119,7 +119,7 @@ jobs:
continue-on-error: true
run: |
cd main
make check-format-juvix-examples
make check-format-juvix-files
make typecheck-juvix-examples
- name: Add ~/.local/bin to PATH
@ -317,7 +317,7 @@ jobs:
if: ${{ success() }}
run: |
cd main
make -s check-format-juvix-examples
make -s check-format-juvix-files
make -s typecheck-juvix-examples
- name: Install Smoke

View File

@ -42,9 +42,9 @@ repos:
- repo: local
hooks:
- id: format-juvix-examples
- id: format-juvix-files
name: format Juvix examples
entry: make -s format-juvix-examples
entry: make -s format-juvix-files
language: system
verbose: false
pass_filenames: false

View File

@ -10,7 +10,7 @@ EXAMPLES= Collatz/Collatz.juvix \
HelloWorld/HelloWorld.juvix \
PascalsTriangle/PascalsTriangle.juvix \
TicTacToe/CLI/TicTacToe.juvix \
Tutorial/Tutorial.juvix \
Tutorial/Tutorial.juvix
DEMO_EXAMPLE=examples/demo/Demo.juvix
@ -130,20 +130,22 @@ format:
clang-format:
@cd runtime && ${MAKE} format
JUVIXEXAMPLEFILES=$(shell find ./examples -name "*.juvix" -print)
JUVIXFILESTOFORMAT=$(shell find ./examples ./tests/positive -type d -name ".juvix-build" -prune -o -type f -name "*.juvix" -print)
JUVIXFORMATFLAGS?=--in-place
JUVIXTYPECHECKFLAGS?=--only-errors
.PHONY: format-juvix-examples
format-juvix-examples:
@for file in $(JUVIXEXAMPLEFILES); do \
${JUVIXBIN} format $(JUVIXFORMATFLAGS) "$$file"; \
.PHONY: format-juvix-files
format-juvix-files:
@for file in $(JUVIXFILESTOFORMAT); do \
juvix format $(JUVIXFORMATFLAGS) "$$file"; \
done
.PHONY: check-format-juvix-examples
check-format-juvix-examples:
.PHONY: check-format-juvix-files
check-format-juvix-files:
@export JUVIXFORMATFLAGS=--check
@${MAKE} format-juvix-examples
@make format-juvix-files
JUVIXEXAMPLEFILES=$(shell find ./examples -name "*.juvix" -print)
.PHONY: typecheck-juvix-examples
typecheck-juvix-examples:

View File

@ -82,7 +82,7 @@ groupStatements = reverse . map reverse . uncurry cons . foldl' aux ([], [])
(StatementOpenModule {}, _) -> False
(StatementInductive {}, _) -> False
(StatementModule {}, _) -> False
(StatementAxiom {}, StatementAxiom {}) -> True
(StatementAxiom {}, StatementAxiom {}) -> False
(StatementAxiom {}, _) -> False
(StatementTypeSignature sig, StatementFunctionClause fun) ->
case sing :: SStage s of

View File

@ -177,11 +177,10 @@ instance PrettyPrint (AxiomDef 'Scoped) where
axiomName' <- P.annDef _axiomName <$> P.ppSymbol _axiomName
let builtin' :: Maybe (Sem r ()) = (<> line) . (\x -> P.ppCode x >>= morpheme (getLoc x)) <$> _axiomBuiltin
_axiomDoc' :: Maybe (Sem r ()) = ppCode <$> _axiomDoc
axiom' = (<> line) . ppCode $ _axiomKw
_axiomDoc'
?<> builtin'
?<> axiom'
<> morpheme (getLoc _axiomName) axiomName'
?<> ppCode _axiomKw
<+> morpheme (getLoc _axiomName) axiomName'
<+> noLoc P.kwColon
<+> ppCode _axiomType

View File

@ -1,14 +1,12 @@
module M;
type Bool :=
true : Bool
| true : Bool
| false : Bool;
type Pair (A : Type) (B : Type) :=
mkPair : A → B → Pair A B;
| mkPair : A → B → Pair A B;
f : _ → _;
f (mkPair false true) := true;
f _ := false;
end;

View File

@ -1,14 +1,14 @@
module M;
type Bool :=
true : Bool
| true : Bool
| false : Bool;
type T :=
t : T;
| t : T;
type Nat :=
zero : Nat
| zero : Nat
| suc : Nat → Nat;
f : _;
@ -16,9 +16,7 @@ f false false := true;
f true _ := false;
type Pair (A : Type) (B : Type) :=
mkPair : A → B → Pair A B;
| mkPair : A → B → Pair A B;
g : _;
g (mkPair (mkPair zero false) true) := mkPair false zero;
end;

View File

@ -1,36 +1,30 @@
module Ape;
builtin string
axiom
String : Type;
axiom String : Type;
infixl 7 *;
axiom
* : String → String → String;
axiom * : String → String → String;
infixr 3 -;
axiom
- : String → String → String;
axiom - : String → String → String;
infixl 1 >>;
axiom
>> : String → String → String;
axiom >> : String → String → String;
infixl 6 +;
axiom
+ : String → String → String;
axiom + : String → String → String;
infixr 6 ++;
axiom
++ : String → String → String;
axiom
f : String → String;
axiom ++ : String → String → String;
axiom f : String → String;
x : String;
x := "" + ("" ++ "");
axiom
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww : String → String;
axiom wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww : String
→ String;
nesting : String;
nesting :=

View File

@ -1,4 +1,3 @@
module Axiom;
axiom
Action : Type;
axiom Action : Type;

View File

@ -1,5 +1,3 @@
module A;
import Nat;
end;

View File

@ -2,5 +2,3 @@ module Input;
import A;
import Nat;
end;

View File

@ -2,7 +2,5 @@ module Nat;
builtin nat
type Nat :=
zero : Nat
| zero : Nat
| suc : Nat → Nat;
end;

View File

@ -1,5 +1,3 @@
module A;
open import Nat;
end;

View File

@ -2,5 +2,3 @@ module Input;
open import A;
open import Nat;
end;

View File

@ -2,7 +2,5 @@ module Nat;
builtin nat
type Nat :=
zero : Nat
| zero : Nat
| suc : Nat → Nat;
end;

View File

@ -1,5 +1,3 @@
module Base;
axiom Base : Type;
end;
axiom Base : Type;

View File

@ -5,5 +5,3 @@ open import Base;
axiom Extra : Type;
axiom _A : Base;
end;

View File

@ -13,8 +13,7 @@ go n s :=
module M;
infixr 4 ,;
axiom
, : String → String → String;
axiom , : String → String → String;
end;
-- qualified commas
@ -48,24 +47,19 @@ t3 :=
, "1234";
infixl 7 +l7;
axiom
+l7 : String → String → String;
axiom +l7 : String → String → String;
infixr 3 +r3;
axiom
+r3 : String → String → String;
axiom +r3 : String → String → String;
infixl 1 +l1;
axiom
+l1 : String → String → String;
axiom +l1 : String → String → String;
infixl 6 +l6;
axiom
+l6 : String → String → String;
axiom +l6 : String → String → String;
infixr 6 +r6;
axiom
+r6 : String → String → String;
axiom +r6 : String → String → String;
-- nesting of chains
t : String;

View File

@ -8,8 +8,7 @@ module M;
end;
infixr 2 +;
axiom
+ : Type → Type → Type;
axiom + : Type → Type → Type;
end;
import M;

View File

@ -11,12 +11,14 @@ infixr 9 ∘;
→ C;
∘ {_} {B} {_} f g x := f (g x);
builtin nat type Nat :=
builtin nat
type Nat :=
| zero : Nat
| suc : Nat → Nat;
infixl 6 +;
builtin nat-plus + : Nat → Nat → Nat;
builtin nat-plus
+ : Nat → Nat → Nat;
+ zero b := b;
+ (suc a) b := suc (a + b);

View File

@ -1,6 +1,7 @@
module LiteralString;
builtin string axiom String : Type;
builtin string
axiom String : Type;
type A :=
| a : A;

View File

@ -1,14 +1,13 @@
module E5;
type T0 (A : Type) :=
c0 : (A -> T0 A) -> T0 A;
| c0 : (A -> T0 A) -> T0 A;
axiom B : Type;
type T1 (A : Type) :=
c1 : (B -> T0 A) -> T1 A;
| c1 : (B -> T0 A) -> T1 A;
positive
type T2 :=
c2 : (B -> (B -> T1 T2)) -> T2;
end;
| c2 : (B -> B -> T1 T2) -> T2;

View File

@ -1,6 +1,7 @@
module Judoc;
axiom A : Type;
axiom b : Type;
type T :=

View File

@ -1,11 +1,10 @@
module Literals;
axiom
Int : Type;
axiom
String : Type;
axiom
+ : Int → Int → Int;
axiom Int : Type;
axiom String : Type;
axiom + : Int → Int → Int;
a : Int;
a := 12313;

View File

@ -1,8 +1,7 @@
module Operators;
infixl 5 +;
axiom
+ : Type → Type → Type;
axiom + : Type → Type → Type;
plus : Type → Type → Type;
plus := (+);

View File

@ -1,8 +1,7 @@
module M;
module O;
axiom
A : Type;
axiom A : Type;
end;
open O;

View File

@ -2,8 +2,7 @@ module M;
module N;
module O;
axiom
A : Type;
axiom A : Type;
end;
end;
@ -13,5 +12,4 @@ module O;
end;
axiom
B : O.A;
axiom B : O.A;

View File

@ -3,9 +3,7 @@ module N;
import M;
module M;
axiom
A : Type;
axiom A : Type;
end;
axiom
B : M.A;
axiom B : M.A;

View File

@ -1,20 +1,17 @@
module Data.Bool;
type Bool :=
true : Bool |
false : Bool;
not : Bool → Bool;
not true := false;
not false := true;
type Bool :=
| true : Bool
| false : Bool;
-- infixr 2 ||;
-- || : Bool → Bool → Bool;
-- || false a := a;
-- || true _ := true;
-- infixr 2 &&;
-- && : Bool → Bool → Bool;
-- && false _ := false;
-- && true a := a;
end;
not : Bool → Bool;
not true := false;
not false := true;
-- infixr 2 ||;
-- || : Bool → Bool → Bool;
-- || false a := a;
-- || true _ := true;
-- infixr 2 &&;
-- && : Bool → Bool → Bool;
-- && false _ := false;
-- && true a := a;

View File

@ -1,7 +1,5 @@
module Data.Maybe;
type Maybe (a : Type) :=
nothing : Maybe a |
just : a → Maybe a;
end;
type Maybe (a : Type) :=
| nothing : Maybe a
| just : a → Maybe a;

View File

@ -1,16 +1,15 @@
module Data.Nat;
type :=
zero : |
suc : ;
infixl 6 +;
+ : ;
+ zero b := b;
+ (suc a) b := suc (a + b);
type :=
| zero :
| suc : ;
infixl 7 *;
* : ;
* zero b := zero;
* (suc a) b := b + a * b;
infixl 6 +;
+ : ;
+ zero b := b;
+ (suc a) b := suc (a + b);
end;
infixl 7 *;
* : ;
* zero b := zero;
* (suc a) b := b + a * b;

View File

@ -1,6 +1,6 @@
module Data.Ord;
type Ordering :=
LT : Ordering |
EQ : Ordering |
GT : Ordering;
end;
type Ordering :=
| LT : Ordering
| EQ : Ordering
| GT : Ordering;

View File

@ -2,6 +2,4 @@ module Data.Product;
infixr 2 ×;
type × (a : Type) (b : Type) :=
, : a → b → a × b;
end;
| , : a → b → a × b;

View File

@ -14,5 +14,3 @@ g x y := f y;
h : {A : Type} -> A -> Maybe Bool;
h x := nothing;
end;

View File

@ -7,6 +7,4 @@ test : {A : Type} -> A -> A;
test x := x;
type Unit :=
unit : Unit;
end;
| unit : Unit;

View File

@ -5,5 +5,3 @@ open import Stdlib.Prelude;
k : Bool;
k := true;
end;

View File

@ -2,8 +2,7 @@ module ShadowPublicOpen;
module M;
module N;
axiom
A : Type;
axiom A : Type;
end;
open N public;
@ -11,5 +10,4 @@ end;
open M;
axiom
A : Type;
axiom A : Type;

View File

@ -1,5 +1,4 @@
module A;
type Foo := bar : Foo;
end;
type Foo :=
| bar : Foo;

View File

@ -1,11 +1,11 @@
module StdlibImport;
open import Stdlib.Prelude;
import A;
open import Stdlib.Prelude;
two : Nat;
two := 1 + 1;
import A;
foo : A.Foo;
foo := A.bar;
end;
two : Nat;
two := 1 + 1;
foo : A.Foo;
foo := A.bar;

View File

@ -29,8 +29,7 @@ infixl 7 ·;
主功能 : Nat;
主功能 := 0;
axiom
= : Type;
axiom = : Type;
K : Nat → Nat → Nat;
K =a@zero (=) := =a · =;

View File

@ -1,10 +1,9 @@
module Ack;
import Data.Nat;
open Data.Nat;
ack : ;
ack zero n := suc n;
ack (suc m) zero := ack m (suc zero);
ack (suc m) (suc n) := ack m (ack (suc m) n);
import Data.Nat;
open Data.Nat;
end;
ack : ;
ack zero n := suc n;
ack (suc m) zero := ack m (suc zero);
ack (suc m) (suc n) := ack m (ack (suc m) n);

View File

@ -1,24 +1,23 @@
module Data.Bool;
type Bool :=
true : Bool |
false : Bool;
not : Bool → Bool;
not true := false;
not false := true;
type Bool :=
| true : Bool
| false : Bool;
infixr 2 ||;
|| : Bool → Bool → Bool;
|| false a := a;
|| true _ := true;
not : Bool → Bool;
not true := false;
not false := true;
infixr 2 &&;
&& : Bool → Bool → Bool;
&& false _ := false;
&& true a := a;
infixr 2 ||;
|| : Bool → Bool → Bool;
|| false a := a;
|| true _ := true;
ite : {a : Type} → Bool → a → a → a;
ite true a _ := a;
ite false _ b := b;
infixr 2 &&;
&& : Bool → Bool → Bool;
&& false _ := false;
&& true a := a;
end;
ite : {a : Type} → Bool → a → a → a;
ite true a _ := a;
ite false _ b := b;

View File

@ -7,16 +7,18 @@ import Data.Nat;
open Data.Nat;
type List (A : Type) :=
nil : List A |
cons : A → List A → List A;
| nil : List A
| cons : A → List A → List A;
-- Do not remove implicit arguments. Useful for testing.
foldr : {A : Type} → {B : Type} → (A → B → B) → B → List A → B;
foldr :
{A : Type} → {B : Type} → (A → B → B) → B → List A → B;
foldr _ z nil := z;
foldr f z (cons h hs) := f h (foldr {_} f z hs);
foldl : {A : Type} → {B : Type} → (B → A → B) → B → List A → B;
foldl f z nil := z ;
foldl :
{A : Type} → {B : Type} → (B → A → B) → B → List A → B;
foldl f z nil := z;
foldl {_} {_} f z (cons h hs) := foldl {_} f (f z h) hs;
map : {A : Type} → {B : Type} → (A → B) → List A → List B;
@ -25,9 +27,8 @@ map f (cons h hs) := cons (f h) (map f hs);
filter : {A : Type} → (A → Bool) → List A → List A;
filter f nil := nil;
filter f (cons h hs) := ite (f h)
(cons h (filter {_} f hs))
(filter f hs);
filter f (cons h hs) :=
ite (f h) (cons h (filter {_} f hs)) (filter f hs);
length : {A : Type} → List A → ;
length nil := zero;
@ -51,5 +52,3 @@ take _ _ := nil;
concat : {A : Type} → List A → List A → List A;
concat nil ys := ys;
concat (cons x xs) ys := cons x (concat xs ys);
end;

View File

@ -1,27 +1,28 @@
module Data.Nat;
type :=
zero : |
suc : ;
infixl 6 +;
+ : ;
+ zero b := b;
+ (suc a) b := suc (a + b);
type :=
| zero :
| suc : ;
infixl 7 *;
* : ;
* zero b := zero;
* (suc a) b := b + a * b;
infixl 6 +;
+ : ;
+ zero b := b;
+ (suc a) b := suc (a + b);
import Data.Bool;
open Data.Bool;
infixl 7 *;
* : ;
* zero b := zero;
* (suc a) b := b + a * b;
even : → Bool;
odd : Bool;
import Data.Bool;
open Data.Bool;
even zero := true;
even (suc n) := odd n;
even : → Bool;
odd zero := false;
odd (suc n) := even n;
end;
odd : → Bool;
even zero := true;
even (suc n) := odd n;
odd zero := false;
odd (suc n) := even n;

View File

@ -1,7 +1,7 @@
module Fib;
type Nat :=
zero : Nat
| zero : Nat
| suc : Nat → Nat;
infixl 6 +;
@ -11,7 +11,5 @@ infixl 6 +;
fib : Nat -> Nat;
fib zero := zero;
fib (suc (zero)) := suc zero;
fib (suc zero) := suc zero;
fib (suc (suc n)) := fib (suc n) + fib n;
end;

View File

@ -2,10 +2,11 @@ module Mutual;
axiom A : Type;
terminating f : A -> A -> A;
terminating g : A -> A -> A;
terminating
f : A -> A -> A;
terminating
g : A -> A -> A;
g x y := f x x;
f x y := g x (f x x);
end;
f x y := g x (f x x);

View File

@ -1,17 +1,17 @@
module TreeGen;
open import Stdlib.Prelude;
type Tree :=
| leaf : Tree
| node : Tree → Tree → Tree;
open import Stdlib.Prelude;
gen : Nat → Tree;
gen zero := leaf;
gen (suc zero) := node leaf leaf;
gen (suc (suc n')) := node (gen n') (gen (suc n'));
type Tree :=
| leaf : Tree
| node : Tree → Tree → Tree;
gen2 : Nat → Tree;
gen2 zero := leaf;
gen2 (suc zero) := node leaf leaf;
gen2 (suc n@(suc n')) := node (gen2 n') (gen2 n);
end;
gen : Nat → Tree;
gen zero := leaf;
gen (suc zero) := node leaf leaf;
gen (suc (suc n')) := node (gen n') (gen (suc n'));
gen2 : Nat → Tree;
gen2 zero := leaf;
gen2 (suc zero) := node leaf leaf;
gen2 (suc n@(suc n')) := node (gen2 n') (gen2 n);

View File

@ -1,7 +1,7 @@
module Undefined;
axiom A : Type;
terminating undefined : A;
undefined := undefined;
end;
terminating
undefined : A;
undefined := undefined;

View File

@ -1,6 +1,4 @@
module M;
type T (A : Type) :=
c : T _;
end;
| c : T _;

View File

@ -1,8 +1,8 @@
module M;
type :=
z : |
s : ;
| z :
| s : ;
nat : Type;
nat := ;
@ -14,5 +14,3 @@ infixl 1 +;
+ : nat2 → nat → nat;
+ z b := b;
+ (s a) b := s (a + b);
end;

View File

@ -1,22 +1,29 @@
module M;
open import Stdlib.Prelude;
S : {A : Type} → {B : Type} → {C : Type} → (A → B → C) → (A → B) → A → C;
S x y z := x z (y z);
open import Stdlib.Prelude;
K : {A : Type} → {B : Type} → A → B → A;
K x y := x;
S :
{A : Type}
→ {B : Type}
→ {C : Type}
→ (A → B → C)
→ (A → B)
→ A
→ C;
S x y z := x z (y z);
I : {A : Type} → A → A;
I := S K (K {_} {Bool});
K : {A : Type} → {B : Type} → A → B → A;
K x y := x;
main : IO;
main := printNatLn
I : {A : Type} → A → A;
I := S K (K {_} {Bool});
main : IO;
main :=
printNatLn
$ I {Nat} 1
+ I I 1
+ I (I 1)
+ I 1
+ I (I I) I (I I I) 1
+ I I I (I I I (I I)) I (I I) I I I 1;
end;

View File

@ -1,11 +1,13 @@
module builtinFail;
open import Stdlib.Data.String;
open import Stdlib.System.IO;
builtin fail axiom fail : {A : Type} → String → A;
open import Stdlib.Data.String;
open import Stdlib.System.IO;
main : IO;
main := printStringLn "Get"
builtin fail
axiom fail : {A : Type} → String → A;
main : IO;
main :=
printStringLn "Get"
>> fail "Enough"
>> printStringLn "Sleep";
end;

View File

@ -1,12 +1,14 @@
module builtinTrace;
open import Stdlib.Prelude;
open import Stdlib.Data.Nat.Ord;
builtin trace axiom trace : {A : Type} → {B : Type} → A → B → B;
open import Stdlib.Prelude;
open import Stdlib.Data.Nat.Ord;
terminating
f : Nat → Nat → Nat;
f x y := if (x == 0) y (trace x (f (sub x 1) y));
builtin trace
axiom trace : {A : Type} → {B : Type} → A → B → B;
terminating
f : Nat → Nat → Nat;
f x y := if (x == 0) y (trace x (f (sub x 1) y));
{-
f 4 0 =
@ -20,6 +22,5 @@ trace 4 (f 3 0)
𝔸 β \X \Y . Apply (Apply trace X) Y
-}
main : IO;
main := printNatLn $ f 4 0;
end;
main : IO;
main := printNatLn $ f 4 0;

View File

@ -1,13 +1,13 @@
module LetSynonym;
type T :=
| t : T;
main : T;
main :=
let
A : Type;
A := T;
x : A;
x := t;
in x;
end;
type T :=
| t : T;
main : T;
main :=
let
A : Type;
A := T;
x : A;
x := t;
in x;