Example #1
0
        private static CSharpSyntaxNode Parse(string input, ParseExpressionVisitor visitor)
        {
            using (var stream = new StringReader(input))
            {
                var inputStream = new AntlrInputStream(stream);

                var lexer             = new DonatelloLexer(inputStream);
                var commonTokenStream = new CommonTokenStream(lexer);
                var parser            = new DonatelloParser(commonTokenStream);
                var file = parser.file();

                return(visitor.Visit(file));
            }
        }
Example #2
0
        /// <summary>
        /// Use ANTLR4 and the associated visitor implementation to produce a roslyn AST
        /// </summary>
        public static CompilationUnitSyntax ParseAsClass(string input, string namespaceName, string className, string mainMethodName = null)
        {
            var visitor = new ParseExpressionVisitor(namespaceName, className, mainMethodName);

            return(Parse(input, visitor) as CompilationUnitSyntax);
        }
Example #3
0
        /// <summary>
        /// Use ANTLR4 and the associated visitor implementation to produce a roslyn AST
        /// </summary>
        public static CSharpSyntaxNode ParseAsRepl(string input)
        {
            var visitor = new ParseExpressionVisitor(repl: true);

            return(Parse(input, visitor));
        }