public SyntaxNode ParseDirective(bool isActive, bool endIsActive, bool isAfterNonWhitespaceOnLine)
{
var hash = Match(SyntaxKind.HashToken);
if (isAfterNonWhitespaceOnLine)
hash = WithDiagnostic(hash, DiagnosticId.BadDirectivePlacement);
switch (Current.ContextualKind)
{
case SyntaxKind.IfKeyword:
return ParseIfDirective(hash, MatchContextual(SyntaxKind.IfKeyword), isActive);
case SyntaxKind.IfDefKeyword:
return ParseIfDefDirective(hash, MatchContextual(SyntaxKind.IfDefKeyword), isActive);
case SyntaxKind.IfNDefKeyword:
return ParseIfNDefDirective(hash, MatchContextual(SyntaxKind.IfNDefKeyword), isActive);
case SyntaxKind.ElseKeyword:
return ParseElseDirective(hash, MatchContextual(SyntaxKind.ElseKeyword), isActive, endIsActive);
case SyntaxKind.ElifKeyword:
return ParseElifDirective(hash, MatchContextual(SyntaxKind.ElifKeyword), isActive, endIsActive);
case SyntaxKind.EndIfKeyword:
return ParseEndIfDirective(hash, MatchContextual(SyntaxKind.EndIfKeyword), isActive, endIsActive);
case SyntaxKind.DefineKeyword:
return ParseDefineDirective(hash, MatchContextual(SyntaxKind.DefineKeyword), isActive);
case SyntaxKind.UndefKeyword:
return ParseUndefDirective(hash, MatchContextual(SyntaxKind.UndefKeyword), isActive);
case SyntaxKind.IncludeKeyword:
return ParseIncludeDirective(hash, MatchContextual(SyntaxKind.IncludeKeyword), isActive);
case SyntaxKind.LineKeyword:
return ParseLineDirective(hash, MatchContextual(SyntaxKind.LineKeyword), isActive);
case SyntaxKind.ErrorKeyword:
return ParseErrorDirective(hash, MatchContextual(SyntaxKind.ErrorKeyword), isActive);
case SyntaxKind.PragmaKeyword:
return ParsePragmaDirective(hash, MatchContextual(SyntaxKind.PragmaKeyword), isActive);
default:
var id = Match(SyntaxKind.IdentifierToken);
var end = ParseEndOfDirective(ignoreErrors: true);
if (!isAfterNonWhitespaceOnLine)
{
if (!id.IsMissing)
id = WithDiagnostic(id, DiagnosticId.DirectiveExpected);
else
hash = WithDiagnostic(hash, DiagnosticId.DirectiveExpected);
}
return new BadDirectiveTriviaSyntax(hash, id, end, isActive);
}
}