Merge pull request #1336 from esdrubal/datatablereadxmlschema
[mono.git] / mcs / class / Microsoft.Build / Microsoft.Build.Internal / ExpressionTokenizer.cs
index 470bbed5d2d757a648813a8ce215e90aaddba2f5..9760ad2acbd18d0b665f0a515035681a237c289d 100644 (file)
@@ -1,8 +1,35 @@
+//
+// ExpressionTokenizer.cs
+//
+// Author:
+//   Atsushi Enomoto (atsushi@xamarin.com)
+//
+// Copyright (C) 2013 Xamarin Inc. (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
 using System;
 using System.Collections.Generic;
 using Microsoft.Build.Evaluation;
 
-namespace Microsoft.Build.Internal
+namespace Microsoft.Build.Internal.Expressions
 {
        enum ExpressionValidationType
        {
@@ -46,11 +73,16 @@ namespace Microsoft.Build.Internal
 
                        error = null;
                        token_value = null;
-                       current_token_position = pos;
 
-                       SkipSpaces ();
+                       while (pos < source.Length) {
+                               if (spaces.IndexOf (source [pos]) >= 0)
+                                       pos++;
+                               else
+                                       break;
+                       }
                        if (pos == source.Length)
                                return false;
+                       current_token_position = pos;
 
                        switch (source [pos++]) {
                        case '.':
@@ -59,7 +91,14 @@ namespace Microsoft.Build.Internal
                        case ',':
                                TokenForItemPropertyValue (",", Token.COMMA);
                                break;
+                       case '[':
+                               TokenForItemPropertyValue ("[", Token.BRACE_OPEN);
+                               break;
+                       case ']':
+                               TokenForItemPropertyValue ("]", Token.BRACE_CLOSE);
+                               break;
                        case '(':
+                               modes.Push (TokenizerMode.Default);
                                TokenForItemPropertyValue ("(", Token.PAREN_OPEN);
                                break;
                        case ')':
@@ -161,29 +200,26 @@ namespace Microsoft.Build.Internal
                                        current_token = Token.TRUE_LITERAL;
                                else if (val.Equals ("FALSE", StringComparison.OrdinalIgnoreCase))
                                        current_token = Token.FALSE_LITERAL;
+                               else if (val.Equals ("YES", StringComparison.OrdinalIgnoreCase))
+                                       current_token = Token.TRUE_LITERAL;
+                               else if (val.Equals ("NO", StringComparison.OrdinalIgnoreCase))
+                                       current_token = Token.FALSE_LITERAL;
+                               else if (val.Equals ("ON", StringComparison.OrdinalIgnoreCase))
+                                       current_token = Token.TRUE_LITERAL;
+                               else if (val.Equals ("OFF", StringComparison.OrdinalIgnoreCase))
+                                       current_token = Token.FALSE_LITERAL;
                                else {
                                        current_token = Token.NAME;
                                        token_value = ProjectCollection.Unescape (val);
                                        break;
                                }
-                               Console.Error.WriteLine ("@@@@@ [{0}]", val);
                                break;
                        }
                        return true;
                }
                string spaces = " \t\r\n";
-               
-               void SkipSpaces ()
-               {
-                       while (current_token_position < source.Length) {
-                               if (spaces.IndexOf (source [current_token_position]) > 0)
-                                       current_token_position++;
-                               else
-                                       break;
-                       }
-               }
 
-               static readonly char [] token_starter_chars = ".,)-=:!><$@%\"' ".ToCharArray ();
+               static readonly char [] token_starter_chars = ".,[]()-=:!><$@%\"' ".ToCharArray ();
                
                void ReadStringLiteral (string source, char c)
                {
@@ -200,7 +236,7 @@ namespace Microsoft.Build.Internal
                
                void TokenForItemPropertyValue (string value, int token)
                {
-                       if (CurrentTokenizerMode == TokenizerMode.InsideItemOrProperty)
+                       if (true)//CurrentTokenizerMode == TokenizerMode.InsideItemOrProperty)
                                current_token = token;
                        else {
                                current_token = Token.NAME;
@@ -254,7 +290,7 @@ namespace Microsoft.Build.Internal
        {
                //int Line { get; }
                int Column { get; }
-               //string File { get; }
+               string File { get; }
                
                string ToLocationString ();
        }
@@ -263,7 +299,7 @@ namespace Microsoft.Build.Internal
        {
                //public int Line { get; set; }
                public int Column { get; set; }
-               //public string File { get; set; }
+               public string File { get; set; }
                
                public string ToLocationString ()
                {