Skip to content

Commit a3c1247

Browse files
committed
Kore.Parser.Parser: use From instances
1 parent 93aeec7 commit a3c1247

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

kore/src/Kore/Parser/Parser.hs

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ parseSymbolHead = parseSymbolOrAliasDeclarationHead Symbol
140140
-}
141141
parsePattern :: Parser ParsedPattern
142142
parsePattern =
143-
(embedParsedPattern <$> parseLiteral) <|> (parseAnyId >>= parseRemainder)
143+
parseLiteral <|> (parseAnyId >>= parseRemainder)
144144
where
145145
parseRemainder identifier =
146146
parseVariableRemainder identifier
147147
<|> parseKoreRemainder identifier
148-
<|> (parseApplicationRemainder identifier)
148+
<|> parseApplicationRemainder identifier
149149

150-
parseLiteral :: Parser (PatternF VariableName ParsedPattern)
150+
parseLiteral :: Parser ParsedPattern
151151
parseLiteral =
152-
(StringLiteralF . Const <$> parseStringLiteral)
152+
(from <$> parseStringLiteral)
153153
<?> "string literal"
154154

155155
parseVariable :: Parser (SomeVariable VariableName)
@@ -176,8 +176,7 @@ parseVariableRemainder identifier = do
176176
-- variable, not a symbol, and now we will validate it as a variable name.
177177
variableName <- getSomeVariableName identifier
178178
variableSort <- parseSort
179-
(pure . embedParsedPattern . VariableF . Const)
180-
Variable { variableName, variableSort }
179+
(pure . from) Variable { variableName, variableSort }
181180

182181
getSomeVariableName :: Id -> Parser (SomeVariableName VariableName)
183182
getSomeVariableName identifier =
@@ -258,8 +257,7 @@ parseApplicationRemainder :: Id -> Parser ParsedPattern
258257
parseApplicationRemainder identifier = do
259258
applicationSymbolOrAlias <- parseSymbolOrAliasRemainder identifier
260259
applicationChildren <- parens . list $ parsePattern
261-
(pure . embedParsedPattern . ApplicationF)
262-
Application { applicationSymbolOrAlias, applicationChildren }
260+
(pure . from) Application { applicationSymbolOrAlias, applicationChildren }
263261

264262
{- | Parse the tail of a 'SymbolOrAlias', after the @Id@.
265263
@@ -311,9 +309,7 @@ parseAssoc foldAssoc = do
311309
braces $ pure ()
312310
application <- parens $ parseApplication parsePattern
313311
let mkApplication child1 child2 =
314-
application { applicationChildren = [child1, child2] }
315-
& ApplicationF
316-
& embedParsedPattern
312+
from application { applicationChildren = [child1, child2] }
317313
case applicationChildren application of
318314
[] -> fail "expected one or more arguments"
319315
children -> pure (foldAssoc mkApplication children)
@@ -363,29 +359,29 @@ parseKoreRemainder :: Id -> Parser ParsedPattern
363359
parseKoreRemainder identifier =
364360
getSpecialId identifier >>= \case
365361
-- Connectives
366-
"top" -> embedParsedPattern . TopF <$> parseConnective0 Top
367-
"bottom" -> embedParsedPattern . BottomF <$> parseConnective0 Bottom
368-
"not" -> embedParsedPattern . NotF <$> parseConnective1 Not
369-
"and" -> embedParsedPattern . AndF <$> parseConnective2 And
370-
"or" -> embedParsedPattern . OrF <$> parseConnective2 Or
371-
"implies" -> embedParsedPattern . ImpliesF <$> parseConnective2 Implies
372-
"iff" -> embedParsedPattern . IffF <$> parseConnective2 Iff
362+
"top" -> from <$> parseConnective0 Top
363+
"bottom" -> from <$> parseConnective0 Bottom
364+
"not" -> from <$> parseConnective1 Not
365+
"and" -> from <$> parseConnective2 And
366+
"or" -> from <$> parseConnective2 Or
367+
"implies" -> from <$> parseConnective2 Implies
368+
"iff" -> from <$> parseConnective2 Iff
373369
-- Quantifiers
374-
"exists" -> embedParsedPattern . ExistsF <$> parseQuantifier Exists
375-
"forall" -> embedParsedPattern . ForallF <$> parseQuantifier Forall
370+
"exists" -> from <$> parseQuantifier Exists
371+
"forall" -> from <$> parseQuantifier Forall
376372
-- Fixpoints
377-
"mu" -> embedParsedPattern . MuF <$> parseFixpoint Mu
378-
"nu" -> embedParsedPattern . NuF <$> parseFixpoint Nu
373+
"mu" -> from <$> parseFixpoint Mu
374+
"nu" -> from <$> parseFixpoint Nu
379375
-- Predicates
380-
"ceil" -> embedParsedPattern . CeilF <$> parsePredicate1 Ceil
381-
"floor" -> embedParsedPattern . FloorF <$> parsePredicate1 Floor
382-
"equals" -> embedParsedPattern . EqualsF <$> parsePredicate2 Equals
383-
"in" -> embedParsedPattern . InF <$> parsePredicate2 In
376+
"ceil" -> from <$> parsePredicate1 Ceil
377+
"floor" -> from <$> parsePredicate1 Floor
378+
"equals" -> from <$> parsePredicate2 Equals
379+
"in" -> from <$> parsePredicate2 In
384380
-- Rewriting
385-
"next" -> embedParsedPattern . NextF <$> parseConnective1 Next
386-
"rewrites" -> embedParsedPattern . RewritesF <$> parseConnective2 Rewrites
381+
"next" -> from <$> parseConnective1 Next
382+
"rewrites" -> from <$> parseConnective2 Rewrites
387383
-- Values
388-
"dv" -> embedParsedPattern . DomainValueF <$> parseDomainValue
384+
"dv" -> from <$> parseDomainValue
389385
-- Syntax sugar
390386
"left-assoc" -> parseLeftAssoc
391387
"right-assoc" -> parseRightAssoc
@@ -403,7 +399,7 @@ getSpecialId Id { getId } = do
403399
_ ::= _ "{" ⟨sort⟩ "}" "(" ")"
404400
@
405401
-}
406-
parseConnective0 :: (Sort -> result) -> Parser result
402+
parseConnective0 :: (Sort -> f ParsedPattern) -> Parser (f ParsedPattern)
407403
parseConnective0 mkResult = do
408404
sort <- braces parseSort
409405
() <- parens $ pure ()

0 commit comments

Comments
 (0)