Skip to content

Commit

Permalink
Fix bug in the parser (non invertable cases)
Browse files Browse the repository at this point in the history
  • Loading branch information
igormoreno committed Apr 5, 2024
1 parent ffa4455 commit ca0e99b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,10 @@ instance Pretty Type where
TyFun t1 t2 -> hsep [p t1, "->", pretty t2]
TyTuple ts -> encloseSep lbrace rbrace comma (map pretty ts)
TyVar name -> pretty name
where p = parenIf $ \case TyFun {} -> True
TyRef {} -> True
_ -> False
where p = parenIf $ \case TyFun {} -> True
TyRef {} -> True
TyArray {} -> True
_ -> False

parenIf :: Pretty a => (a -> Bool) -> a -> Doc b
parenIf f t = (if f t then parens else id) (pretty t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ langDef = Tok.LanguageDef
, Tok.identLetter = alphaNum <|> oneOf "_'"
, Tok.opStart = oneOf ":!#$%&*+./<=>?@\\^|-~;"
, Tok.opLetter = oneOf ":!#$%&*+./<=>?@\\^|-~;"
, Tok.reservedNames = ["if", "then", "else", "true", "false", "succ",
"pred", "iszero", "unit", "Bool", "Nat", "array", "null"]
, Tok.reservedNames = ["if", "then", "else", "true", "false",
"succ", "pred", "iszero",
"Bool", "Nat",
"unit", "Unit",
"ref", "Ref",
"array", "Array",
"null", "NullType"]
, Tok.reservedOpNames = []
, Tok.caseSensitive = True
}
Expand Down Expand Up @@ -101,7 +106,7 @@ pTerm = Ex.buildExpressionParser table factor
, Ex.Prefix (IsZero <$ reserved "iszero")
, Ex.Prefix (Ref <$ reserved "ref") ]
, [ Ex.Infix (App <$ reservedOp "") Ex.AssocLeft ]
, [ Ex.Infix (ArrayAccess <$ reservedOp "|") Ex.AssocLeft ]
, [ Ex.Infix (ArrayAccess <$ reservedOp "|") Ex.AssocLeft ]
, [ Ex.Infix (Assign <$ reservedOp ":=") Ex.AssocRight ]
, [ Ex.Infix (Seq <$ reservedOp ";") Ex.AssocRight ] ]

Expand All @@ -111,13 +116,14 @@ pTypAtom :: Parser Type
pTypAtom = TyBool <$ reserved "Bool"
<|> TyNat <$ reserved "Nat"
<|> TyUnit <$ reserved "Unit"
<|> TyNull <$ reserved "NullType"
<|> TyTuple <$> braces (commaSep pTyp)
<|> parens pTyp

pTyp :: Parser Type
pTyp = Ex.buildExpressionParser table pTypAtom
where table = [ [ Ex.Infix (TyFun <$ reservedOp "->") Ex.AssocRight
, Ex.Prefix (TyRef <$ reserved "Ref")
where table = [ [ Ex.Infix (TyFun <$ reservedOp "->") Ex.AssocRight
, Ex.Prefix (TyRef <$ reserved "Ref")
, Ex.Prefix (TyArray <$ reserved "Array") ] ]

decToPeano :: Integer -> Term
Expand Down

0 comments on commit ca0e99b

Please sign in to comment.