Skip to content

Commit

Permalink
Correct handling of discretionary "()" types
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Feb 25, 2019
1 parent 7d288a5 commit 9923f4c
Showing 1 changed file with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public TypeReader(LexTokenReader reader)

public PType readType() throws ParserException, LexException
{
PType type = readUnionType();
PType type = readDiscretionaryType();

if (lastToken().is(VDMToken.ARROW)
|| lastToken().is(VDMToken.TOTAL_FUNCTION))
Expand All @@ -67,16 +67,42 @@ public PType readType() throws ParserException, LexException
nextToken();
PType result = readType();

if (result instanceof AVoidType)
{
throwMessage(2070, "Function type cannot return void type");
}

type = AstFactory.newAFunctionType(token.location, token.is(VDMToken.ARROW), productExpand(type), result);
}
else if (type instanceof AVoidType)
{
throwMessage(2070, "Cannot use '()' type here");
}

return type;
}

private PType readDiscretionaryType()
throws ParserException, LexException
{
LexToken token = lastToken();
ILexLocation location = token.location;
PType type = null;

if (token.is(VDMToken.BRA))
{
reader.push();

if (nextToken().is(VDMToken.KET))
{
type = AstFactory.newAVoidType(location);
nextToken();
reader.unpush();
return type;
}
else
{
reader.pop();
}
}

return readUnionType();
}

private PType readUnionType() throws ParserException, LexException
{
Expand Down Expand Up @@ -345,15 +371,9 @@ private PType readBasicType() throws ParserException, LexException
break;

case BRA:
if (nextToken().is(VDMToken.KET))
{
type = AstFactory.newAVoidType(location);
nextToken();
} else
{
type = AstFactory.newABracketType(location, readType());
checkFor(VDMToken.KET, 2256, "Bracket mismatch");
}
nextToken();
type = AstFactory.newABracketType(location, readType());
checkFor(VDMToken.KET, 2256, "Bracket mismatch");
break;

case SEQ_OPEN:
Expand Down Expand Up @@ -393,10 +413,10 @@ private PType readBasicType() throws ParserException, LexException
public AOperationType readOperationType() throws ParserException,
LexException
{
PType paramtype = readType();
PType paramtype = readDiscretionaryType();
LexToken arrow = lastToken();
checkFor(VDMToken.OPDEF, 2258, "Expecting '==>' in explicit operation type");
PType resulttype = readType();
PType resulttype = readDiscretionaryType();
return AstFactory.newAOperationType(arrow.location, productExpand(paramtype), resulttype);
}

Expand Down

0 comments on commit 9923f4c

Please sign in to comment.