parser stuff
This commit is contained in:
parent
f5a98e6584
commit
1e7a6cf01f
2 changed files with 59 additions and 15 deletions
|
@ -4,6 +4,7 @@ import Quox.Syntax
|
|||
import Quox.Token
|
||||
import Quox.Lexer
|
||||
|
||||
import Data.Maybe
|
||||
import Data.SnocVect
|
||||
import Data.SnocList
|
||||
import Text.Parser
|
||||
|
@ -86,9 +87,9 @@ find _ _ = Nothing
|
|||
|
||||
|
||||
export
|
||||
bound : Vars k -> Grammar True (Var k)
|
||||
bound vs =
|
||||
terminal "bound variable" $ \case Name x => find1 vs x; _ => Nothing
|
||||
bound : (what : String) -> Vars k -> Grammar True (Var k)
|
||||
bound what vs = terminal "bound \{what} variable" $
|
||||
\case Name x => find1 vs x; _ => Nothing
|
||||
|
||||
export
|
||||
sname : Grammar True String
|
||||
|
@ -101,10 +102,13 @@ qname = do
|
|||
pure $ MakeName {mods = cast $ init parts, base = UN $ last parts}
|
||||
|
||||
export
|
||||
nameWith : Vars k -> Grammar True (Either (Var k) Name)
|
||||
nameWith vs = do
|
||||
nameWith : (bound : Vars k) -> (avoid : Vars n) ->
|
||||
Grammar True (Either (Var k) Name)
|
||||
nameWith bound avoid = do
|
||||
y <- qname
|
||||
pure $ maybe (Right y) Left $ find vs y
|
||||
when (isJust $ find avoid y) $
|
||||
fail "wrong type of bound variable: \{show y}"
|
||||
pure $ maybe (Right y) Left $ find bound y
|
||||
|
||||
|
||||
export
|
||||
|
@ -112,4 +116,16 @@ dimension : Vars d -> Grammar True (Dim d)
|
|||
dimension vs =
|
||||
K Zero <$ zero
|
||||
<|> K One <$ one
|
||||
<|> B <$> bound vs
|
||||
<|> B <$> bound "dimension" vs
|
||||
|
||||
|
||||
mutual
|
||||
export
|
||||
term : (dvars : Vars d) -> (tvars : Vars n) -> Grammar True (Term d n)
|
||||
term dvars tvars =
|
||||
E <$> squares (elim dvars tvars)
|
||||
|
||||
export
|
||||
elim : (dvars : Vars d) -> (tvars : Vars n) -> Grammar True (Elim d n)
|
||||
elim dvars tvars =
|
||||
either B F <$> nameWith {bound = tvars, avoid = dvars}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue