Beispiel #1
0
 private void FinishRecord()
 {
     if (SequenceInvokationList.Matches(PreviousRecordSequenceInvokationList))
     {
         InvokeRootSequence();
     }
     else
     {
         tableCount++;
         PreviousRecordSequenceInvokationList.Assign(SequenceInvokationList);
         InvokeRootSequence();
     }
 }
Beispiel #2
0
        private void ParseChar(char aChar)
        {
            if (!lineParser.InLine)
            {
                // new line starting
                // calculate initial lineType and check if first char is ok

                lineBuilder.Clear();

                lineType = CalculateStartLineType(aChar);
                switch (lineType)
                {
                case FtLineType.Signature:
                    declarationParser.StartLine();
                    SetLineCommentChar(aChar);
                    break;

                case FtLineType.Declaration2:
                    declarationParser.StartLine();
                    break;

                case FtLineType.Comment:
                    if (!headerRead)
                    {
                        if (metaEmbedded && !embeddedMetaRead)
                        {
                            embeddedMetaParser.StartLine();
                        }
                    }
                    break;

                case FtLineType.EmbeddedMeta:
                    embeddedMetaParser.StartLine();
                    break;

                case FtLineType.Heading:
                    InvokeRootSequence();
                    int headingLineReadIndex = headingLineReadCount++;
                    headingLineParser.Start(headingLineReadIndex);
                    OnHeadingLineStarted(headingLineReadIndex);
                    break;
                }
            }

            bool endOfLineToBeEmbedded = recordParser.IsEndOfLineToBeEmbedded();

            LineParser.LineEndedType lineEndedType;
            lineParser.ParseChar(aChar, endOfLineToBeEmbedded, out lineEndedType);

            if (lineEndedType != LineParser.LineEndedType.Continued)
            {
                bool lineEndInitiated;
                if (lineEndedType == LineParser.LineEndedType.Initiated)
                {
                    lineEndInitiated = true;
                }
                else
                {
                    lineEndInitiated = false;
                    lineBuilder.Append(aChar);
                }

                switch (lineType)
                {
                case FtLineType.Signature:
                    if (!lineEndInitiated)
                    {
                        declarationParser.ParseSignatureLineChar(aChar);
                    }
                    else
                    {
                        declarationParser.FinishSignatureLine();
                    }
                    break;

                case FtLineType.Declaration2:
                    if (!lineEndInitiated)
                    {
                        declarationParser.ParseDeclaration2LineChar(aChar);
                    }
                    else
                    {
                        FinishDeclaration();
                    }
                    break;

                case FtLineType.Comment:
                    if (!headerRead)
                    {
                        if (metaEmbedded && !embeddedMetaRead)
                        {
                            if (!lineEndInitiated)
                            {
                                // see if embedded Meta started in this line
                                bool embeddedMetaPresent;
                                embeddedMetaParser.ParseNotYetDetectedChar(aChar, out embeddedMetaPresent);
                                if (embeddedMetaPresent)
                                {
                                    lineType = FtLineType.EmbeddedMeta;
                                }
                            }
                        }
                    }
                    break;

                case FtLineType.EmbeddedMeta:
                    if (!lineEndInitiated)
                    {
                        embeddedMetaParser.ParseChar(aChar);
                    }
                    else
                    {
                        embeddedMetaParser.AppendLine();
                        if (embeddedMetaParser.Ready)
                        {
                            FinishEmbeddedMeta();
                        }
                    }
                    break;

                case FtLineType.Blank:
                    if (!headerRead)
                    {
                        if (!lineEndInitiated)
                        {
                            // must be a heading line
                            lineType = FtLineType.Heading;
                            if (metaEmbedded && !embeddedMetaRead)
                            {
                                // error if expecting embedded Meta
                                throw new FtSerializationException(FtSerializationError.EmbeddedMetaNotFound, Properties.Resources.SerializationReader_ParseChar_EmbeddedMetaLineNotBlankOrComment);
                            }
                            else
                            {
                                Debug.Assert(HeadingLineCount > 0 && !headingLinesRead);
                                InvokeRootSequence();
                                int headingLineReadIndex = headingLineReadCount++;
                                headingLineParser.Start(headingLineReadIndex);
                                OnHeadingLineStarted(headingLineReadIndex);
                                headingLineParser.ParseChar(aChar);
                            }
                        }
                    }
                    else
                    {
                        if (!lineEndInitiated)
                        {
                            // is actually a record line
                            lineType = FtLineType.Record;
                            if (newTableStarted)
                            {
                                PreviousRecordSequenceInvokationList.Assign(SequenceInvokationList);
                                newTableStarted = false;
                            }
                            InvokeRootSequence();
                            int recordIndex = recordCount++;
                            recordParser.Start(recordIndex);
                            OnRecordStarted(recordIndex);
                            recordParser.ParseChar(aChar);
                        }
                        else
                        {
                            if (!IgnoreBlankLines)
                            {
                                throw new FtSerializationException(FtSerializationError.RecordNotEnoughFields, Properties.Resources.SerializationReader_ParseChar_BlankRecordsNotAllowed);
                            }
                        }
                    }

                    break;

                case FtLineType.Heading:
                    if (!lineEndInitiated)
                    {
                        headingLineParser.ParseChar(aChar);
                    }
                    else
                    {
                        FinishHeadingLine();
                    }
                    break;

                case FtLineType.Record:
                    if (!lineEndInitiated)
                    {
                        recordParser.ParseChar(aChar);
                    }
                    else
                    {
                        FinishRecord();
                    }
                    break;

                default:
                    throw FtInternalException.Create(InternalError.SerializationReader_ParseChar_UnsupportedLineType, lineType.ToString());
                }
            }
        }