Exemplo n.º 1
0
        public static IReadOnlyList <SyntaxToken> ParseAllTokens(SourceText sourceText)
        {
            var tokens = new List <SyntaxToken>();

            var pretokenizer       = new UnityPretokenizer(sourceText);
            var pretokenizedTokens = pretokenizer.GetTokens();

            var         lexer = new UnityLexer(sourceText, pretokenizedTokens);
            SyntaxToken token;

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

            return(tokens);
        }
Exemplo n.º 2
0
        private static SyntaxTree Parse(SourceText sourceText, Func <UnityParser, SyntaxNode> parseFunc)
        {
            var pretokenizer       = new UnityPretokenizer(sourceText);
            var pretokenizedTokens = pretokenizer.GetTokens();

            var lexer  = new UnityLexer(sourceText, pretokenizedTokens);
            var parser = new UnityParser(lexer);

            var result = new SyntaxTree(sourceText,
                                        syntaxTree =>
            {
                var node = parseFunc(parser);
                node.SetSyntaxTree(syntaxTree);
                return(node);
            });

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

            return(result);
        }