Esempio n. 1
0
        /// <summary>
        /// Parse LG content and achieve the AST.
        /// </summary>
        /// <param name="resource">LG resource.</param>
        /// <returns>The abstract syntax tree of lg file.</returns>
        public static IParseTree AntlrParseTemplates(LGResource resource)
        {
            if (string.IsNullOrEmpty(resource.Content))
            {
                return(null);
            }

            var input = new AntlrInputStream(resource.Content);
            var lexer = new LGFileLexer(input);

            lexer.RemoveErrorListeners();

            var tokens = new CommonTokenStream(lexer);
            var parser = new LGFileParser(tokens);

            parser.RemoveErrorListeners();
            var listener = new ErrorListener(resource.FullName);

            parser.AddErrorListener(listener);
            parser.BuildParseTree = true;

            return(parser.file());
        }
        private static IParseTree AntlrParseTemplates(string text, string id)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            var input = new AntlrInputStream(text);
            var lexer = new LGFileLexer(input);

            lexer.RemoveErrorListeners();

            var tokens = new CommonTokenStream(lexer);
            var parser = new LGFileParser(tokens);

            parser.RemoveErrorListeners();
            var listener = new ErrorListener(id);

            parser.AddErrorListener(listener);
            parser.BuildParseTree = true;

            return(parser.file());
        }