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.
32 namespace Microsoft.Build.BuildEngine {
34 internal class Token {
39 public Token (string tokenValue, TokenType tokenType, int position)
41 this.tokenValue = tokenValue;
42 this.tokenType = tokenType;
43 this.Position = position + 1;
47 get { return tokenValue; }
50 public TokenType Type {
51 get { return tokenType; }
59 public static string TypeAsString (TokenType tokenType)
62 case TokenType.Item:return "@";
63 case TokenType.Property:return "$";
64 case TokenType.Metadata:return "%";
65 case TokenType.Transform:return "->";
66 case TokenType.Less:return "<";
67 case TokenType.Greater:return ">";
68 case TokenType.LessOrEqual:return "<=";
69 case TokenType.GreaterOrEqual:return ">=";
70 case TokenType.Equal:return "=";
71 case TokenType.NotEqual:return "!=";
72 case TokenType.LeftParen:return "(";
73 case TokenType.RightParen:return ")";
74 case TokenType.Dot:return ".";
75 case TokenType.Comma:return ",";
76 case TokenType.Not:return "!";
77 case TokenType.And:return "and";
78 case TokenType.Or:return "or";
79 case TokenType.Apostrophe:return "'";
80 default: return tokenType.ToString ();
84 public override string ToString ()
86 if (tokenType == TokenType.EOF || tokenType == TokenType.BOF)
87 return String.Format ("{0} at character position {1}", tokenType.ToString (), Position);
89 return String.Format ("\"{0}\" at character position {1}", tokenValue, Position);
93 internal enum TokenType {
106 // LiteralSubExpression,