Beispiel #1
0
        public static SyntaxTree GetSyntaxTree(this ITextSnapshot snapshot, CancellationToken cancellationToken)
        {
            var sourceText = new VisualStudioSourceText(snapshot);

            var options = new ParserOptions();
            options.PreprocessorDefines.Add("__INTELLISENSE__");

            var fileSystem = snapshot.TextBuffer.GetIncludeFileSystem();

            return SyntaxFactory.ParseSyntaxTree(sourceText, options, fileSystem, cancellationToken);
        }
        private static SyntaxTree Parse(SourceText sourceText, ParserOptions options, IIncludeFileSystem fileSystem, Func<HlslParser, SyntaxNode> parseFunc)
        {
            var lexer = new HlslLexer(sourceText, options, fileSystem);
            var parser = new HlslParser(lexer);

            var result = new SyntaxTree(sourceText,
                syntaxTree => new Tuple<SyntaxNode, List<FileSegment>>(
                    parseFunc(parser),
                    lexer.FileSegments));

            Debug.WriteLine(DateTime.Now +  " - Finished parsing");

            return result;
        }
Beispiel #3
0
        public static SyntaxTree GetSyntaxTree(this ITextSnapshot snapshot, VisualStudioSourceTextFactory sourceTextFactory, CancellationToken cancellationToken)
        {
            return CachedSyntaxTrees.GetValue(snapshot, key =>
            {
                var sourceText = key.ToSourceText();

                var options = new ParserOptions();
                options.PreprocessorDefines.Add("__INTELLISENSE__");

                var fileSystem = key.TextBuffer.GetIncludeFileSystem(sourceTextFactory);

                return SyntaxFactory.ParseSyntaxTree(sourceText, options, fileSystem, cancellationToken);
            });
        }
Beispiel #4
0
        public static SyntaxTree GetSyntaxTree(this ITextSnapshot snapshot, CancellationToken cancellationToken)
        {
            return CachedSyntaxTrees.GetValue(snapshot, key =>
            {
                var sourceText = key.ToSourceText();

                var options = new ParserOptions();
                options.PreprocessorDefines.Add("__INTELLISENSE__");

                var sourceTextFactory = VisualStudioSourceTextFactory.Instance ?? HlslToolsPackage.Instance.AsVsServiceProvider().GetComponentModel().GetService<VisualStudioSourceTextFactory>();
                var fileSystem = key.TextBuffer.GetIncludeFileSystem(sourceTextFactory);

                return SyntaxFactory.ParseSyntaxTree(sourceText, options, fileSystem, cancellationToken);
            });
        }
Beispiel #5
0
        public HlslLexer(SourceText text, ParserOptions options = null, IIncludeFileSystem fileSystem = null)
        {
            _fileSystem = fileSystem ?? new DummyFileSystem();
            _directives = DirectiveStack.Empty;

            if (options != null)
                foreach (var define in options.PreprocessorDefines)
                {
                    _directives = _directives.Add(new Directive(new ObjectLikeDefineDirectiveTriviaSyntax(
                        null, null, SyntaxFactory.ParseToken(define), new List<SyntaxToken>
                        {
                            SyntaxFactory.ParseToken("1")
                        }, null, true)));
                }

            ExpandMacros = true;

            FileSegments = new List<FileSegment>();
            _includeStack = new Stack<IncludeContext>();
            PushIncludeContext(text);
        }
 public static SyntaxTree ParseSyntaxTree(SourceText sourceText, ParserOptions options = null, IIncludeFileSystem fileSystem = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return Parse(sourceText, options, fileSystem ?? new DummyFileSystem(), p => p.ParseCompilationUnit(cancellationToken));
 }