Exemple #1
0
        private void MergeLocalLine(CodeLine line)
        {
            Match match;

            switch (_mergeMode)
            {
                case MergeMode.Normal:
                    if ((match = line.Match(_rxReplace)).Success)
                    {
                        _mergeMode = MergeMode.ReplaceStart;
                        _replace.Clear();
                        var trailing = match.Groups[1].Value.Trim();
                        if (!string.IsNullOrEmpty(trailing)) _replace.Add(trailing);
                    }
                    else if ((match = line.Match(_rxInsert)).Success)
                    {
                        var labelName = match.Groups[1].Value.Trim();
                        _insertIndex = FindLabel(labelName);
                        if (_insertIndex < 0)
                        {
                            _errors.Add(new CodeError(line,
                                string.Format("Label '{0}' not found.", labelName)));
                        }
                        else
                        {
                            if (_showMergeComments)
                            {
                                _lines.Insert(_insertIndex, new CodeLine(null, 0,
                                    string.Format("// insert from {0} ({1})", line.FileName, line.LineNum)));
                                _insertIndex++;
                            }
                        }
                        _mergeMode = MergeMode.Insert;
                    }
                    else
                    {
                        _lines.Add(line);
                    }
                    break;

                case MergeMode.ReplaceStart:
                    if ((match = line.Match(_rxWith)).Success)
                    {
                        if (_replace.Count == 0)
                        {
                            _errors.Add(new CodeError(line, "Empty #replace statement."));
                            _insertIndex = -1;
                        }
                        else if ((_insertIndex = FindReplace()) < 0)
                        {
                            _errors.Add(new CodeError(line, "#replace not found."));
                        }
                        else
                        {
                            _lines.RemoveRange(_insertIndex, _replace.Count);

                            if (_showMergeComments)
                            {
                                _lines.Insert(_insertIndex, new CodeLine(null, 0,
                                    string.Format("// replace from {0} ({1})", line.FileName, line.LineNum)));
                                _insertIndex++;
                            }

                            if (!string.IsNullOrWhiteSpace(match.Groups[1].Value))
                            {
                                _lines.Insert(_insertIndex, new CodeLine(line.File, line.LineNum, match.Groups[1].Value));
                            }
                        }

                        _mergeMode = MergeMode.ReplaceWith;
                        _replace.Clear();
                    }
                    else
                    {
                        _replace.Add(line.Text);
                    }
                    break;

                case MergeMode.ReplaceWith:
                    if ((match = line.Match(_rxEndReplace)).Success)
                    {
                        if (_insertIndex >= 0)
                        {
                            if (_showMergeComments)
                            {
                                _lines.Insert(_insertIndex, new CodeLine(null, 0, "// end of replace"));
                                _insertIndex++;
                            }
                        }

                        _mergeMode = MergeMode.Normal;
                        _insertIndex = -1;

                        if (!String.IsNullOrWhiteSpace(match.Groups[1].Value))
                        {
                            _lines.Add(new CodeLine(line.File, line.LineNum, match.Groups[1].Value));
                        }
                    }
                    else
                    {
                        if (_insertIndex >= 0)
                        {
                            _lines.Insert(_insertIndex, line);
                            _insertIndex++;
                        }
                    }
                    break;

                case MergeMode.Insert:
                    if ((match = line.Match(_rxEndInsert)).Success)
                    {
                        if (_insertIndex >= 0 && _showMergeComments)
                        {
                            _lines.Insert(_insertIndex, new CodeLine(null, 0, "// end of insert"));
                        }

                        _mergeMode = MergeMode.Normal;
                        _insertIndex = -1;
                    }
                    else
                    {
                        if (_insertIndex > 0)
                        {
                            _lines.Insert(_insertIndex, line);
                            _insertIndex++;
                        }
                    }
                    break;
            }
        }
Exemple #2
0
 public CodeError(CodeLine line, string message)
 {
     _line = line;
     _message = message;
 }
Exemple #3
0
        private void MergeLocalFile(CodeFile file)
        {
            _mergeMode = MergeMode.Normal;

            using (var reader = new StreamReader(file.FileName))
            {
                if (_showMergeComments)
                {
                    _lines.Add(new CodeLine(null, 0, string.Concat("// start of local file ", file.FileName)));
                }

                int lineNum = 1;
                while (!reader.EndOfStream)
                {
                    var line = new CodeLine(file, lineNum, reader.ReadLine());
                    MergeLocalLine(line);
                    lineNum++;
                }

                if (_showMergeComments)
                {
                    _lines.Add(new CodeLine(null, 0, string.Concat("// end of local file ", file.FileName)));
                }
            }
        }