2023-03-04 15:02:51 -05:00
|
|
|
|
module Tests.Parser
|
|
|
|
|
|
|
|
|
|
import Quox.Parser
|
|
|
|
|
import Data.List
|
|
|
|
|
import Data.String
|
|
|
|
|
import TAP
|
2023-04-25 20:47:42 -04:00
|
|
|
|
import Language.Reflection
|
|
|
|
|
|
|
|
|
|
%language ElabReflection
|
2023-03-04 15:02:51 -05:00
|
|
|
|
|
|
|
|
|
public export
|
|
|
|
|
data Failure =
|
2023-03-12 13:28:37 -04:00
|
|
|
|
ParseError Parser.Error
|
2023-03-04 15:02:51 -05:00
|
|
|
|
| WrongResult String
|
|
|
|
|
| ExpectedFail String
|
|
|
|
|
|
|
|
|
|
export
|
2023-03-12 13:28:37 -04:00
|
|
|
|
ToInfo Parser.Error where
|
2023-03-04 15:02:51 -05:00
|
|
|
|
toInfo (LexError err) =
|
|
|
|
|
[("type", "LexError"), ("info", show err)]
|
|
|
|
|
toInfo (ParseError errs) =
|
|
|
|
|
("type", "ParseError") ::
|
|
|
|
|
map (bimap show show) ([1 .. length errs] `zip` toList errs)
|
2023-03-12 13:28:37 -04:00
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
ToInfo Failure where
|
|
|
|
|
toInfo (ParseError err) =
|
|
|
|
|
toInfo err
|
2023-03-04 15:02:51 -05:00
|
|
|
|
toInfo (WrongResult got) =
|
|
|
|
|
[("type", "WrongResult"), ("got", got)]
|
|
|
|
|
toInfo (ExpectedFail got) =
|
|
|
|
|
[("type", "ExpectedFail"), ("got", got)]
|
|
|
|
|
|
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parameters {auto _ : (Show a, Eq a)} {c : Bool} (grm : FileName -> Grammar c a)
|
|
|
|
|
parsesWith : String -> (a -> Bool) -> Test
|
|
|
|
|
parsesWith inp p = test (ltrim inp) $ do
|
2023-07-18 17:12:04 -04:00
|
|
|
|
res <- mapFst ParseError $ lexParseWith (grm "<test>") inp
|
2023-04-25 20:47:42 -04:00
|
|
|
|
unless (p res) $ Left $ WrongResult $ show res
|
2023-03-04 15:02:51 -05:00
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parsesAs : String -> a -> Test
|
|
|
|
|
parsesAs inp exp = parsesWith inp (== exp)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
|
%macro
|
|
|
|
|
parseMatch : String -> TTImp -> Elab Test
|
|
|
|
|
parseMatch inp pat =
|
|
|
|
|
parsesWith inp <$> check `(\case ~(pat) => True; _ => False)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseFails : String -> Test
|
|
|
|
|
parseFails inp = test "\{ltrim inp} # fails" $ do
|
|
|
|
|
either (const $ Right ()) (Left . ExpectedFail . show) $
|
|
|
|
|
lexParseWith (grm "‹test›") inp
|
2023-03-04 15:02:51 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export
|
|
|
|
|
tests : Test
|
|
|
|
|
tests = "parser" :- [
|
2023-04-24 16:25:00 -04:00
|
|
|
|
"pattern vars" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch patVar "_" `(Unused _),
|
|
|
|
|
parseMatch patVar "F" `(PV "F" _),
|
2023-04-24 16:25:00 -04:00
|
|
|
|
parseFails patVar "a.b.c"
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"names" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parsesAs (const qname) "x"
|
2023-03-12 13:28:37 -04:00
|
|
|
|
(MakePName [<] "x"),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parsesAs (const qname) "Data.String.length"
|
2023-03-12 13:28:37 -04:00
|
|
|
|
(MakePName [< "Data", "String"] "length"),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseFails (const qname) "_"
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"dimensions" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch dim "0" `(K Zero _),
|
|
|
|
|
parseMatch dim "1" `(K One _),
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch dim "𝑖" `(V "𝑖" {}),
|
2023-03-04 15:02:51 -05:00
|
|
|
|
parseFails dim "M.x",
|
|
|
|
|
parseFails dim "_"
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"quantities" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch qty "0" `(PQ Zero _),
|
|
|
|
|
parseMatch qty "1" `(PQ One _),
|
|
|
|
|
parseMatch qty "ω" `(PQ Any _),
|
|
|
|
|
parseMatch qty "#" `(PQ Any _),
|
2023-03-04 15:02:51 -05:00
|
|
|
|
parseFails qty "anythingElse",
|
|
|
|
|
parseFails qty "_"
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"enum types" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term #"{}"# `(Enum [] _),
|
|
|
|
|
parseMatch term #"{a}"# `(Enum ["a"] _),
|
|
|
|
|
parseMatch term #"{a,}"# `(Enum ["a"] _),
|
|
|
|
|
parseMatch term #"{a.b.c.d}"# `(Enum ["a.b.c.d"] _),
|
|
|
|
|
parseMatch term #"{"hel lo"}"# `(Enum ["hel lo"] _),
|
|
|
|
|
parseMatch term #"{a, b}"# `(Enum ["a", "b"] _),
|
|
|
|
|
parseMatch term #"{a, b,}"# `(Enum ["a", "b"] _),
|
|
|
|
|
parseMatch term #"{a, b, ","}"# `(Enum ["a", "b", ","] _),
|
2023-03-04 15:02:51 -05:00
|
|
|
|
parseFails term #"{,}"#
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"tags" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term #" 'a "# `(Tag "a" _),
|
|
|
|
|
parseMatch term #" 'abc "# `(Tag "abc" _),
|
|
|
|
|
parseMatch term #" '"abc" "# `(Tag "abc" _),
|
|
|
|
|
parseMatch term #" '"a b c" "# `(Tag "a b c" _),
|
|
|
|
|
note "application to two arguments",
|
|
|
|
|
parseMatch term #" 'a b c "#
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (App (Tag "a" _) (V "b" {}) _) (V "c" {}) _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"universes" :- [
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch term "★⁰" `(TYPE 0 _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "★1" `(TYPE 1 _),
|
|
|
|
|
parseMatch term "★ 2" `(TYPE 2 _),
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch term "Type³" `(TYPE 3 _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "Type4" `(TYPE 4 _),
|
|
|
|
|
parseMatch term "Type 100" `(TYPE 100 _),
|
|
|
|
|
parseMatch term "(Type 1000)" `(TYPE 1000 _),
|
2023-05-21 14:33:42 -04:00
|
|
|
|
parseMatch term "Type" `(TYPE 0 _),
|
|
|
|
|
parseMatch term "★" `(TYPE 0 _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"applications" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(V "f" {}),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f.x.y"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(V (MakePName [< "f", "x"] "y") {}),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (V "f" {}) (V "x" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f x y"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (App (V "f" {}) (V "x" {}) _) (V "y" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(f x) y"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (App (V "f" {}) (V "x" {}) _) (V "y" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f (g x)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (V "f" {}) (App (V "g" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f (g x) y"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (App (V "f" {}) (App (V "g" {}) (V "x" {}) _) _) (V "y" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f @p"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(DApp (V "f" {}) (V "p" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f x @p y"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(App (DApp (App (V "f" {}) (V "x" {}) _) (V "p" {}) _) (V "y" {}) _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"annotations" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f :: A"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Ann (V "f" {}) (V "A" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f ∷ A"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Ann (V "f" {}) (V "A" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f x y ∷ A B C"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Ann (App (App (V "f" {}) (V "x" {}) _) (V "y" {}) _)
|
|
|
|
|
(App (App (V "A" {}) (V "B" {}) _) (V "C" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "Type 0 ∷ Type 1 ∷ Type 2"
|
|
|
|
|
`(Ann (TYPE 0 _) (Ann (TYPE 1 _) (TYPE 2 _) _) _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"binders" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "1.(x : A) → B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ One _) (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "1.(x : A) -> B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ One _) (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "ω.(x : A) → B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ Any _) (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "#.(x : A) -> B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ Any _) (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "1.(x y : A) -> B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ One _) (PV "x" _) (V "A" {})
|
|
|
|
|
(Pi (PQ One _) (PV "y" _) (V "A" {})
|
|
|
|
|
(App (V "B" {}) (V "x" {}) _) _) _),
|
2023-07-18 17:12:04 -04:00
|
|
|
|
parseMatch term "(x : A) → B x"
|
|
|
|
|
`(Pi (PQ One _) (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "1.A → B"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pi (PQ One _) (Unused _) (V "A" {}) (V "B" {}) _),
|
2023-07-18 17:12:04 -04:00
|
|
|
|
parseMatch term "A → B"
|
|
|
|
|
`(Pi (PQ One _) (Unused _) (V "A" {}) (V "B" {}) _),
|
|
|
|
|
parseMatch term "A → B → C"
|
|
|
|
|
`(Pi (PQ One _) (Unused _) (V "A" {})
|
|
|
|
|
(Pi (PQ One _) (Unused _) (V "B" {}) (V "C" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "1.(List A) → List B"
|
|
|
|
|
`(Pi (PQ One _) (Unused _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(App (V "List" {}) (V "A" {}) _)
|
|
|
|
|
(App (V "List" {}) (V "B" {}) _) _),
|
|
|
|
|
parseMatch term "0.★⁰ → ★⁰"
|
|
|
|
|
`(Pi (PQ Zero _) (Unused _) (TYPE 0 _) (TYPE 0 _) _),
|
2023-03-18 18:27:27 -04:00
|
|
|
|
parseFails term "1.List A → List B",
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(x : A) × B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(x : A) ** B x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (PV "x" _) (V "A" {}) (App (V "B" {}) (V "x" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(x y : A) × B" $
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (PV "x" _) (V "A" {}) (Sig (PV "y" _) (V "A" {}) (V "B" {}) _) _),
|
2023-03-18 18:27:27 -04:00
|
|
|
|
parseFails term "1.(x : A) × B x",
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "A × B"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (Unused _) (V "A" {}) (V "B" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "A ** B"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (Unused _) (V "A" {}) (V "B" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "A × B × C" $
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Sig (Unused _) (V "A" {}) (Sig (Unused _) (V "B" {}) (V "C" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(A × B) × C" $
|
2023-07-18 17:12:04 -04:00
|
|
|
|
`(Sig (Unused _) (Sig (Unused _) (V "A" {}) (V "B" {}) _) (V "C" {}) _),
|
|
|
|
|
parseMatch term "A × B → C" $
|
|
|
|
|
`(Pi (PQ One _) (Unused _)
|
|
|
|
|
(Sig (Unused _) (V "A" {}) (V "B" {}) _)
|
|
|
|
|
(V "C" {}) _),
|
|
|
|
|
parseMatch term "A → B × C" $
|
|
|
|
|
`(Pi (PQ One _) (Unused _)
|
|
|
|
|
(V "A" {})
|
|
|
|
|
(Sig (Unused _) (V "B" {}) (V "C" {}) _) _),
|
|
|
|
|
parseMatch term "A → B × C → D" $
|
|
|
|
|
`(Pi (PQ One _) (Unused _)
|
|
|
|
|
(V "A" {})
|
|
|
|
|
(Pi (PQ One _) (Unused _)
|
|
|
|
|
(Sig (Unused _) (V "B" {}) (V "C" {}) _)
|
|
|
|
|
(V "D" {}) _) _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"lambdas" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "λ x ⇒ x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Lam (PV "x" _) (V "x" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "fun x => x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Lam (PV "x" _) (V "x" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "δ i ⇒ x @i"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(DLam (PV "i" _) (DApp (V "x" {}) (V "i" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "dfun i => x @i"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(DLam (PV "i" _) (DApp (V "x" {}) (V "i" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "λ x y z ⇒ x z y"
|
|
|
|
|
`(Lam (PV "x" _)
|
|
|
|
|
(Lam (PV "y" _)
|
|
|
|
|
(Lam (PV "z" _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(App (App (V "x" {}) (V "z" {}) _) (V "y" {}) _) _) _) _)
|
2023-03-04 15:02:51 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"pairs" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(x, y)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (V "x" {}) (V "y" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(x, y, z)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (V "x" {}) (Pair (V "y" {}) (V "z" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "((x, y), z)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (Pair (V "x" {}) (V "y" {}) _) (V "z" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(f x, g @y)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (App (V "f" {}) (V "x" {}) _) (DApp (V "g" {}) (V "y" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "((x : A) × B, 0.(x : C) → D)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (Sig (PV "x" _) (V "A" {}) (V "B" {}) _)
|
|
|
|
|
(Pi (PQ Zero _) (PV "x" _) (V "C" {}) (V "D" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "(λ x ⇒ x, δ i ⇒ e @i)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Pair (Lam (PV "x" _) (V "x" {}) _)
|
|
|
|
|
(DLam (PV "i" _) (DApp (V "e" {}) (V "i" {}) _) _) _),
|
|
|
|
|
parseMatch term "(x,)" `(V "x" {}), -- i GUESS
|
2023-03-04 15:02:51 -05:00
|
|
|
|
parseFails term "(,y)",
|
|
|
|
|
parseFails term "(x,,y)"
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"equality type" :- [
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "Eq (i ⇒ A) s t"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (PV "i" _, V "A" {}) (V "s" {}) (V "t" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "Eq (i ⇒ A (B @i)) (f x) (g y)"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (PV "i" _, App (V "A" {}) (DApp (V "B" {}) (V "i" {}) _) _)
|
|
|
|
|
(App (V "f" {}) (V "x" {}) _)
|
|
|
|
|
(App (V "g" {}) (V "y" {}) _) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "Eq A s t"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (Unused _, V "A" {}) (V "s" {}) (V "t" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "s ≡ t : A"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (Unused _, V "A" {}) (V "s" {}) (V "t" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "s == t : A"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (Unused _, V "A" {}) (V "s" {}) (V "t" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "f x ≡ g y : A B"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Eq (Unused _, App (V "A" {}) (V "B" {}) _)
|
|
|
|
|
(App (V "f" {}) (V "x" {}) _)
|
|
|
|
|
(App (V "g" {}) (V "y" {}) _) _),
|
|
|
|
|
parseMatch term "(A × B) ≡ (A' × B') : ★¹"
|
2023-04-25 20:47:42 -04:00
|
|
|
|
`(Eq (Unused _, TYPE 1 _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(Sig (Unused _) (V "A" {}) (V "B" {}) _)
|
|
|
|
|
(Sig (Unused _) (V "A'" {}) (V "B'" {}) _) _),
|
|
|
|
|
note "A × (B ≡ A' × B' : ★¹)",
|
|
|
|
|
parseMatch term "A × B ≡ A' × B' : ★¹"
|
|
|
|
|
`(Sig (Unused _) (V "A" {})
|
2023-04-25 20:47:42 -04:00
|
|
|
|
(Eq (Unused _, TYPE 1 _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(V "B" {}) (Sig (Unused _) (V "A'" {}) (V "B'" {}) _) _) _),
|
2023-03-04 15:02:51 -05:00
|
|
|
|
parseFails term "Eq",
|
|
|
|
|
parseFails term "Eq s t",
|
|
|
|
|
parseFails term "s ≡ t",
|
|
|
|
|
parseFails term "≡"
|
|
|
|
|
],
|
|
|
|
|
|
2023-03-26 08:40:54 -04:00
|
|
|
|
"naturals" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "ℕ" `(Nat _),
|
|
|
|
|
parseMatch term "Nat" `(Nat _),
|
|
|
|
|
parseMatch term "zero" `(Zero _),
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch term "succ n" `(Succ (V "n" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "3"
|
|
|
|
|
`(Succ (Succ (Succ (Zero _) _) _) _),
|
|
|
|
|
parseMatch term "succ (succ 1)"
|
|
|
|
|
`(Succ (Succ (Succ (Zero _) _) _) _),
|
2023-04-24 16:25:00 -04:00
|
|
|
|
parseFails term "succ succ 5",
|
2023-03-26 08:40:54 -04:00
|
|
|
|
parseFails term "succ"
|
|
|
|
|
],
|
|
|
|
|
|
2023-03-31 13:11:35 -04:00
|
|
|
|
"box" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "[1.ℕ]"
|
|
|
|
|
`(BOX (PQ One _) (Nat _) _),
|
|
|
|
|
parseMatch term "[ω. ℕ × ℕ]"
|
|
|
|
|
`(BOX (PQ Any _) (Sig (Unused _) (Nat _) (Nat _) _) _),
|
|
|
|
|
parseMatch term "[a]"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Box (V "a" {}) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "[0]"
|
|
|
|
|
`(Box (Zero _) _),
|
|
|
|
|
parseMatch term "[1]"
|
|
|
|
|
`(Box (Succ (Zero _) _) _)
|
2023-03-31 13:11:35 -04:00
|
|
|
|
],
|
|
|
|
|
|
2023-04-24 16:25:00 -04:00
|
|
|
|
"coe" :- [
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "coe A @p @q x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Coe (Unused _, V "A" {}) (V "p" {}) (V "q" {}) (V "x" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "coe (i ⇒ A) @p @q x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Coe (PV "i" _, V "A" {}) (V "p" {}) (V "q" {}) (V "x" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "coe A x"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Coe (Unused _, V "A" {}) (K Zero _) (K One _) (V "x" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseFails term "coe A @p @q",
|
|
|
|
|
parseFails term "coe (i ⇒ A) @p q x"
|
2023-04-24 16:25:00 -04:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"comp" :- [
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "comp A @p @q s @r { 0 𝑗 ⇒ s₀; 1 𝑘 ⇒ s₁ }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Comp (Unused _, V "A" {}) (V "p" {}) (V "q" {}) (V "s" {}) (V "r" {})
|
|
|
|
|
(PV "𝑗" _, V "s₀" {}) (PV "𝑘" _, V "s₁" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "comp (𝑖 ⇒ A) @p @q s @r { 0 𝑗 ⇒ s₀; 1 𝑘 ⇒ s₁ }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Comp (PV "𝑖" _, V "A" {}) (V "p" {}) (V "q" {}) (V "s" {}) (V "r" {})
|
|
|
|
|
(PV "𝑗" _, V "s₀" {}) (PV "𝑘" _, V "s₁" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "comp A @p @q s @r { 1 𝑗 ⇒ s₀; 0 𝑘 ⇒ s₁; }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Comp (Unused _, V "A" {}) (V "p" {}) (V "q" {}) (V "s" {}) (V "r" {})
|
|
|
|
|
(PV "𝑘" _, V "s₁" {}) (PV "𝑗" _, V "s₀" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseMatch term "comp A s @r { 0 𝑗 ⇒ s₀; 1 𝑘 ⇒ s₁ }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Comp (Unused _, V "A" {}) (K Zero _) (K One _) (V "s" {}) (V "r" {})
|
|
|
|
|
(PV "𝑗" _, V "s₀" {}) (PV "𝑘" _, V "s₁" {}) _),
|
2023-05-16 12:14:42 -04:00
|
|
|
|
parseFails term "comp A @p @q s @r { 1 𝑗 ⇒ s₀; 1 𝑘 ⇒ s₁; }",
|
|
|
|
|
parseFails term "comp A @p @q s @r { 0 𝑗 ⇒ s₀ }",
|
|
|
|
|
parseFails term "comp A @p @q s @r { }"
|
2023-04-24 16:25:00 -04:00
|
|
|
|
],
|
|
|
|
|
|
2023-03-04 15:02:51 -05:00
|
|
|
|
"case" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term
|
|
|
|
|
"case1 f s return x ⇒ A x of { (l, r) ⇒ r l }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ One _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
2023-04-25 20:47:42 -04:00
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term
|
|
|
|
|
"case1 f s return x => A x of { (l, r) ⇒ r l; }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ One _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
2023-04-25 20:47:42 -04:00
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term
|
2023-07-18 17:12:04 -04:00
|
|
|
|
"case 1. f s return x ⇒ A x of { (l, r) ⇒ r l }"
|
|
|
|
|
`(Case (PQ One _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
|
|
|
|
parseMatch term
|
|
|
|
|
"caseω f s return x ⇒ A x of { (l, r) ⇒ r l }"
|
|
|
|
|
`(Case (PQ Any _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
|
|
|
|
parseMatch term
|
|
|
|
|
"case0 f s return x ⇒ A x of { (l, r) ⇒ r l }"
|
|
|
|
|
`(Case (PQ Zero _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
|
|
|
|
parseMatch term
|
|
|
|
|
"case f s return x ⇒ A x of { (l, r) ⇒ r l }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ One _) (App (V "f" {}) (V "s" {}) _)
|
|
|
|
|
(PV "x" _, App (V "A" {}) (V "x" {}) _)
|
2023-04-25 20:47:42 -04:00
|
|
|
|
(CasePair (PV "l" _, PV "r" _)
|
2023-05-21 14:09:34 -04:00
|
|
|
|
(App (V "r" {}) (V "l" {}) _) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term
|
|
|
|
|
"case1 t return A of { 'x ⇒ p; 'y ⇒ q; 'z ⇒ r }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ One _) (V "t" {})
|
|
|
|
|
(Unused _, V "A" {})
|
|
|
|
|
(CaseEnum [(PT "x" _, V "p" {}),
|
|
|
|
|
(PT "y" _, V "q" {}),
|
|
|
|
|
(PT "z" _, V "r" {})] _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "caseω t return A of {}"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ Any _) (V "t" {}) (Unused _, V "A" {}) (CaseEnum [] _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "case# t return A of {}"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ Any _) (V "t" {}) (Unused _, V "A" {}) (CaseEnum [] _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "caseω n return A of { 0 ⇒ a; succ n' ⇒ b }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ Any _) (V "n" {}) (Unused _, V "A" {})
|
|
|
|
|
(CaseNat (V "a" {}) (PV "n'" _, PQ Zero _, Unused _, V "b" {}) _) _),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch term "caseω n return ℕ of { succ _, 1.ih ⇒ ih; zero ⇒ 0; }"
|
2023-05-21 14:09:34 -04:00
|
|
|
|
`(Case (PQ Any _) (V "n" {}) (Unused _, Nat _)
|
|
|
|
|
(CaseNat (Zero _) (Unused _, PQ One _, PV "ih" _, V "ih" {}) _) _),
|
2023-07-18 17:12:04 -04:00
|
|
|
|
parseMatch term "caseω n return ℕ of { succ _, ω.ih ⇒ ih; zero ⇒ 0; }"
|
|
|
|
|
`(Case (PQ Any _) (V "n" {}) (Unused _, Nat _)
|
|
|
|
|
(CaseNat (Zero _) (Unused _, PQ Any _, PV "ih" _, V "ih" {}) _) _),
|
|
|
|
|
parseMatch term "caseω n return ℕ of { succ _, ih ⇒ ih; zero ⇒ 0; }"
|
|
|
|
|
`(Case (PQ Any _) (V "n" {}) (Unused _, Nat _)
|
|
|
|
|
(CaseNat (Zero _) (Unused _, PQ One _, PV "ih" _, V "ih" {}) _) _),
|
2023-03-26 08:40:54 -04:00
|
|
|
|
parseFails term "caseω n return A of { zero ⇒ a }",
|
|
|
|
|
parseFails term "caseω n return ℕ of { succ ⇒ 5 }"
|
2023-03-06 05:35:57 -05:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"definitions" :- [
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch definition "defω x : {a} × {b} = ('a, 'b);"
|
|
|
|
|
`(MkPDef (PQ Any _) "x"
|
|
|
|
|
(Just (Sig (Unused _) (Enum ["a"] _) (Enum ["b"] _) _))
|
|
|
|
|
(Pair (Tag "a" _) (Tag "b" _) _) _),
|
|
|
|
|
parseMatch definition "def# x : {a} ** {b} = ('a, 'b)"
|
|
|
|
|
`(MkPDef (PQ Any _) "x"
|
|
|
|
|
(Just (Sig (Unused _) (Enum ["a"] _) (Enum ["b"] _) _))
|
|
|
|
|
(Pair (Tag "a" _) (Tag "b" _) _) _),
|
|
|
|
|
parseMatch definition "def ω.x : {a} × {b} = ('a, 'b)"
|
|
|
|
|
`(MkPDef (PQ Any _) "x"
|
|
|
|
|
(Just (Sig (Unused _) (Enum ["a"] _) (Enum ["b"] _) _))
|
|
|
|
|
(Pair (Tag "a" _) (Tag "b" _) _) _),
|
|
|
|
|
parseMatch definition "def x : {a} × {b} = ('a, 'b)"
|
|
|
|
|
`(MkPDef (PQ Any _) "x"
|
|
|
|
|
(Just (Sig (Unused _) (Enum ["a"] _) (Enum ["b"] _) _))
|
|
|
|
|
(Pair (Tag "a" _) (Tag "b" _) _) _),
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch definition "def0 A : ★⁰ = {a, b, c}"
|
2023-04-25 20:47:42 -04:00
|
|
|
|
`(MkPDef (PQ Zero _) "A" (Just $ TYPE 0 _)
|
|
|
|
|
(Enum ["a", "b", "c"] _) _)
|
2023-03-12 13:28:37 -04:00
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
"top level" :- [
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch input "def0 A : ★⁰ = {}; def0 B : ★¹ = A;"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD $ MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Zero _) "A" (Just $ TYPE 0 _) (Enum [] _) _) _,
|
|
|
|
|
PD $ MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Zero _) "B" (Just $ TYPE 1 _) (V "A" {}) _) _]),
|
2023-05-21 14:09:34 -04:00
|
|
|
|
parseMatch input "def0 A : ★⁰ = {} def0 B : ★¹ = A" $
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD $ MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Zero _) "A" (Just $ TYPE 0 _) (Enum [] _) _) _,
|
|
|
|
|
PD $ MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Zero _) "B" (Just $ TYPE 1 _) (V "A" {}) _) _]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
note "empty input",
|
|
|
|
|
parsesAs input "" [],
|
2023-04-24 16:25:00 -04:00
|
|
|
|
parseFails input ";;;;;;;;;;;;;;;;;;;;;;;;;;",
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input "namespace a {}"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD $ MkPDecl [] (PNs $ MkPNamespace [< "a"] [] _) _]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input "namespace a.b.c {}"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD $ MkPDecl []
|
|
|
|
|
(PNs $ MkPNamespace [< "a", "b", "c"] [] _) _]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input "namespace a {namespace b {}}"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD (MkPDecl []
|
|
|
|
|
(PNs $ MkPNamespace [< "a"]
|
|
|
|
|
[MkPDecl [] (PNs $ MkPNamespace [< "b"] [] _) _] _) _)]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input "namespace a {def x = 't ∷ {t}}"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD (MkPDecl []
|
|
|
|
|
(PNs $ MkPNamespace [< "a"]
|
|
|
|
|
[MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Any _) "x" Nothing
|
|
|
|
|
(Ann (Tag "t" _) (Enum ["t"] _) _) _) _] _) _)]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input "namespace a {def x = 't ∷ {t}} def y = a.x"
|
2023-09-22 12:38:32 -04:00
|
|
|
|
`([PD (MkPDecl []
|
|
|
|
|
(PNs $ MkPNamespace [< "a"]
|
|
|
|
|
[MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Any _) "x" Nothing
|
|
|
|
|
(Ann (Tag "t" _) (Enum ["t"] _) _) _) _] _) _),
|
|
|
|
|
PD (MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Any _) "y" Nothing
|
|
|
|
|
(V (MakePName [< "a"] "x") Nothing _) _) _)]),
|
2023-04-25 20:47:42 -04:00
|
|
|
|
parseMatch input #" load "a.quox"; def b = a.b "#
|
|
|
|
|
`([PLoad "a.quox" _,
|
2023-09-22 12:38:32 -04:00
|
|
|
|
PD (MkPDecl []
|
|
|
|
|
(PDef $ MkPDef (PQ Any _) "b" Nothing
|
|
|
|
|
(V (MakePName [< "a"] "b") Nothing _) _) _)])
|
2023-03-04 15:02:51 -05:00
|
|
|
|
]
|
|
|
|
|
]
|