Пример #1
0
 /// <inheritdoc />
 public CProcessorState(CTree currentTree, CHeaderFileParser parser, CProcessorStateValues globalValues)
 {
     CurrentTree  = currentTree;
     Parser       = parser;
     GlobalValues = globalValues;
     Values       = new CProcessorStateValues();
 }
Пример #2
0
        public void Parse()
        {
            Root = new CTree(null, null);
            var             parentTree       = Root;
            var             globalValues     = new CProcessorStateValues();
            CProcessorState state            = null;
            CProcessorBase  currentProcessor = null;

            using (var stream = File.OpenText())
            {
                while (!stream.EndOfStream)
                {
                    var line = stream.ReadLine();

                    while (!string.IsNullOrWhiteSpace(line))
                    {
                        if (currentProcessor == null)
                        {
                            foreach (var cProcessor in Processors)
                            {
                                if (cProcessor.CanParse(line))
                                {
                                    state            = new CProcessorState(parentTree, this, globalValues);
                                    currentProcessor = cProcessor;

                                    break;
                                }
                            }
                        }

                        if (currentProcessor != null)
                        {
                            var result = currentProcessor.Parse(line, state);

                            state.CurrentTree = result.CurrentTree;

                            if (result.EndOfProcess)
                            {
                                state            = null;
                                currentProcessor = null;
                            }

                            parentTree = result.CurrentTree;
                            line       = result.UnParsed;
                        }
                        else
                        {
                            // Skip Line
                            break;
                        }
                    }
                }
            }
        }