Handle fault messages in duplex callback channel.
[mono.git] / mcs / class / Microsoft.Build.Engine / Microsoft.Build.BuildEngine / Token.cs
1 //
2 // TokenType.cs
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //   Jaroslaw Kowalski <jaak@jkowalski.net>
7 // 
8 // (C) 2006 Marek Sieradzki
9 // (C) 2004-2006 Jaroslaw Kowalski
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 #if NET_2_0
31
32 using System;
33
34 namespace Microsoft.Build.BuildEngine {
35
36         internal class Token {
37         
38                 string          tokenValue;
39                 TokenType       tokenType;
40         
41                 public Token (string tokenValue, TokenType tokenType, int position)
42                 {
43                         this.tokenValue = tokenValue;
44                         this.tokenType = tokenType;
45                         this.Position = position + 1;
46                 }
47                 
48                 public string Value {
49                         get { return tokenValue; }
50                 }
51                 
52                 public TokenType Type {
53                         get { return tokenType; }
54                 }
55
56                 // this is 1-based
57                 public int Position {
58                         get; private set;
59                 }
60
61                 public static string TypeAsString (TokenType tokenType)
62                 {
63                         switch (tokenType) {
64                                 case TokenType.Item:return "@";
65                                 case TokenType.Property:return "$";
66                                 case TokenType.Metadata:return "%";
67                                 case TokenType.Transform:return "->";
68                                 case TokenType.Less:return "<";
69                                 case TokenType.Greater:return ">";
70                                 case TokenType.LessOrEqual:return "<=";
71                                 case TokenType.GreaterOrEqual:return ">=";
72                                 case TokenType.Equal:return "=";
73                                 case TokenType.NotEqual:return "!=";
74                                 case TokenType.LeftParen:return "(";
75                                 case TokenType.RightParen:return ")";
76                                 case TokenType.Dot:return ".";
77                                 case TokenType.Comma:return ",";
78                                 case TokenType.Not:return "!";
79                                 case TokenType.And:return "and";
80                                 case TokenType.Or:return "or";
81                                 case TokenType.Apostrophe:return "'";
82                                 default: return tokenType.ToString ();
83                         }
84                 }
85
86                 public override string ToString ()
87                 {
88                         if (tokenType == TokenType.EOF || tokenType == TokenType.BOF)
89                                 return String.Format ("{0} at character position {1}", tokenType.ToString (), Position);
90
91                         return String.Format ("\"{0}\" at character position {1}", tokenValue, Position);
92                 }
93         }
94         
95         internal enum TokenType {
96                 EOF,
97                 BOF,
98                 Number,
99                 String,
100                 //Keyword,
101                 Punct,
102                 WhiteSpace,
103                 Item,
104                 Property,
105                 Metadata,
106                 FunctionName,
107                 Transform,
108 //              LiteralSubExpression,
109
110                 FirstPunct,
111
112                 Less,
113                 Greater,
114                 LessOrEqual,
115                 GreaterOrEqual,
116                 Equal,
117                 NotEqual,
118                 LeftParen,
119                 RightParen,
120                 Dot,
121                 Comma,
122                 Not,
123                 And,
124                 Or,
125                 Apostrophe,
126                 
127                 LastPunct,
128                 Invalid,
129         }
130 }
131
132 #endif