5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 // Jaroslaw Kowalski <jaak@jkowalski.net>
8 // (C) 2006 Marek Sieradzki
9 // (C) 2004-2006 Jaroslaw Kowalski
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
34 namespace Microsoft.Build.BuildEngine {
36 internal class Token {
41 public Token (string tokenValue, TokenType tokenType, int position)
43 this.tokenValue = tokenValue;
44 this.tokenType = tokenType;
45 this.Position = position + 1;
49 get { return tokenValue; }
52 public TokenType Type {
53 get { return tokenType; }
61 public static string TypeAsString (TokenType 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 ();
86 public override string ToString ()
88 if (tokenType == TokenType.EOF || tokenType == TokenType.BOF)
89 return String.Format ("{0} at character position {1}", tokenType.ToString (), Position);
91 return String.Format ("\"{0}\" at character position {1}", tokenValue, Position);
95 internal enum TokenType {
108 // LiteralSubExpression,