private ReadWithCommentResultType HandleUncommonAdvanceResults(ReaderStateMachine.AdvanceResult res, char?lastRead) { string c; if (lastRead.HasValue) { c = lastRead.Value.ToString(); } else { c = "<end of data>"; } return (res switch { ReaderStateMachine.AdvanceResult.Exception_ExpectedEndOfRecord => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Encountered '{c}' when expecting end of record"), ReaderStateMachine.AdvanceResult.Exception_InvalidState => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Internal state machine is in an invalid state due to a previous error"), ReaderStateMachine.AdvanceResult.Exception_StartEscapeInValue => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Encountered '{c}', starting an escaped value, when already in a value"), ReaderStateMachine.AdvanceResult.Exception_UnexpectedCharacterInEscapeSequence => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Encountered '{c}' in an escape sequence, which is invalid"), ReaderStateMachine.AdvanceResult.Exception_ExpectedEndOfRecordOrValue => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Encountered '{c}' when expecting the end of a record or value"), ReaderStateMachine.AdvanceResult.Exception_UnexpectedEnd => Throw.InvalidOperationException_Returns <ReadWithCommentResultType>($"Data ended unexpectedly"), // this is CRAZY unlikely, but indicates that the TransitionMatrix used was incorrect ReaderStateMachine.AdvanceResult.Exception_UnexpectedLineEnding => Throw.ImpossibleException_Returns <ReadWithCommentResultType, T>($"Unexpected {nameof(Cesil.ReadRowEnding)} value encountered", Configuration), // likewise, CRAZY unlikely ReaderStateMachine.AdvanceResult.Exception_UnexpectedState => Throw.ImpossibleException_Returns <ReadWithCommentResultType, T>($"Unexpected state value entered", Configuration), _ => Throw.ImpossibleException_Returns <ReadWithCommentResultType, T>($"Unexpected {nameof(ReaderStateMachine.AdvanceResult)}: {res}", Configuration), });
internal static void StateTransition_ChangeState(ReaderStateMachine.State from, char c, ReaderStateMachine.State to, ReaderStateMachine.AdvanceResult res, [CallerMemberName] string?caller = null) { caller = SetCaller(caller); Debug.WriteLine($"{caller}: {from} + {c} => {to} & {res}"); }