Show instances, fixed a bunch of bugs in parsing

- The case / let / indent stuff actually works
- Needed a bunch of defers
- Idris silently builds loops in immediate definitions
This commit is contained in:
2022-09-10 22:10:35 -07:00
parent 39deff1465
commit 1ed884eff9
10 changed files with 305 additions and 55 deletions

View File

@@ -1,7 +1,16 @@
module Syntax
import Data.String
import Derive
-- Good enough start, lets parse
-- This is informed by pi-forall and others and is somewhat low level
-- %language ElabReflection
-- %logging "foo" 19
%hide Name
%hide Decl
Name = String
@@ -9,8 +18,11 @@ data Term : Type where
TyTerm = Term
public export
data Literal = LString String | LInt Int | LBool Bool
public export
data RigCount = Rig0 | RigW
public export
data Plicity = Implicit | Explicit | Eq
public export
@@ -20,6 +32,8 @@ data Pattern
| PatWild
| PatLit Literal
-- %runElab deriveShow `{Pattern}
-- could be a pair, but I suspect stuff will be added?
public export
data CaseAlt = MkAlt Pattern Term
@@ -29,7 +43,7 @@ data Term
= Var Name
| Ann Term TyTerm
| Lit Literal
| Let Name Term Term
| Let (List (Name, Term)) Term
| Pi Name Plicity Term Term
| App Term Term
| Lam Pattern Term
@@ -56,3 +70,47 @@ record Module where
name : Name
imports : List Name
decls : List Decl
foo : List String -> String
foo ts = "(" ++ unwords ts ++ ")"
mutual
Show RigCount where
show Rig0 = "Rig0"
show RigW = "RigW"
Show Pattern where
show (PatVar str) = foo ["PatVar", show str]
show (PatCon str xs) = foo ["PatCon", show str, assert_total $ show xs]
show PatWild = "PatWild"
show (PatLit x) = foo ["PatLit" , show x]
Show CaseAlt where
show (MkAlt x y)= foo ["MkAlt", show x, assert_total $ show y]
Show Plicity where
show Implicit = "Implicit"
show Explicit = "Explicit"
show Eq = "Eq"
Show Literal where
show (LString str) = foo [ "LString", show str]
show (LInt i) = foo [ "LInt", show i]
show (LBool x) = foo [ "LBool", show x]
export
Show Term where
show (Var name) = foo ["Var", show name]
show (Ann t ty) = foo [ "Ann", show t, show ty]
show (Lit x) = foo [ "Lit", show x]
show (Let alts y) = foo [ "Let", assert_total $ show alts, show y]
show (Pi str x y z) = foo [ "Pi", show str, show x, show y, show z]
show (App x y) = foo [ "App", show x, show y]
show (Lam x y) = foo [ "Lam", show x, show y]
show (Case x xs) = foo [ "Case", show x, show xs]
show Wildcard = "Wildcard"
show (ParseError str) = foo [ "ParseError", "str"]