Beispiel #1
0
        internal SyntaxTree(SourceText text, Func<SyntaxTree, Tuple<SyntaxNode, List<FileSegment>>> parseFunc)
        {
            Text = text;

            var parsed = parseFunc(this);
            Root = parsed.Item1;
            _fileSegments = parsed.Item2;
        }
        public static IReadOnlyList<SyntaxToken> ParseAllTokens(SourceText sourceText, IIncludeFileSystem fileSystem = null)
        {
            var tokens = new List<SyntaxToken>();

            var lexer = new HlslLexer(sourceText, fileSystem: fileSystem);
            SyntaxToken token;
            do
            {
                tokens.Add(token = lexer.Lex(LexerMode.Syntax));
            } while (token.Kind != SyntaxKind.EndOfFileToken);

            return tokens;
        }
        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 #4
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));
 }
Beispiel #6
0
 public IncludeContext(SourceText text)
 {
     CharReader = new CharReader(text);
     Text = text;
 }
Beispiel #7
0
        private void PushIncludeContext(SourceText text)
        {
            _currentFileSegmentAbsolutePosition = FileSegments.Sum(x => x.Length);

            var includeContext = new IncludeContext(text);
            _includeStack.Push(includeContext);
            _charReader = includeContext.CharReader;
            FileSegments.Add(new FileSegment(text, 0));
        }
Beispiel #8
0
 public FileSegment(SourceText text, int start)
 {
     Text = text;
     Start = start;
 }
 private static IReadOnlyList<SyntaxToken> LexAllTokens(SourceText text, IIncludeFileSystem fileSystem = null)
 {
     return SyntaxFactory.ParseAllTokens(text, fileSystem);
 }
Beispiel #10
0
 public CharReader(SourceText text)
 {
     _text = text;
 }