ShaderTools.Hlsl.Parser.DirectiveParser.ParseDirective C# (CSharp) Method

ParseDirective() public method

public ParseDirective ( bool isActive, bool endIsActive, bool isAfterNonWhitespaceOnLine ) : SyntaxNode
isActive bool
endIsActive bool
isAfterNonWhitespaceOnLine bool
return SyntaxNode
        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);
            }
        }

Usage Example

Exemplo n.º 1
0
        public HlslLexer(SourceText text, ParserOptions options = null, IIncludeFileSystem includeFileSystem = null)
        {
            _includeFileResolver = new IncludeFileResolver(includeFileSystem ?? new DummyFileSystem());
            _directives          = DirectiveStack.Empty;

            if (options != null)
            {
                foreach (var define in options.PreprocessorDefines)
                {
                    var lexer = new HlslLexer(
                        SourceText.From($"#define {define.Key} {define.Value}",
                                        "__ConfiguredPreprocessorDefinitions__.hlsl"));
                    lexer._mode        = LexerMode.Directive;
                    lexer.ExpandMacros = false;

                    var dp        = new DirectiveParser(lexer, _directives);
                    var directive = dp.ParseDirective(true, true, false);
                    _directives = directive.ApplyDirectives(_directives);
                }
            }

            _options = options ?? new ParserOptions();

            ExpandMacros = true;

            _rootText = text;

            FileSegments  = new List <FileSegment>();
            _includeStack = new Stack <IncludeContext>();
            PushIncludeContext(text);
        }
All Usage Examples Of ShaderTools.Hlsl.Parser.DirectiveParser::ParseDirective