slight parser optimization

This commit is contained in:
Rachel Lambda Samuelsson 2022-08-01 18:26:13 +02:00
parent 7c24f93efc
commit 9275d39107

View File

@ -222,16 +222,23 @@ lexPi str =
{- Basic idea, parsing has a list of the identifiers to convert to -} {- Basic idea, parsing has a list of the identifiers to convert to -}
{- de bruijn indecies, and a Nat to keep track of context size -} {- de bruijn indecies, and a Nat to keep track of context size -}
mutual mutual
-- has pi, sigma, and arrows, strongest binding
expr : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n) expr : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n)
expr defs n env = tpi defs n env expr defs n env = tpi defs n env
<|> tsigma defs n env <|> tsigma defs n env
<|> (do <|> (do
e <- expr1 defs n env e <- expr1 defs n env
tarr defs n env e <|> tapp defs n env e <|> pure e) tarr defs n env e <|> pure e)
-- handles application of expr2s (and terms)
expr1 : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n) expr1 : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n)
expr1 defs n env = ttopind defs n env expr1 defs n env = do
e <- expr2 defs n env
tapp defs n env e <|> pure e
-- anything which has an application in it (and induction principle) or a term
expr2 : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n)
expr2 defs n env = ttopind defs n env
<|> tbotind defs n env <|> tbotind defs n env
<|> tsuc defs n env <|> tsuc defs n env
<|> tnatind defs n env <|> tnatind defs n env
@ -239,10 +246,9 @@ mutual
<|> tid defs n env <|> tid defs n env
<|> trefl defs n env <|> trefl defs n env
<|> tj defs n env <|> tj defs n env
<|> (do <|> term defs n env
t <- term defs n env
tapp defs n env t <|> pure t)
-- terms, no application
term : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n) term : List String -> (n : Nat) -> Vect n String -> Grammar () PiToken True (Term n)
term defs n env = ttype term defs n env = ttype
<|> ttop <|> ttop