Skip to content

Commit

Permalink
Allow EM, HD and PM on view variables without type (#539)
Browse files Browse the repository at this point in the history
fixes #538
  • Loading branch information
MarkusAmshove authored Dec 30, 2024
1 parent cd46f29 commit bed03d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ private VariableNode variable(GroupNode enclosingGroup) throws ParseError
return typedDdmArrayVariable;
}

if (peekKind(SyntaxKind.EM) || peekKind(SyntaxKind.HD) || peekKind(SyntaxKind.PM))
{
consumeEmHdPm(variable);
// The parens we're in is for attributes, not the type, so the type has to be inferred from the DDM.
return typedVariableFromDdm(variable, enclosingGroup);
}

return typedVariable(variable);
}

Expand All @@ -122,6 +129,15 @@ private VariableNode variable(GroupNode enclosingGroup) throws ParseError
return typedVariableFromDdm(variable, enclosingGroup);
}

private void consumeEmHdPm(VariableNode variable) throws ParseError
{
while (!isAtEnd() && !peekKind(SyntaxKind.RPAREN) && !peekKind(SyntaxKind.END_DEFINE))
{
consume(variable);
}
consumeMandatory(variable, SyntaxKind.RPAREN);
}

private TypedVariableNode typedVariable(VariableNode variable) throws ParseError
{
var typedVariable = new TypedVariableNode(variable);
Expand Down Expand Up @@ -174,14 +190,10 @@ private TypedVariableNode typedVariable(VariableNode variable) throws ParseError
type.setDynamicLength();
}

// Consume optional emhdpm
// Consume optional EMHDPM
if (consumeOptionally(typedVariable, SyntaxKind.LPAREN))
{
while (!isAtEnd() && peek().kind() != SyntaxKind.RPAREN && peek().kind() != SyntaxKind.END_DEFINE)
{
consume(typedVariable);
}
consumeMandatory(typedVariable, SyntaxKind.RPAREN);
consumeEmHdPm(typedVariable);
}

typedVariable.setType(type);
Expand Down Expand Up @@ -239,7 +251,7 @@ private GroupNode group(VariableNode variable) throws ParseError

// This is used when there is no type specified in the view.
// Type is loaded from DDM.
private VariableNode typedVariableFromDdm(VariableNode variable, GroupNode enclosingGroup)
private VariableNode typedVariableFromDdm(VariableNode variable, GroupNode enclosingGroup) throws ParseError
{
// unresolved DDM
if (view.ddm() == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,19 @@ void allowEmHdPmInViews()
assertNodeType(view.variables().first(), IGroupNode.class);
}

@Test
void allowEmHdPmInViewVariablesWithoutExplicitType()
{
assertParsesWithoutDiagnostics("""
define data
local
1 myview view of myddm
2 withouttype (hd='Header')
2 withtype (n2) (hd='Header')
end-define
""");
}

@Test
void parseViewWithOptionalOf()
{
Expand Down

0 comments on commit bed03d8

Please sign in to comment.