예제 #1
0
        static public ParserNode Parse(string data, ParserType parserType, bool strict)
        {
            switch (parserType)
            {
            case ParserType.Balanced: return(BalancedVisitor.Parse(data, strict));

            case ParserType.Columns: return(ColumnsVisitor.Parse(data, strict));

            case ParserType.CSharp: return(CSharpVisitor.Parse(data, strict));

            case ParserType.CSV: return(CSVVisitor.Parse(data, strict));

            case ParserType.ExactColumns: return(ExactColumnsVisitor.Parse(data, strict));

            case ParserType.HTML: return(HTMLVisitor.Parse(data, strict));

            case ParserType.JSON: return(JSONVisitor.Parse(data, strict));

            case ParserType.SQL: return(SQLVisitor.Parse(data, strict));

            case ParserType.TSV: return(TSVVisitor.Parse(data, strict));

            case ParserType.XML: return(XMLVisitor.Parse(data, strict));

            default: throw new ArgumentException("Unable to parse this type");
            }
        }
예제 #2
0
        static public string Reformat(ParserNode node, string input, ParserType parserType)
        {
            switch (parserType)
            {
            case ParserType.HTML: return(HTMLVisitor.Format(node, input));

            case ParserType.JSON: return(JSONVisitor.Format(node, input));

            case ParserType.XML: return(XMLVisitor.Format(node, input));

            default: throw new Exception("Unable to reformat this type");
            }
        }
예제 #3
0
        static internal string Uncomment(ParserType type, TextData data, Range range)
        {
            switch (type)
            {
            case ParserType.CSharp: return(CSharpVisitor.Uncomment(data, range));

            case ParserType.HTML:
            case ParserType.XML:
                return(HTMLVisitor.Uncomment(data, range));

            default: throw new Exception("Cannot comment this content type");
            }
        }
예제 #4
0
        public void VisitorTest()
        {
            try
            {
                string        input = "<html><title>blahg blah blah</title><p>para graph</p><p>second para</p></html>";
                StringBuilder text  = new StringBuilder(input);

                Console.WriteLine(input);

                var inputStream       = new AntlrInputStream(text.ToString());
                var htmlLexer         = new HTMLLexer(inputStream);
                var commonTokenStream = new CommonTokenStream(htmlLexer);
                var htmlParser        = new HTMLParser(commonTokenStream);
                var htmlContext       = htmlParser.htmlDocument();
                var visitor           = new HTMLVisitor();
                visitor.Visit(htmlContext);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex);
            }
        }