Use newtypes to retain more information

This commit is contained in:
Samae 2023-12-02 18:09:32 +02:00
parent af7ebce206
commit 3ad26674d3

View file

@ -29,19 +29,19 @@ insuranceNetworkParser = many1 line
, INASTExprInsurerId <$> insurerId ] , INASTExprInsurerId <$> insurerId ]
-- <lesser-than> ::= "<" <integer> -- <lesser-than> ::= "<" <integer>
lt :: Parser INASTLt lt :: Parser INASTLt
lt = "<" *> integer lt = INASTLt <$> ("<" *> integer)
-- <greater-than> ::= ">" <integer> -- <greater-than> ::= ">" <integer>
gt :: Parser INASTGt gt :: Parser INASTGt
gt = ">" *> integer gt = INASTGt <$> (">" *> integer)
-- <equals> ::= "=" <integer> -- <equals> ::= "=" <integer>
eq :: Parser INASTEq eq :: Parser INASTEq
eq = "=" *> integer eq = INASTEq <$> ("=" *> integer)
-- <insurer-id> ::= "I" <integer> -- <insurer-id> ::= "I" <integer>
insurerId :: Parser INASTInsurerId insurerId :: Parser INASTInsurerId
insurerId = "I" *> integer insurerId = INASTInsurerId <$> ("I" *> integer)
-- <percent> ::= <integer> "%" -- <percent> ::= <integer> "%"
percent :: Parser INASTPercent percent :: Parser INASTPercent
percent = integer <* "%" percent = INASTPercent <$> integer <* "%"
-- <integer> ::= <digit> | <non-zero-digit> <integer> -- <integer> ::= <digit> | <non-zero-digit> <integer>
-- Overapproximation of the grammar -- Overapproximation of the grammar
integer :: Parser Int integer :: Parser Int
@ -58,8 +58,13 @@ data INASTExpr = INASTExprLt INASTLt
| INASTExprInsurerId INASTInsurerId | INASTExprInsurerId INASTInsurerId
deriving (Show) deriving (Show)
type INASTLt = Int newtype INASTLt = INASTLt Int
type INASTGt = Int deriving (Show)
type INASTEq = Int newtype INASTGt = INASTGt Int
type INASTInsurerId = Int deriving (Show)
type INASTPercent = Int newtype INASTEq = INASTEq Int
deriving (Show)
newtype INASTInsurerId = INASTInsurerId Int
deriving (Show)
newtype INASTPercent = INASTPercent Int
deriving (Show)