parser stuff
This commit is contained in:
parent
8a955eebb3
commit
50a2ec02cb
2 changed files with 38 additions and 27 deletions
|
@ -87,9 +87,23 @@ find _ _ = Nothing
|
|||
|
||||
|
||||
export
|
||||
bound : (what : String) -> Vars k -> Grammar True (Var k)
|
||||
bound what vs = terminal "bound \{what} variable" $
|
||||
\case Name x => find1 vs x; _ => Nothing
|
||||
checkAvoid1 : Vars n -> String -> Grammar False ()
|
||||
checkAvoid1 avoid y =
|
||||
when (isJust $ find1 avoid y) $
|
||||
fail "wrong type of bound variable: \{show y}"
|
||||
|
||||
export
|
||||
checkAvoid : Vars n -> Name -> Grammar False ()
|
||||
checkAvoid avoid (MakeName [<] (UN y)) = checkAvoid1 avoid y
|
||||
checkAvoid _ _ = pure ()
|
||||
|
||||
export
|
||||
bound : (what : String) -> (bound : Vars k) -> (avoid : Vars n) ->
|
||||
Grammar True (Var k)
|
||||
bound what vs avoid = do
|
||||
x <- terminal "bound \{what} variable" $ \case Name x => Just x; _ => Nothing
|
||||
checkAvoid1 avoid x
|
||||
maybe (fail "not in scope: \{x}") pure $ find1 vs x
|
||||
|
||||
export
|
||||
sname : Grammar True String
|
||||
|
@ -106,24 +120,23 @@ nameWith : (bound : Vars k) -> (avoid : Vars n) ->
|
|||
Grammar True (Either (Var k) Name)
|
||||
nameWith bound avoid = do
|
||||
y <- qname
|
||||
when (isJust $ find avoid y) $
|
||||
fail "wrong type of bound variable: \{show y}"
|
||||
checkAvoid avoid y
|
||||
pure $ maybe (Right y) Left $ find bound y
|
||||
|
||||
|
||||
export
|
||||
dimension : Vars d -> Grammar True (Dim d)
|
||||
dimension vs =
|
||||
dimension : (dvars : Vars d) -> (tvars : Vars n) -> Grammar True (Dim d)
|
||||
dimension dvars tvars =
|
||||
K Zero <$ zero
|
||||
<|> K One <$ one
|
||||
<|> B <$> bound "dimension" vs
|
||||
<|> B <$> bound "dimension" {bound = dvars, avoid = tvars}
|
||||
|
||||
|
||||
mutual
|
||||
export
|
||||
term : (dvars : Vars d) -> (tvars : Vars n) -> Grammar True (Term d n)
|
||||
term dvars tvars =
|
||||
E <$> squares (elim dvars tvars)
|
||||
E <$> squares (elim {dvars, tvars})
|
||||
|
||||
export
|
||||
elim : (dvars : Vars d) -> (tvars : Vars n) -> Grammar True (Elim d n)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue