~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/NRefactory/Project/Src/Lexer/Token.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// <file>
2
 
//     <copyright see="prj:///doc/copyright.txt"/>
3
 
//     <license see="prj:///doc/license.txt"/>
4
 
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
5
 
//     <version>$Revision: 4482 $</version>
6
 
// </file>
7
 
 
8
 
using System;
9
 
 
10
 
namespace ICSharpCode.OldNRefactory.Parser
11
 
{
12
 
        public enum LiteralFormat : byte
13
 
        {
14
 
                None,
15
 
                DecimalNumber,
16
 
                HexadecimalNumber,
17
 
                OctalNumber,
18
 
                StringLiteral,
19
 
                VerbatimStringLiteral,
20
 
                CharLiteral,
21
 
                DateTimeLiteral
22
 
        }
23
 
        
24
 
        public class Token
25
 
        {
26
 
                internal readonly int kind;
27
 
                
28
 
                internal readonly int col;
29
 
                internal readonly int line;
30
 
                
31
 
                internal readonly LiteralFormat literalFormat;
32
 
                internal readonly object literalValue;
33
 
                internal readonly string val;
34
 
                internal Token next;
35
 
                readonly Location endLocation;
36
 
                
37
 
                public int Kind {
38
 
                        get { return kind; }
39
 
                }
40
 
                
41
 
                public LiteralFormat LiteralFormat {
42
 
                        get { return literalFormat; }
43
 
                }
44
 
                
45
 
                public object LiteralValue {
46
 
                        get { return literalValue; }
47
 
                }
48
 
                
49
 
                public string Value {
50
 
                        get { return val; }
51
 
                }
52
 
                
53
 
                public Location EndLocation {
54
 
                        get { return endLocation; }
55
 
                }
56
 
                
57
 
                public Location Location {
58
 
                        get {
59
 
                                return new Location(col, line);
60
 
                        }
61
 
                }
62
 
                
63
 
                public Token(int kind) : this(kind, 0, 0)
64
 
                {
65
 
                }
66
 
                
67
 
                public Token(int kind, int col, int line) : this (kind, col, line, null)
68
 
                {
69
 
                }
70
 
                
71
 
                public Token(int kind, int col, int line, string val)
72
 
                {
73
 
                        this.kind         = kind;
74
 
                        this.col          = col;
75
 
                        this.line         = line;
76
 
                        this.val          = val;
77
 
                        this.endLocation  = new Location(col + (string.IsNullOrEmpty(val) ? 1 : val.Length), line);
78
 
                }
79
 
                
80
 
                internal Token(int kind, int x, int y, string val, object literalValue, LiteralFormat literalFormat)
81
 
                        : this(kind, new Location(x, y), new Location(x + val.Length, y), val, literalValue, literalFormat)
82
 
                {
83
 
                }
84
 
                
85
 
                public Token(int kind, Location startLocation, Location endLocation, string val, object literalValue, LiteralFormat literalFormat)
86
 
                {
87
 
                        this.kind         = kind;
88
 
                        this.col          = startLocation.Column;
89
 
                        this.line         = startLocation.Line;
90
 
                        this.endLocation = endLocation;
91
 
                        this.val          = val;
92
 
                        this.literalValue = literalValue;
93
 
                        this.literalFormat = literalFormat;
94
 
                }
95
 
                
96
 
                public override string ToString()
97
 
                {
98
 
                        return string.Format("[C# {0}/VB {1} Location={2} EndLocation={3} val={4}]",
99
 
                                CSharp.Tokens.GetTokenString(kind),
100
 
                                VB.Tokens.GetTokenString(kind),
101
 
                                Location, 
102
 
                                EndLocation, 
103
 
                                val);
104
 
                        
105
 
                }
106
 
        }
107
 
}