Rename parsers for consistency
This commit is contained in:
parent
a647b9e26f
commit
90f97c4c30
1 changed files with 8 additions and 6 deletions
|
|
@ -57,6 +57,7 @@ pTermToStat p = do
|
||||||
(TVar _) -> fail "expected term, not variable"
|
(TVar _) -> fail "expected term, not variable"
|
||||||
(TStat s) -> pure s
|
(TStat s) -> pure s
|
||||||
|
|
||||||
|
-- | Parse a statement of the form @name(args)@.
|
||||||
pPlainStat :: Parser (Stat T.Text)
|
pPlainStat :: Parser (Stat T.Text)
|
||||||
pPlainStat = do
|
pPlainStat = do
|
||||||
name <- pName
|
name <- pName
|
||||||
|
|
@ -64,7 +65,7 @@ pPlainStat = do
|
||||||
pure $ Stat name terms
|
pure $ Stat name terms
|
||||||
|
|
||||||
pStat :: Parser (Stat T.Text)
|
pStat :: Parser (Stat T.Text)
|
||||||
pStat = pPlainStat <|> pTermToStat pExpr
|
pStat = pPlainStat <|> pTermToStat pTerm
|
||||||
|
|
||||||
pStats :: Parser [Stat T.Text]
|
pStats :: Parser [Stat T.Text]
|
||||||
pStats = (pStat `sepBy1` symbol ",") <* symbol "."
|
pStats = (pStat `sepBy1` symbol ",") <* symbol "."
|
||||||
|
|
@ -83,16 +84,17 @@ pList = do
|
||||||
elems <- brackets $ pTerm `sepBy` symbol ","
|
elems <- brackets $ pTerm `sepBy` symbol ","
|
||||||
pure $ foldr (\a b -> TStat $ Stat "[|]" [a, b]) (TStat $ Stat "[]" []) elems
|
pure $ foldr (\a b -> TStat $ Stat "[|]" [a, b]) (TStat $ Stat "[]" []) elems
|
||||||
|
|
||||||
pTerm :: Parser (Term T.Text)
|
-- | Parse a term that is not an expression.
|
||||||
pTerm
|
pPlainTerm :: Parser (Term T.Text)
|
||||||
|
pPlainTerm
|
||||||
= (TVar <$> pVarName)
|
= (TVar <$> pVarName)
|
||||||
<|> (TStat <$> pPlainStat)
|
<|> (TStat <$> pPlainStat)
|
||||||
<|> try pCons
|
<|> try pCons
|
||||||
<|> pList
|
<|> pList
|
||||||
<|> parens pExpr
|
<|> parens pTerm
|
||||||
|
|
||||||
pExpr :: Parser (Term T.Text)
|
pTerm :: Parser (Term T.Text)
|
||||||
pExpr = makeExprParser pTerm
|
pTerm = makeExprParser pPlainTerm
|
||||||
[ [ binary "=" ]
|
[ [ binary "=" ]
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue