コード例 #1
0
        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);
        }
コード例 #2
0
        public static IReadOnlyList <SyntaxToken> ParseAllTokens(SourceFile file, IIncludeFileSystem fileSystem = null)
        {
            var tokens = new List <SyntaxToken>();

            var         lexer = new HlslLexer(file, includeFileSystem: fileSystem);
            SyntaxToken token;

            do
            {
                tokens.Add(token = lexer.Lex(LexerMode.Syntax));
            } while (token.Kind != SyntaxKind.EndOfFileToken);

            return(tokens);
        }
コード例 #3
0
        private void CreatesAst(string source)
        {
            //ANTLRFileStream fStream = new ANTLRFileStream(source, Encoding.ASCII);
            ANTLRStringStream stream = new ANTLRStringStream(source);
            HlslLexer         lexer  = new HlslLexer(stream);
            HlslParser        parser = new HlslParser(new CommonTokenStream(lexer));

            parser.GlobalScope = _globalScope;
            var program = parser.Program();

            _programs.Add(program);

            if (parser.Errors.Count > 0)
            {
                foreach (var item in parser.Errors)
                {
                    _log.Error(item.Message, item.Line, item.CharPositionInLine);
                }
                return;
            }
        }