Adjusted the parsers to store a type with array constructors (Rain will infer it later, so it uses Any)

This commit is contained in:
Neil Brown 2008-03-19 13:22:35 +00:00
parent 7baeb318f2
commit a930e17f89
3 changed files with 10 additions and 5 deletions

View File

@ -936,7 +936,11 @@ arrayConstructor
e <- inTypeContext subCtx expression
scopeOutRep r'
sRight
return $ A.ExprConstr m $ A.RepConstr m r' e
innerT <- typeOfExpression e
let t = case ctx of
Just t -> t
Nothing -> A.Array [A.UnknownDimension] innerT
return $ A.ExprConstr m $ A.RepConstr m t r' e
<?> "array constructor expression"
associativeOpExpression :: OccParser A.Expression

View File

@ -215,7 +215,8 @@ literal = do {(lr, dim) <- stringLiteral ; return $ A.Literal (findMeta lr) (A.L
<?> "literal"
range :: RainParser A.Expression
range = try $ do {m <- sLeftQ ; begin <- integerLiteral; sDots ; end <- integerLiteral ; sRightQ ; return $ A.ExprConstr m $ A.RangeConstr m begin end}
range = try $ do {m <- sLeftQ ; begin <- integerLiteral; sDots ; end <- integerLiteral ;
sRightQ ; return $ A.ExprConstr m $ A.RangeConstr m A.Any begin end}
expression :: RainParser A.Expression
expression

View File

@ -255,11 +255,11 @@ testRange :: [ParseTest A.Expression]
testRange =
[
pass("[0..1]", RP.expression, assertPatternMatch "testRange 0" $ pat $
A.ExprConstr m $ A.RangeConstr m (intLiteral 0) (intLiteral 1))
A.ExprConstr m $ A.RangeConstr m A.Any (intLiteral 0) (intLiteral 1))
,pass("[0..10000]", RP.expression, assertPatternMatch "testRange 1" $ pat $
A.ExprConstr m $ A.RangeConstr m (intLiteral 0) (intLiteral 10000))
A.ExprConstr m $ A.RangeConstr m A.Any (intLiteral 0) (intLiteral 10000))
,pass("[-3..-1]", RP.expression, assertPatternMatch "testRange 2" $ pat $
A.ExprConstr m $ A.RangeConstr m (intLiteral $ -3) (intLiteral $ -1))
A.ExprConstr m $ A.RangeConstr m A.Any (intLiteral $ -3) (intLiteral $ -1))
--For now, at least, this should fail:
,fail("[0..x]", RP.expression)
]