/// <summary> /// A função correspondente à transição correspondente ao ponto interno aos delimitadores. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> /// <exception cref="UtilitiesDataException">Se a leitura falhar no estado corrente.</exception> private IState <SymbValue, SymbType> InsideDelimitersTransition(IObjectReader <ISymbol <SymbValue, SymbType> > reader) { var symbolsStack = new Stack <SymbType>(); var symbol = reader.Get(); symbolsStack.Push(symbol.SymbolType); this.currentSymbolValues.Add(symbol); while (symbolsStack.Count > 0) { var topValue = symbolsStack.Pop(); if (reader.IsAtEOF()) { var dataParser = this.provider( this.currentRowNumber, this.currentColumnNumber); var error = new LogStatus <string, EParseErrorLevel>(); var parsed = dataParser.Parse(this.currentSymbolValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new UtilitiesDataException(string.Format( "Can't parse value from cell with coords ({0},{1}) with the provided parser.", this.currentRowNumber, this.currentRowNumber)); } this.currentRow.Add(parsed); this.dataAdder.Add(this.currentTable, this.currentRow); return(this.states[1]); } else { symbol = reader.Get(); var close = this.delimiters[topValue]; if (close.Contains(symbol.SymbolType)) { this.currentSymbolValues.Add(symbol); } else { if (!this.ignoreSymbolTypes.Contains(symbol.SymbolType)) { this.currentSymbolValues.Add(symbol); } symbolsStack.Push(topValue); if (this.delimiters.ContainsKey(symbol.SymbolType)) { symbolsStack.Push(symbol.SymbolType); } } } } reader.UnGet(); return(this.states[2]); }
/// <summary> /// A função correspondente à transição inicial. /// </summary> /// <param name="reader">O leitor de símbolos.</param> /// <returns>O próximo estado.</returns> /// <exception cref="UtilitiesDataException">Se a leitura falhar no estado corrente.</exception> private IState <SymbValue, SymbType> StartTransition(IObjectReader <ISymbol <SymbValue, SymbType> > reader) { if (reader.IsAtEOF()) { return(this.states[1]); } else { var symbol = reader.Get(); if (symbol.SymbolType.Equals(this.lineSeparator)) { this.dataAdder.Add(this.currentTable, this.currentRow); ++this.currentRowNumber; return(this.states[2]); } else if (symbol.SymbolType.Equals(this.columnSeparator)) { var dataParser = this.provider( this.currentRowNumber, this.currentColumnNumber); var error = new LogStatus <string, EParseErrorLevel>(); var parsed = dataParser.Parse( this.currentSymbolValues.ToArray(), error); if (error.HasLogs(EParseErrorLevel.ERROR)) { throw new UtilitiesDataException(string.Format( "Can't parse value from cell with coords ({0},{1}) with the provided parser.", this.currentRowNumber, this.currentRowNumber)); } this.currentRow.Add(parsed); ++this.currentColumnNumber; return(this.states[2]); } else if (this.delimiters.ContainsKey(symbol.SymbolType)) { reader.UnGet(); return(this.states[3]); } else { if (!this.ignoreSymbolTypes.Contains(symbol.SymbolType)) { this.currentSymbolValues.Add(symbol); } return(this.states[2]); } } }