Skip to content

Commit

Permalink
Try to not raise copy code parameter relacted diagnostics within a co…
Browse files Browse the repository at this point in the history
…py code
  • Loading branch information
MarkusAmshove committed Nov 14, 2023
1 parent b13f1db commit 0ccb2c1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,17 @@ protected void report(IDiagnostic diagnostic)
{
if (diagnostic != null)
{
if (!shouldRelocateDiagnostics() && diagnostic.fileType() == NaturalFileType.COPYCODE)
{
var prev = previousToken();
if (prev != null && prev.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// Do not raise diagnostics in copy codes. They can only be properly analyzed through
// INCLUDE in a proper module
return;
}
}

if (shouldRelocateDiagnostics() && diagnostic instanceof ParserDiagnostic parserDiagnostic)
{
diagnostics.add(parserDiagnostic.relocate(relocatedDiagnosticPosition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public static ParserDiagnostic unexpectedToken(SyntaxKind expectedToken, TokenLi
{
var currentToken = tokens.peek();
var invalidToken = currentToken != null ? currentToken : tokens.peek(-1);
if (invalidToken.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// We're most likely inside a copy code, so the diagnostic doesn't make sense
return null;
}
var message = currentToken != null ? "Unexpected token <%s>, expected <%s>".formatted(formatTokenKind(invalidToken), expectedToken) : "Unexpected token after this, expected <%s>".formatted(expectedToken);
return ParserDiagnostic.create(
message,
Expand All @@ -80,6 +85,11 @@ public static ParserDiagnostic unexpectedToken(Collection<SyntaxKind> expectedTo
var invalidToken = currentToken != null ? currentToken : tokens.peek(-1);
var expectedTokens = expectedTokenKinds.stream().map(Enum::toString).collect(Collectors.joining(", "));
var message = currentToken != null ? "Unexpected token <%s>, expected one of <%s>".formatted(formatTokenKind(invalidToken), expectedTokens) : "Unexpected token after this, expected one of <%s>".formatted(expectedTokens);
if (invalidToken.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// We're most likely inside a copy code, so the diagnostic doesn't make sense
return null;
}
return ParserDiagnostic.create(
message,
invalidToken,
Expand Down Expand Up @@ -446,6 +456,11 @@ public static IDiagnostic invalidMaskOrScanComparisonOperator(SyntaxToken maskTo

public static IDiagnostic unexpectedToken(SyntaxToken wrongToken, String message)
{
if (wrongToken.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// We're most likely inside a copy code, so the diagnostic doesn't make sense
return null;
}
return ParserDiagnostic.create(
message,
wrongToken,
Expand Down Expand Up @@ -617,17 +632,13 @@ public static IDiagnostic groupHasMixedConstVariables(ISyntaxNode variable)
);
}

public static IDiagnostic cyclomaticInclude(SyntaxToken referencingToken)
{
return ParserDiagnostic.create(
"Cyclomatic INCLUDE found. %s is recursively included multiple times.".formatted(referencingToken.symbolName()),
referencingToken,
ParserError.CYCLOMATIC_INCLUDE
);
}

public static IDiagnostic unexpectedTokenWhenIdentifierWasExpected(SyntaxToken token)
{
if (token.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// We're most likely inside a copy code, so the diagnostic doesn't make sense
return null;
}
return ParserDiagnostic.create(
"Identifier expected, but got %s".formatted(token.kind()),
token,
Expand All @@ -637,6 +648,11 @@ public static IDiagnostic unexpectedTokenWhenIdentifierWasExpected(SyntaxToken t

public static IDiagnostic operandExpected(SyntaxToken token)
{
if (token.kind() == SyntaxKind.COPYCODE_PARAMETER)
{
// We're most likely inside a copy code, so the diagnostic doesn't make sense
return null;
}
return ParserDiagnostic.create(
"Expected operand, but got %s".formatted(token.kind()),
token,
Expand Down

0 comments on commit 0ccb2c1

Please sign in to comment.