Example #1
0
        string[]  parse(string text)
        {
            AntlrInputStream  inputStream       = new AntlrInputStream(text);
            CSVLexer          lexer             = new CSVLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            CSVParser         parser            = new CSVParser(commonTokenStream);

            CSVParser.CsvFileContext csvCtx = parser.csvFile();
            CsvFileVisitor           v      = new CsvFileVisitor();

            return(v.getValues(csvCtx));
        }
Example #2
0
            public string[] getValues(CSVParser.CsvFileContext context)
            {
                CSVParser.RowContext[] rowContexts = context.row();

                string[] result = null;

                if (rowContexts.Length > 0)
                {
                    CSVParser.FieldContext[] fca = rowContexts[0].field();
                    result = new string[fca.Length];
                    int i = 0;
                    foreach (CSVParser.FieldContext fc in fca)
                    {
                        result[i++] = fc.GetText();
                    }
                }

                return(result);
            }
Example #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CSVParser.csvFile"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitCsvFile([NotNull] CSVParser.CsvFileContext context)
 {
 }
Example #4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CSVParser.csvFile"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitCsvFile([NotNull] CSVParser.CsvFileContext context)
 {
     return(VisitChildren(context));
 }