~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
using System.Text;
 
7
 
 
8
namespace ICSharpCode.NRefactory.Parser
 
9
{
 
10
        public class SpecialTracker
 
11
        {
 
12
                List<ISpecial> currentSpecials = new List<ISpecial>();
 
13
                
 
14
                CommentType   currentCommentType;
 
15
                StringBuilder sb = new StringBuilder();
 
16
                Location         startPosition;
 
17
                bool commentStartsLine;
 
18
                
 
19
                public List<ISpecial> CurrentSpecials {
 
20
                        get {
 
21
                                return currentSpecials;
 
22
                        }
 
23
                }
 
24
                
 
25
                /// <summary>
 
26
                /// Gets the specials from the SpecialTracker and resets the lists.
 
27
                /// </summary>
 
28
                public List<ISpecial> RetrieveSpecials()
 
29
                {
 
30
                        List<ISpecial> tmp = currentSpecials;
 
31
                        currentSpecials = new List<ISpecial>();
 
32
                        return tmp;
 
33
                }
 
34
                
 
35
                public void AddEndOfLine(Location point)
 
36
                {
 
37
                        currentSpecials.Add(new BlankLine(point));
 
38
                }
 
39
                
 
40
                public void AddPreprocessingDirective(PreprocessingDirective directive)
 
41
                {
 
42
                        if (directive == null)
 
43
                                throw new ArgumentNullException("directive");
 
44
                        currentSpecials.Add(directive);
 
45
                }
 
46
                
 
47
                // used for comment tracking
 
48
                public void StartComment(CommentType commentType, bool commentStartsLine, Location startPosition)
 
49
                {
 
50
                        this.currentCommentType = commentType;
 
51
                        this.startPosition      = startPosition;
 
52
                        this.sb.Length          = 0;
 
53
                        this.commentStartsLine  = commentStartsLine;
 
54
                }
 
55
                
 
56
                public void AddChar(char c)
 
57
                {
 
58
                        sb.Append(c);
 
59
                }
 
60
                
 
61
                public void AddString(string s)
 
62
                {
 
63
                        sb.Append(s);
 
64
                }
 
65
                
 
66
                public void FinishComment(Location endPosition)
 
67
                {
 
68
                        currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), commentStartsLine, startPosition, endPosition));
 
69
                }
 
70
        }
 
71
}