Skip to content

Commit 7e0553f

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

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

kore/src/Kore/Parser/Parser.hs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,15 @@ 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)
151-
parseLiteral =
152-
(StringLiteralF . Const <$> parseStringLiteral)
153-
<?> "string literal"
150+
parseLiteral :: Parser ParsedPattern
151+
parseLiteral = (from <$> parseStringLiteral) <?> "string literal"
154152

155153
parseVariable :: Parser (SomeVariable VariableName)
156154
parseVariable = do
@@ -176,8 +174,7 @@ parseVariableRemainder identifier = do
176174
-- variable, not a symbol, and now we will validate it as a variable name.
177175
variableName <- getSomeVariableName identifier
178176
variableSort <- parseSort
179-
(pure . embedParsedPattern . VariableF . Const)
180-
Variable { variableName, variableSort }
177+
(pure . from) Variable { variableName, variableSort }
181178

182179
getSomeVariableName :: Id -> Parser (SomeVariableName VariableName)
183180
getSomeVariableName identifier =
@@ -258,8 +255,7 @@ parseApplicationRemainder :: Id -> Parser ParsedPattern
258255
parseApplicationRemainder identifier = do
259256
applicationSymbolOrAlias <- parseSymbolOrAliasRemainder identifier
260257
applicationChildren <- parens . list $ parsePattern
261-
(pure . embedParsedPattern . ApplicationF)
262-
Application { applicationSymbolOrAlias, applicationChildren }
258+
(pure . from) Application { applicationSymbolOrAlias, applicationChildren }
263259

264260
{- | Parse the tail of a 'SymbolOrAlias', after the @Id@.
265261
@@ -311,9 +307,7 @@ parseAssoc foldAssoc = do
311307
braces $ pure ()
312308
application <- parens $ parseApplication parsePattern
313309
let mkApplication child1 child2 =
314-
application { applicationChildren = [child1, child2] }
315-
& ApplicationF
316-
& embedParsedPattern
310+
from application { applicationChildren = [child1, child2] }
317311
case applicationChildren application of
318312
[] -> fail "expected one or more arguments"
319313
children -> pure (foldAssoc mkApplication children)
@@ -363,29 +357,29 @@ parseKoreRemainder :: Id -> Parser ParsedPattern
363357
parseKoreRemainder identifier =
364358
getSpecialId identifier >>= \case
365359
-- 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
360+
"top" -> from <$> parseConnective0 Top
361+
"bottom" -> from <$> parseConnective0 Bottom
362+
"not" -> from <$> parseConnective1 Not
363+
"and" -> from <$> parseConnective2 And
364+
"or" -> from <$> parseConnective2 Or
365+
"implies" -> from <$> parseConnective2 Implies
366+
"iff" -> from <$> parseConnective2 Iff
373367
-- Quantifiers
374-
"exists" -> embedParsedPattern . ExistsF <$> parseQuantifier Exists
375-
"forall" -> embedParsedPattern . ForallF <$> parseQuantifier Forall
368+
"exists" -> from <$> parseQuantifier Exists
369+
"forall" -> from <$> parseQuantifier Forall
376370
-- Fixpoints
377-
"mu" -> embedParsedPattern . MuF <$> parseFixpoint Mu
378-
"nu" -> embedParsedPattern . NuF <$> parseFixpoint Nu
371+
"mu" -> from <$> parseFixpoint Mu
372+
"nu" -> from <$> parseFixpoint Nu
379373
-- 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
374+
"ceil" -> from <$> parsePredicate1 Ceil
375+
"floor" -> from <$> parsePredicate1 Floor
376+
"equals" -> from <$> parsePredicate2 Equals
377+
"in" -> from <$> parsePredicate2 In
384378
-- Rewriting
385-
"next" -> embedParsedPattern . NextF <$> parseConnective1 Next
386-
"rewrites" -> embedParsedPattern . RewritesF <$> parseConnective2 Rewrites
379+
"next" -> from <$> parseConnective1 Next
380+
"rewrites" -> from <$> parseConnective2 Rewrites
387381
-- Values
388-
"dv" -> embedParsedPattern . DomainValueF <$> parseDomainValue
382+
"dv" -> from <$> parseDomainValue
389383
-- Syntax sugar
390384
"left-assoc" -> parseLeftAssoc
391385
"right-assoc" -> parseRightAssoc
@@ -403,7 +397,7 @@ getSpecialId Id { getId } = do
403397
_ ::= _ "{" ⟨sort⟩ "}" "(" ")"
404398
@
405399
-}
406-
parseConnective0 :: (Sort -> result) -> Parser result
400+
parseConnective0 :: (Sort -> f ParsedPattern) -> Parser (f ParsedPattern)
407401
parseConnective0 mkResult = do
408402
sort <- braces parseSort
409403
() <- parens $ pure ()

0 commit comments

Comments
 (0)