Ejemplo n.º 1
0
        /// <summary>
        /// Parse supplied text using default settings.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public static List <List <string> > ParseTable(string line)
        {
            LexListSettings settings = new LexListSettings();

            settings.MultipleRecordsUsingNewLine = true;
            return(Parse(line, settings));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parse a non-quoted item e.g. 123 as opposed to "123"
        /// </summary>
        private void ParseNonQuotedItem(LexListSettings settings)
        {
            // Read non-quoted text until the separator char is hit.
            string item = ReadNonQuotedToken(_separatorMap, true);

            if (settings.TrimWhiteSpace)
            {
                item = item.Trim();
            }

            // Store the current list item.
            _tokenList.Add(item);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Check for and handle new line.
        /// </summary>
        /// <returns></returns>
        public bool CheckAndHandleNewLine(LexListSettings settings)
        {
            if (_reader.IsEol())
            {
                _reader.ConsumeNewLine();

                // Check if newline means start of new record.
                if (settings.MultipleRecordsUsingNewLine)
                {
                    _lines.Add(_tokenList);
                    _tokenList = new List <string>();
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Parse a quoted item. e.g. "batman"
        /// </summary>
        /// <param name="settings"></param>
        private void ParseQuotedItem(LexListSettings settings)
        {
            string quote = _reader.CurrentChar;
            string item  = ReadQuotedToken();

            if (settings.TrimWhiteSpace)
            {
                item = item.Trim();
            }

            // Store the current list item.
            _tokenList.Add(item);

            // Check that closing quote is present.
            if (Expect(quote))
            {
                _reader.ReadChar();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Create with supplied settings.
 /// </summary>
 /// <param name="settings"></param>
 public LexList(LexListSettings settings)
 {
     Init(settings);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Parse supplied text using supplied settings.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="settings"></param>
        /// <returns></returns>
        public static List <List <string> > Parse(string text, LexListSettings settings)
        {
            LexList lex = new LexList(settings);

            return(lex.ParseLines(text));
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Parse supplied text using supplied settings.
 /// </summary>
 /// <param name="line"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static List<List<string>> Parse(string text, LexListSettings settings)
 {
     LexList lex = new LexList(settings);
     return lex.ParseLines(text);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Parse
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public List <List <string> > ParseLines(string text)
        {
            // First cut of lex parser.
            // This needs to be handled differently and should allow whitespace to
            // be a separator.
            LexListSettings settings = _settings as LexListSettings;

            Reset(text);

            // Move to first char.
            _reader.ReadChar();

            // Get rid of initial whitespace.
            _reader.ConsumeWhiteSpace();

            while (!_reader.IsEnd())
            {
                if (_reader.IsWhiteSpace())
                {
                    _reader.ConsumeWhiteSpace();

                    // Continue check.
                    // The consuming of white space always leaves
                    // the reader at the beginning of a non-whitespace char.
                    continue;
                }
                // Check for quotes.
                else if (_reader.CurrentChar == "'" || _reader.CurrentChar == "\"")
                {
                    ParseQuotedItem(settings);
                }
                else
                {
                    ParseNonQuotedItem(settings);
                }

                // Check for and consume whitespace.
                CheckAndConsumeWhiteSpace();

                // Check for comma and consume it.
                CheckAndHandleComma();

                // Consume whitespace
                CheckAndConsumeWhiteSpace();

                // Handle new lines and whether to store
                // next line as another record.
                if (!CheckAndHandleNewLine(settings))
                {
                    // Now read next char
                    _reader.ReadChar();
                }
            }

            // Handle errors.
            CheckAndThrowErrors();

            // Token list always gets reset in the beginning of this method.
            if (_tokenList.Count > 0)
            {
                _lines.Add(_tokenList);
            }

            return(_lines);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Create with supplied settings.
 /// </summary>
 /// <param name="settings"></param>
 public LexList(LexListSettings settings)
 {
     Init(settings);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Parse a quoted item. e.g. "batman"
        /// </summary>
        /// <param name="settings"></param>
        private void ParseQuotedItem(LexListSettings settings)
        {
            string quote = _reader.CurrentChar;
            string item = ReadQuotedToken();

            if (settings.TrimWhiteSpace)
                item = item.Trim();

            // Store the current list item.
            _tokenList.Add(item);

            // Check that closing quote is present.
            if (Expect(quote))
                _reader.ReadChar();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Parse a non-quoted item e.g. 123 as opposed to "123"
        /// </summary>
        private void ParseNonQuotedItem(LexListSettings settings)
        {
            // Read non-quoted text until the separator char is hit.
            string item = ReadNonQuotedToken(_separatorMap, true);

            if (settings.TrimWhiteSpace)
                item = item.Trim();

            // Store the current list item.
            _tokenList.Add(item);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Check for and handle new line.
        /// </summary>
        /// <returns></returns>
        public bool CheckAndHandleNewLine(LexListSettings settings)
        {
            if (_reader.IsEol())
            {
                _reader.ConsumeNewLine();

                // Check if newline means start of new record.
                if (settings.MultipleRecordsUsingNewLine)
                {
                    _lines.Add(_tokenList);
                    _tokenList = new List<string>();
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Parse supplied text using default settings.
 /// </summary>
 /// <param name="line"></param>
 /// <returns></returns>
 public static List<List<string>> ParseTable(string line)
 {
     LexListSettings settings = new LexListSettings();
     settings.MultipleRecordsUsingNewLine = true;
     return Parse(line, settings);
 }