Skip to content

Commit ca0e99b

Browse files
committed
Fix bug in the parser (non invertable cases)
1 parent ffa4455 commit ca0e99b

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

notional-machines/src/NotionalMachines/Lang/TypedLambdaArray/AbstractSyntax.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,9 +574,10 @@ instance Pretty Type where
574574
TyFun t1 t2 -> hsep [p t1, "->", pretty t2]
575575
TyTuple ts -> encloseSep lbrace rbrace comma (map pretty ts)
576576
TyVar name -> pretty name
577-
where p = parenIf $ \case TyFun {} -> True
578-
TyRef {} -> True
579-
_ -> False
577+
where p = parenIf $ \case TyFun {} -> True
578+
TyRef {} -> True
579+
TyArray {} -> True
580+
_ -> False
580581

581582
parenIf :: Pretty a => (a -> Bool) -> a -> Doc b
582583
parenIf f t = (if f t then parens else id) (pretty t)

notional-machines/src/NotionalMachines/Lang/TypedLambdaArray/ParserUnparser.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ langDef = Tok.LanguageDef
3232
, Tok.identLetter = alphaNum <|> oneOf "_'"
3333
, Tok.opStart = oneOf ":!#$%&*+./<=>?@\\^|-~;"
3434
, Tok.opLetter = oneOf ":!#$%&*+./<=>?@\\^|-~;"
35-
, Tok.reservedNames = ["if", "then", "else", "true", "false", "succ",
36-
"pred", "iszero", "unit", "Bool", "Nat", "array", "null"]
35+
, Tok.reservedNames = ["if", "then", "else", "true", "false",
36+
"succ", "pred", "iszero",
37+
"Bool", "Nat",
38+
"unit", "Unit",
39+
"ref", "Ref",
40+
"array", "Array",
41+
"null", "NullType"]
3742
, Tok.reservedOpNames = []
3843
, Tok.caseSensitive = True
3944
}
@@ -101,7 +106,7 @@ pTerm = Ex.buildExpressionParser table factor
101106
, Ex.Prefix (IsZero <$ reserved "iszero")
102107
, Ex.Prefix (Ref <$ reserved "ref") ]
103108
, [ Ex.Infix (App <$ reservedOp "") Ex.AssocLeft ]
104-
, [ Ex.Infix (ArrayAccess <$ reservedOp "|") Ex.AssocLeft ]
109+
, [ Ex.Infix (ArrayAccess <$ reservedOp "|") Ex.AssocLeft ]
105110
, [ Ex.Infix (Assign <$ reservedOp ":=") Ex.AssocRight ]
106111
, [ Ex.Infix (Seq <$ reservedOp ";") Ex.AssocRight ] ]
107112

@@ -111,13 +116,14 @@ pTypAtom :: Parser Type
111116
pTypAtom = TyBool <$ reserved "Bool"
112117
<|> TyNat <$ reserved "Nat"
113118
<|> TyUnit <$ reserved "Unit"
119+
<|> TyNull <$ reserved "NullType"
114120
<|> TyTuple <$> braces (commaSep pTyp)
115121
<|> parens pTyp
116122

117123
pTyp :: Parser Type
118124
pTyp = Ex.buildExpressionParser table pTypAtom
119-
where table = [ [ Ex.Infix (TyFun <$ reservedOp "->") Ex.AssocRight
120-
, Ex.Prefix (TyRef <$ reserved "Ref")
125+
where table = [ [ Ex.Infix (TyFun <$ reservedOp "->") Ex.AssocRight
126+
, Ex.Prefix (TyRef <$ reserved "Ref")
121127
, Ex.Prefix (TyArray <$ reserved "Array") ] ]
122128

123129
decToPeano :: Integer -> Term

0 commit comments

Comments
 (0)