internal SyntaxTree(SourceFile file, HlslParseOptions options, Func <SyntaxTree, Tuple <SyntaxNode, List <FileSegment> > > parseFunc)
        {
            File    = file;
            Text    = file.Text;
            Options = options;

            var parsed = parseFunc(this);

            Root          = parsed.Item1;
            _fileSegments = parsed.Item2;
        }
        public void CanParseWithInvalidConfiguredPreprocessorDefinition()
        {
            var code    = @"
#if FOO == 1
float a;
#else
float b;
#endif";
            var options = new HlslParseOptions
            {
                PreprocessorDefines =
                {
                    { "FOO", "1 . % \\" }
                }
            };
            var syntaxTree = SyntaxFactory.ParseSyntaxTree(SourceText.From(code, "__Root__.hlsl"), options);

            Assert.Equal(1, syntaxTree.GetDiagnostics().Count());
        }
        public SyntaxTreeBase ParseSyntaxTree(SourceFile file, CancellationToken cancellationToken)
        {
            var configFile = _workspace.LoadConfigFile(file);

            var options = new HlslParseOptions();

            options.PreprocessorDefines.Add("__INTELLISENSE__", "1");

            foreach (var kvp in configFile.HlslPreprocessorDefinitions)
            {
                options.PreprocessorDefines.Add(kvp.Key, kvp.Value);
            }

            options.AdditionalIncludeDirectories.AddRange(configFile.HlslAdditionalIncludeDirectories);

            return(SyntaxFactory.ParseSyntaxTree(
                       file,
                       options,
                       _fileSystem,
                       cancellationToken));
        }
Beispiel #4
0
        private static SyntaxTree Parse(SourceFile sourceFile, HlslParseOptions options, IIncludeFileSystem fileSystem, Func <HlslParser, SyntaxNode> parseFunc)
        {
            var lexer  = new HlslLexer(sourceFile, options, fileSystem);
            var parser = new HlslParser(lexer);

            var result = new SyntaxTree(
                sourceFile,
                options,
                syntaxTree =>
            {
                var node = parseFunc(parser);
                node.SetSyntaxTree(syntaxTree);

                return(new Tuple <SyntaxNode, List <FileSegment> >(
                           node,
                           lexer.FileSegments));
            });

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

            return(result);
        }
        public void CanParseWithConfiguredPreprocessorDefinition()
        {
            var code    = @"
#if FOO == 1
float a;
#else
float b;
#endif";
            var options = new HlslParseOptions
            {
                PreprocessorDefines =
                {
                    { "FOO", "1" }
                }
            };
            var syntaxTree = SyntaxFactory.ParseSyntaxTree(SourceText.From(code, "__Root__.hlsl"), options);

            foreach (var diagnostic in syntaxTree.GetDiagnostics())
            {
                _output.WriteLine(diagnostic.ToString());
            }
            Assert.Empty(syntaxTree.GetDiagnostics());
        }
 public IncludeFileResolver(IIncludeFileSystem fileSystem, HlslParseOptions parserOptions)
 {
     _fileSystem    = fileSystem;
     _parserOptions = parserOptions;
 }
Beispiel #7
0
 internal static SyntaxTree ParseSyntaxTree(SourceText sourceText, HlslParseOptions options = null, IIncludeFileSystem fileSystem = null, CancellationToken cancellationToken = default)
 {
     return(ParseSyntaxTree(new SourceFile(sourceText), options, fileSystem, cancellationToken));
 }
Beispiel #8
0
 public static SyntaxTree ParseSyntaxTree(SourceFile file, HlslParseOptions options = null, IIncludeFileSystem fileSystem = null, CancellationToken cancellationToken = default)
 {
     return(Parse(file, options, fileSystem ?? new DummyFileSystem(), p => p.ParseCompilationUnit(cancellationToken)));
 }
Beispiel #9
0
 public static CompilationUnitSyntax ParseCompilationUnit(SourceFile file, HlslParseOptions options = null, IIncludeFileSystem fileSystem = null)
 {
     return((CompilationUnitSyntax)Parse(file, options, fileSystem, p => p.ParseCompilationUnit(CancellationToken.None)).Root);
 }