CqlLexerHelpers.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / EntitySql / CqlLexerHelpers.cs / 2 / CqlLexerHelpers.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....]
// @backup [....] 
//--------------------------------------------------------------------- 

namespace System.Data.Common.EntitySql 
{
    using System;
    using System.Globalization;
    using System.Collections.Generic; 
    using System.Text.RegularExpressions;
    using System.Diagnostics; 
    using System.Text; 

    ///  
    /// Represents Cql scanner and helper functions.
    /// 
    internal sealed partial class CqlLexer
    { 
        static readonly StringComparer _stringComparer = StringComparer.OrdinalIgnoreCase;
        static Dictionary _keywords; 
        static HashSet _invalidAliasName; 
        static Dictionary _operators;
        static Dictionary _punctuators; 
        static HashSet _functionKeywords = InitializeFunctionKeywords();
        static Regex _reDateTimeValue;
        static Regex _reTimeValue;
        static Regex _reDateTimeOffsetValue; 
        private const string _datetimeValueRegularExpression = @"^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}([ ])+[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?$";
        private const string _timeValueRegularExpression = @"^[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?$"; 
        private const string _datetimeOffsetValueRegularExpression = @"^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}([ ])+[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?([ ])*[\+-][0-9]{1,2}:[0-9]{1,2}$"; 

        private int _iPos; 
        private int _lineNumber;
        ParserOptions _parserOptions;
        private string _query;
        private bool _identifierState; 
        private bool _aliasIdentifierState;
 
        /// Defines the set of characters to be interpreted as mandatory line breaks 
        /// according to UNICODE 5.0, section 5.8 Newline Guidelines.These are 'mandatory'
        /// line breaks. We do not handle other 'line breaking opportunities'as defined by 
        /// UNICODE 5.0 since they are intended for presentation. The mandatory line break
        /// defines breaking opportunities that must not be ignored. For all practical purposes
        /// the interpretation of mandatory breaks determines the end of one line and consequently
        /// the start of the next line of query text. 
        /// NOTE that CR and CRLF is treated as a composite 'character' and was obviously and intentionaly
        /// omitted in the character set bellow. 
        static readonly Char[] _newLineCharacters = { '\u000A' , // LF - line feed 
                                                      '\u0085' , // NEL - next line
                                                      '\u000B' , // VT - vertical tab 
                                                      '\u2028' , // LS - line separator
                                                      '\u2029'   // PS - paragraph separator
                                                    };
 
        /// 
        /// Intializes scanner 
        ///  
        /// input query
        /// parser options 
        internal CqlLexer( string query, ParserOptions parserOptions )
            : this()
        {
            EntityUtil.CheckArgumentNull(query,"query"); 
            EntityUtil.CheckArgumentNull(parserOptions, "parserOptions");
 
            _query = query; 
            _parserOptions = parserOptions;
            yy_reader = new System.IO.StringReader(_query); 
        }

        /// 
        /// Creates a new token. 
        /// 
        /// tokenid 
        /// ast node 
        /// 
        static internal Token NewToken( short tokenId, AstNode tokenvalue ) 
        {
            return new Token(tokenId, tokenvalue);
        }
 
        /// 
        /// Creates a new token representing a terminal. 
        ///  
        /// tokenid
        /// lexical value 
        /// 
        static internal Token NewToken( short tokenId, TerminalToken termToken )
        {
            return new Token(tokenId, termToken); 
        }
 
        ///  
        /// Represents a token to be used in parser stack.
        ///  
        internal class Token
        {
            private short _tokenId;
            private object _tokenValue; 

            internal Token( short tokenId, AstNode tokenValue ) 
            { 
                _tokenId = tokenId;
                _tokenValue = tokenValue; 
            }

            internal Token( short tokenId, TerminalToken terminal )
            { 
                _tokenId = tokenId;
                _tokenValue = terminal; 
            } 

            internal short TokenId 
            {
                get { return _tokenId; }
            }
 
            internal object Value
            { 
                get { return _tokenValue; } 
            }
        } 

        /// 
        /// Represents a terminal token
        ///  
        internal class TerminalToken
        { 
            string _token; 
            int _iPos;
 
            internal TerminalToken( string token, int iPos )
            {
                _token = token;
                _iPos = iPos; 
            }
 
            internal int IPos 
            {
                get { return _iPos; } 
            }

            internal string Token
            { 
                get { return _token; }
            } 
        } 

        internal static class yy_translate 
        {
            internal static char translate( char c )
            #region TRANSLATE
            { 
                if (Char.IsWhiteSpace(c)||Char.IsControl(c))
                { 
                    if (IsNewLine(c)) 
                    {
                        return '\n'; 
                    }
                    return ' ';
                }
 
                if (c < 0x007F)
                { 
                    return c; 
                }
 
                if (Char.IsLetter(c)||Char.IsSymbol(c)||Char.IsNumber(c))
                {
                    return 'a';
                } 

                // 
                // otherwise pass dummy 'marker' char so as we can continue 'extracting' tokens. 
                //
                return '`'; 
            }
            #endregion
        }
 

        ///  
        /// Returns current lexeme 
        /// 
        internal string YYText 
        {
            get { return yytext(); }
        }
 
        /// 
        /// Returns current input position 
        ///  
        internal int IPos
        { 
            get { return _iPos; }
        }

        ///  
        /// Advances input position.
        ///  
        /// updated input position 
        internal int AdvanceIPos()
        { 
            _iPos += YYText.Length;
            return _iPos;
        }
 
        /// 
        /// returns true if given term is a eSql keyword 
        ///  
        /// 
        ///  
        internal static bool IsReservedKeyword( string term )
        {
            return CqlLexer.InternalKeywordDictionary.ContainsKey(term);
        } 

        ///  
        /// Map lexical symbols to respective identifier or kword. 
        /// 
        /// lexeme 
        /// Token
        internal Token MapIdentifierOrKeyword( string symbol )
        {
            if (symbol[0] == '[' && symbol.Length > 1) 
            {
                if (symbol[symbol.Length - 1] == ']') 
                { 
                    Identifier id = new Identifier(symbol, true, _query, _iPos);
                    id.ErrCtx.ErrorContextInfo = EntityRes.CtxEscapedIdentifier; 
                    return NewToken(CqlParser.ESCAPED_IDENTIFIER, id);
                }
                else
                { 
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifier(symbol), _iPos);
                } 
            } 

            // look ahead to see if keyword could be used as function 
            yy_mark_end();
            Char ch = yy_advance();
            while (ch != YY_EOF && (Char.IsWhiteSpace(ch) || IsNewLine(ch)))
            { 
                ch = yy_advance();
            } 
            yy_to_mark(); 

            if (ch == '(' && _functionKeywords.Contains(symbol)) 
            {
                return NewToken(CqlParser.IDENTIFIER, new Identifier(symbol, false, _query, _iPos));
            }
 
            if ((!_identifierState && !_aliasIdentifierState && ch != '.') && CqlLexer.InternalKeywordDictionary.ContainsKey(symbol))
            { 
                ResetKeywordAsIdentifierState(); 

                if (symbol.Equals("AS", StringComparison.OrdinalIgnoreCase)) 
                {
                    _aliasIdentifierState = true;
                }
 
                return NewToken(CqlLexer.InternalKeywordDictionary[symbol], new TerminalToken(symbol, _iPos));
            } 
            else 
            {
                ResetKeywordAsIdentifierState(); 

                if (InternalInvalidAliasNameDictionary.Contains(symbol))
                {
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidAliasName(symbol), _iPos); 
                }
 
                Identifier id = new Identifier(symbol, false, _query, _iPos); 
                id.ErrCtx.ErrorContextInfo = EntityRes.CtxIdentifier;
                return NewToken(CqlParser.IDENTIFIER, id); 
            }
        }

        ///  
        /// Maps operator to respective token
        ///  
        /// operator lexeme 
        /// Token
        internal Token MapOperator( string oper ) 
        {
            if (InternalOperatorDictionary.ContainsKey(oper))
            {
                return NewToken(InternalOperatorDictionary[oper], new TerminalToken(oper, _iPos)); 
            }
            else 
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidOperatorSymbol, _iPos);
            } 
        }

        /// 
        /// Maps puctuator to respective token 
        /// 
        /// punctuator 
        /// Token 
        internal Token MapPunctuator( string punct )
        { 
            if (InternalPunctuatorDictionary.ContainsKey(punct))
            {
                ResetKeywordAsIdentifierState();
 
                if (punct.Equals(".", StringComparison.OrdinalIgnoreCase))
                { 
                    _identifierState = true; 
                }
 
                return NewToken(InternalPunctuatorDictionary[punct], new TerminalToken(punct, _iPos));
            }
            else
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidPunctuatorSymbol, _iPos);
            } 
        } 

        ///  
        /// Maps double quoted string to ids or literal strings
        /// 
        /// 
        /// Token 
        internal Token MapDoubleQuotedString( string symbol )
        { 
            if (_parserOptions.AllowQuotedIdentifiers) 
            {
                return NewToken(CqlParser.ESCAPED_IDENTIFIER, new Identifier(symbol, true, _query, _iPos)); 
            }
            else
            {
                LiteralKind literalKind = LiteralKind.NonUnicodeString; 
                if ('N' == symbol[0])
                { 
                    literalKind = LiteralKind.UnicodeString; 
                }
 
                return NewToken(CqlParser.LITERAL, new Literal(symbol, literalKind, _query, _iPos));
            }
        }
 
        /// 
        /// Creates literal token 
        ///  
        /// literal
        /// literal kind 
        /// Literal Token
        internal Token NewLiteralToken( string literal, LiteralKind literalKind )
        {
            string literalValue = literal; 
            switch (literalKind)
            { 
                case LiteralKind.Binary: 
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidBinaryValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("binary", literalValue), _iPos);
                    }
                    break; 

                case LiteralKind.String: 
                    literalKind = LiteralKind.NonUnicodeString; 
                    if ('N' == literal[0])
                    { 
                        literalKind = LiteralKind.UnicodeString;
                    }
                    break;
 
                case LiteralKind.DateTime:
                    literalValue = GetLiteralSingleQuotePayload(literal); 
                    if (!IsValidDateTimeValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("datetime", literalValue), _iPos); 
                    }
                    break;

                case LiteralKind.Time: 
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidTimeValue(literalValue)) 
                    { 
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("time", literalValue), _iPos);
                    } 
                    break;
                case LiteralKind.DateTimeOffset:
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidDateTimeOffsetValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("datetimeoffset", literalValue), _iPos); 
                    } 
                    break;
 

                case LiteralKind.Guid:
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidGuidValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("guid", literalValue), _iPos); 
                    } 
                    break;
            } 

            return NewToken(CqlParser.LITERAL, new Literal(literalValue, literalKind, _query, _iPos));
        }
 
        /// 
        /// Creates parameter token 
        ///  
        /// param
        /// Parameter Token 
        internal Token NewParameterToken( string param )
        {
            return NewToken(CqlParser.PARAMETER, new Parameter(param, _query, _iPos));
        } 

        ///  
        /// handles escaped identifiers 
        /// ch will always be translated i.e. normalized.
        ///  
        /// 
        internal Token HandleEscapedIdentifiers()
        {
            char ch = YYText[0]; 
            int count = -1;
            while (ch != YY_EOF) 
            { 
                if (ch == YY_EOF)
                { 
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifierEOF, _iPos);
                }
                else if (ch == ']')
                { 
                    count++;
                    yy_mark_end(); 
                    ch = yy_advance(); 
                    if (ch == ']') count--;
                    if (ch != ']') break; 
                }
                ch = yy_advance();
            }
 
            if (0 != count)
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifierUnbalanced(YYText), _iPos); 
            }
 
            yy_to_mark();

            ResetKeywordAsIdentifierState();
 
            return MapIdentifierOrKeyword(YYText.Replace("]]","]"));
        } 
 
        static internal bool IsLetterOrDigitOrUnderscore( string symbol , out bool isIdentifierASCII )
        { 
            isIdentifierASCII = true;
            for (int i = 0 ; i < symbol.Length ; i++)
            {
                isIdentifierASCII = isIdentifierASCII && symbol[i] < 0x80; 
                if (!isIdentifierASCII && !IsLetter(symbol[i]) && !IsDigit(symbol[i]) && (symbol[i] != '_'))
                { 
                    return false; 
                }
            } 
            return true;
        }

        private void ResetKeywordAsIdentifierState() 
        {
            _identifierState = _aliasIdentifierState = false; 
        } 

        private void ResetIndetifierState() 
        {
            _identifierState = false;
        }
 
        static private bool IsLetter( char c )
        { 
            return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); 
        }
 
        static private bool IsDigit( char c )
        {
            return (c >= '0' && c <= '9');
        } 

        static bool isHexDigit( char c ) 
        { 
            return (IsDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
        } 

        /// 
        /// Returns true if given char is a new line character defined by
        /// UNICODE 5.0, section 5.8 Newline Guidelines. 
        /// These are 'mandatory' line breaks. NOTE that CRLF is treated as a
        /// composite 'character' and was intentionaly omitted in the character set bellow. 
        ///  
        /// 
        ///  
        internal static bool IsNewLine(Char c)
        {
            for(int i=0; i < _newLineCharacters.Length; i++)
            { 
                if ( c == _newLineCharacters[i] )
                { 
                    return true; 
                }
            } 
            return false;
        }

        ///  
        /// extracts single quoted literal 'payload'. literal MUST BE normalized.
        ///  
        ///  
        /// 
        static private string GetLiteralSingleQuotePayload(string literal) 
        {
            Debug.Assert(-1 != literal.IndexOf('\''), "quoted literal value must have single quotes");
            Debug.Assert(-1 != literal.LastIndexOf('\''), "quoted literal value must have single quotes");
            Debug.Assert(literal.IndexOf('\'') != literal.LastIndexOf('\''), "quoted literal value must have 2 single quotes"); 
            Debug.Assert(literal.Split(new char[] { '\'' }).Length == 3, "quoted literal value must have 2 single quotes");
 
            // NOTE: this is not a precondition validation. This validation is for security purposes based on the 
            // paranoid assumption that all input is evil. we should not see this exception under normal
            // conditions. 
            if ((literal.Split(new char[] { '\'' }).Length != 3) || (-1 == literal.IndexOf('\'')) || (-1 == literal.LastIndexOf('\'')))
            {
                throw EntityUtil.EntitySqlError(System.Data.Entity.Strings.MalformedSingleQuotePayload);
            } 

            int startIndex = literal.IndexOf('\''); 
 
            string literalPayload = literal.Substring(startIndex + 1, literal.Length - (startIndex + 2));
 
            Debug.Assert(literalPayload.IndexOf('\'') == -1, "quoted literal payload must not have single quotes");
            Debug.Assert(literalPayload.LastIndexOf('\'') == -1, "quoted literal payload must not have single quotes");

            // NOTE: this is not a precondition validation. This validation is for security purposes based on the 
            // paranoid assumption that all input is evil. we should not see this exception under normal
            // conditions. 
            if (literalPayload.Split(new char[] { '\'' }).Length != 1) 
            {
                throw EntityUtil.EntitySqlError(System.Data.Entity.Strings.MalformedSingleQuotePayload); 
            }

            return literalPayload;
        } 

        ///  
        /// returns true if guid literal value format is valid 
        /// 
        ///  
        /// 
        static bool IsValidGuidValue( string guidValue )
        {
            int startIndex = 0; 
            int endIndex = guidValue.Length - 1;
            if ((endIndex - startIndex) + 1 != 36) 
            { 
                return false;
            } 

            int i = 0;
            bool bValid = true;
            while (bValid && i < 36) 
            {
                if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) 
                { 
                    bValid = (guidValue[startIndex + i] == '-');
                } 
                else
                {
                    bValid = isHexDigit(guidValue[startIndex + i]);
                } 
                i++;
            } 
            return bValid; 
        }
 
        /// 
        /// returns true if binary literal value format is valid
        /// 
        ///  
        /// 
        static bool IsValidBinaryValue( string binaryValue ) 
        { 
            Debug.Assert(null != binaryValue, "binaryValue must not be null");
 
            if (String.IsNullOrEmpty(binaryValue))
            {
                return true;
            } 

            int i = 0; 
            bool bValid = binaryValue.Length > 0; 
            while (bValid && i < binaryValue.Length)
            { 
                bValid = isHexDigit(binaryValue[i++]);
            }

            return bValid; 
        }
 
        ///  
        /// Returns true if datetime literal value format is valid
        /// allowed format is: dddd-d?d-d?d{space}+d?d:d?d(:d?d(.d?d?d)?)? 
        /// where d is any decimal digit.
        /// 
        /// 
        ///  
        static bool IsValidDateTimeValue( string datetimeValue )
        { 
            if (null == _reDateTimeValue) 
            {
                _reDateTimeValue = new Regex(_datetimeValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant); 
            }
            return _reDateTimeValue.IsMatch(datetimeValue);
        }
 
        /// 
        /// Returns true if time literal value format is valid 
        /// allowed format is: +d?d:d?d(:d?d(.d?d?d)?)? 
        /// where d is any decimal digit.
        ///  
        /// 
        /// 
        static bool IsValidTimeValue(string timeValue)
        { 
            if (null == _reTimeValue)
            { 
                _reTimeValue = new Regex(_timeValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant); 
            }
            return _reTimeValue.IsMatch(timeValue); 
        }

        /// 
        /// Returns true if datetimeoffset literal value format is valid 
        /// allowed format is: dddd-d?d-d?d{space}+d?d:d?d(:d?d(.d?d?d)?)?([+-]d?d:d?d)?
        /// where d is any decimal digit. 
        ///  
        /// 
        ///  
        static bool IsValidDateTimeOffsetValue(string datetimeOffsetValue)
        {
            if (null == _reDateTimeOffsetValue)
            { 
                _reDateTimeOffsetValue = new Regex(_datetimeOffsetValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant);
            } 
            return _reDateTimeOffsetValue.IsMatch(datetimeOffsetValue); 
        }
 

        private static Dictionary InternalKeywordDictionary
        {
            get 
            {
                if (null == _keywords) 
                { 
                    #region eSql Keywords
                    Dictionary keywords = new Dictionary(60, _stringComparer); 
                    keywords.Add("all", CqlParser.ALL);
                    keywords.Add("and", CqlParser.AND);
                    keywords.Add("anyelement", CqlParser.ANYELEMENT);
                    keywords.Add("apply", CqlParser.APPLY); 
                    keywords.Add("as", CqlParser.AS);
                    keywords.Add("asc", CqlParser.ASC); 
                    keywords.Add("between", CqlParser.BETWEEN); 
                    keywords.Add("by", CqlParser.BY);
                    keywords.Add("case", CqlParser.CASE); 
                    keywords.Add("cast", CqlParser.CAST);
                    keywords.Add("collate", CqlParser.COLLATE);
                    keywords.Add("createref", CqlParser.CREATEREF);
                    keywords.Add("cross", CqlParser.CROSS); 
                    keywords.Add("deref", CqlParser.DEREF);
                    keywords.Add("desc", CqlParser.DESC); 
                    keywords.Add("distinct", CqlParser.DISTINCT); 
                    keywords.Add("element", CqlParser.ELEMENT);
                    keywords.Add("else", CqlParser.ELSE); 
                    keywords.Add("end", CqlParser.END);
                    keywords.Add("escape", CqlParser.ESCAPE);
                    keywords.Add("except", CqlParser.EXCEPT);
                    keywords.Add("exists", CqlParser.EXISTS); 
                    keywords.Add("flatten", CqlParser.FLATTEN);
                    keywords.Add("from", CqlParser.FROM); 
                    keywords.Add("full", CqlParser.FULL); 
                    keywords.Add("group", CqlParser.GROUP);
                    keywords.Add("having", CqlParser.HAVING); 
                    keywords.Add("in", CqlParser.IN);
                    keywords.Add("inner", CqlParser.INNER);
                    keywords.Add("intersect", CqlParser.INTERSECT);
                    keywords.Add("is", CqlParser.IS); 
                    keywords.Add("join", CqlParser.JOIN);
                    keywords.Add("key", CqlParser.KEY); 
                    keywords.Add("left", CqlParser.LEFT); 
                    keywords.Add("like", CqlParser.LIKE);
                    keywords.Add("limit", CqlParser.LIMIT); 
                    keywords.Add("multiset", CqlParser.MULTISET);
                    keywords.Add("navigate", CqlParser.NAVIGATE);
                    keywords.Add("not", CqlParser.NOT);
                    keywords.Add("null", CqlParser.NULL); 
                    keywords.Add("of", CqlParser.OF);
                    keywords.Add("oftype", CqlParser.OFTYPE); 
                    keywords.Add("on", CqlParser.ON); 
                    keywords.Add("only", CqlParser.ONLY);
                    keywords.Add("or", CqlParser.OR); 
                    keywords.Add("order", CqlParser.ORDER);
                    keywords.Add("outer", CqlParser.OUTER);
                    keywords.Add("overlaps", CqlParser.OVERLAPS);
                    keywords.Add("ref", CqlParser.REF); 
                    keywords.Add("relationship", CqlParser.RELATIONSHIP);
                    keywords.Add("right", CqlParser.RIGHT); 
                    keywords.Add("row", CqlParser.ROW); 
                    keywords.Add("select", CqlParser.SELECT);
                    keywords.Add("set", CqlParser.SET); 
                    keywords.Add("skip", CqlParser.SKIP);
                    keywords.Add("then", CqlParser.THEN);
                    keywords.Add("top", CqlParser.TOP);
                    keywords.Add("treat", CqlParser.TREAT); 
                    keywords.Add("union", CqlParser.UNION);
                    keywords.Add("using", CqlParser.USING); 
                    keywords.Add("value", CqlParser.VALUE); 
                    keywords.Add("when", CqlParser.WHEN);
                    keywords.Add("where", CqlParser.WHERE); 
                    keywords.Add("with", CqlParser.WITH);
                    _keywords = keywords;
                    #endregion
                } 
                return _keywords;
            } 
 
        }
 
        private static HashSet InternalInvalidAliasNameDictionary
        {
            get
            { 
                if (null == _invalidAliasName)
                { 
                    #region Invalid Aliases 
                    HashSet invalidAliasName = new HashSet(_stringComparer);
                    invalidAliasName.Add("all"); 
                    invalidAliasName.Add("and");
                    invalidAliasName.Add("apply");
                    invalidAliasName.Add("as");
                    invalidAliasName.Add("asc"); 
                    invalidAliasName.Add("between");
                    invalidAliasName.Add("by"); 
                    invalidAliasName.Add("case"); 
                    invalidAliasName.Add("cast");
                    invalidAliasName.Add("collate"); 
                    invalidAliasName.Add("createref");
                    invalidAliasName.Add("deref");
                    invalidAliasName.Add("desc");
                    invalidAliasName.Add("distinct"); 
                    invalidAliasName.Add("element");
                    invalidAliasName.Add("else"); 
                    invalidAliasName.Add("end"); 
                    invalidAliasName.Add("escape");
                    invalidAliasName.Add("except"); 
                    invalidAliasName.Add("exists");
                    invalidAliasName.Add("flatten");
                    invalidAliasName.Add("from");
                    invalidAliasName.Add("group"); 
                    invalidAliasName.Add("having");
                    invalidAliasName.Add("in"); 
                    invalidAliasName.Add("inner"); 
                    invalidAliasName.Add("intersect");
                    invalidAliasName.Add("is"); 
                    invalidAliasName.Add("join");
                    invalidAliasName.Add("like");
                    invalidAliasName.Add("multiset");
                    invalidAliasName.Add("navigate"); 
                    invalidAliasName.Add("not");
                    invalidAliasName.Add("null"); 
                    invalidAliasName.Add("of"); 
                    invalidAliasName.Add("oftype");
                    invalidAliasName.Add("on"); 
                    invalidAliasName.Add("only");
                    invalidAliasName.Add("or");
                    invalidAliasName.Add("overlaps");
                    invalidAliasName.Add("ref"); 
                    invalidAliasName.Add("relationship");
                    invalidAliasName.Add("select"); 
                    invalidAliasName.Add("set"); 
                    invalidAliasName.Add("then");
                    invalidAliasName.Add("treat"); 
                    invalidAliasName.Add("union");
                    invalidAliasName.Add("using");
                    invalidAliasName.Add("when");
                    invalidAliasName.Add("where"); 
                    invalidAliasName.Add("with");
                    _invalidAliasName = invalidAliasName; 
                    #endregion 
                }
                return _invalidAliasName; 
            }
        }

        private static Dictionary InternalOperatorDictionary 
        {
            get 
            { 
                if (null == _operators)
                { 
                    #region Initializes operator dictionary
                    Dictionary operators = new Dictionary(16, _stringComparer);
                    operators.Add("==", CqlParser.OP_EQ);
                    operators.Add("!=", CqlParser.OP_NEQ); 
                    operators.Add("<>", CqlParser.OP_NEQ);
                    operators.Add("<", CqlParser.OP_LT); 
                    operators.Add("<=", CqlParser.OP_LE); 
                    operators.Add(">", CqlParser.OP_GT);
                    operators.Add(">=", CqlParser.OP_GE); 
                    operators.Add("&&", CqlParser.AND);
                    operators.Add("||", CqlParser.OR);
                    operators.Add("!", CqlParser.NOT);
                    operators.Add("+", CqlParser.PLUS); 
                    operators.Add("-", CqlParser.MINUS);
                    operators.Add("*", CqlParser.STAR); 
                    operators.Add("/", CqlParser.FSLASH); 
                    operators.Add("%", CqlParser.PERCENT);
                    _operators = operators; 
                    #endregion
                }
                return _operators;
            } 
        }
 
        private static Dictionary InternalPunctuatorDictionary 
        {
            get 
            {
                if (null == _punctuators)
                {
                    #region Initializes punctuators dictionary 
                    Dictionary punctuators = new Dictionary(16, _stringComparer);
                    punctuators.Add(",", CqlParser.COMMA); 
                    punctuators.Add(":", CqlParser.COLON); 
                    punctuators.Add(".", CqlParser.DOT);
                    punctuators.Add("?", CqlParser.QMARK); 
                    punctuators.Add("(", CqlParser.L_PAREN);
                    punctuators.Add(")", CqlParser.R_PAREN);
                    punctuators.Add("[", CqlParser.L_BRACE);
                    punctuators.Add("]", CqlParser.R_BRACE); 
                    punctuators.Add("{", CqlParser.L_CURLY);
                    punctuators.Add("}", CqlParser.R_CURLY); 
                    punctuators.Add(";", CqlParser.SCOLON); 
                    punctuators.Add("=", CqlParser.EQUAL);
                    _punctuators = punctuators; 
                    #endregion
                }
                return _punctuators;
            } 
        }
 
        ///  
        /// Initializes function keyword dictionary
        ///  
        private static HashSet InitializeFunctionKeywords()
        {
            HashSet functionKeywords = new HashSet(_stringComparer);
            functionKeywords.Add("left"); 
            functionKeywords.Add("right");
            return functionKeywords; 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner  [....]
// @backup [....] 
//--------------------------------------------------------------------- 

namespace System.Data.Common.EntitySql 
{
    using System;
    using System.Globalization;
    using System.Collections.Generic; 
    using System.Text.RegularExpressions;
    using System.Diagnostics; 
    using System.Text; 

    ///  
    /// Represents Cql scanner and helper functions.
    /// 
    internal sealed partial class CqlLexer
    { 
        static readonly StringComparer _stringComparer = StringComparer.OrdinalIgnoreCase;
        static Dictionary _keywords; 
        static HashSet _invalidAliasName; 
        static Dictionary _operators;
        static Dictionary _punctuators; 
        static HashSet _functionKeywords = InitializeFunctionKeywords();
        static Regex _reDateTimeValue;
        static Regex _reTimeValue;
        static Regex _reDateTimeOffsetValue; 
        private const string _datetimeValueRegularExpression = @"^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}([ ])+[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?$";
        private const string _timeValueRegularExpression = @"^[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?$"; 
        private const string _datetimeOffsetValueRegularExpression = @"^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2}([ ])+[0-9]{1,2}:[0-9]{1,2}(:[0-9]{1,2}(\.[0-9]{1,7})?)?([ ])*[\+-][0-9]{1,2}:[0-9]{1,2}$"; 

        private int _iPos; 
        private int _lineNumber;
        ParserOptions _parserOptions;
        private string _query;
        private bool _identifierState; 
        private bool _aliasIdentifierState;
 
        /// Defines the set of characters to be interpreted as mandatory line breaks 
        /// according to UNICODE 5.0, section 5.8 Newline Guidelines.These are 'mandatory'
        /// line breaks. We do not handle other 'line breaking opportunities'as defined by 
        /// UNICODE 5.0 since they are intended for presentation. The mandatory line break
        /// defines breaking opportunities that must not be ignored. For all practical purposes
        /// the interpretation of mandatory breaks determines the end of one line and consequently
        /// the start of the next line of query text. 
        /// NOTE that CR and CRLF is treated as a composite 'character' and was obviously and intentionaly
        /// omitted in the character set bellow. 
        static readonly Char[] _newLineCharacters = { '\u000A' , // LF - line feed 
                                                      '\u0085' , // NEL - next line
                                                      '\u000B' , // VT - vertical tab 
                                                      '\u2028' , // LS - line separator
                                                      '\u2029'   // PS - paragraph separator
                                                    };
 
        /// 
        /// Intializes scanner 
        ///  
        /// input query
        /// parser options 
        internal CqlLexer( string query, ParserOptions parserOptions )
            : this()
        {
            EntityUtil.CheckArgumentNull(query,"query"); 
            EntityUtil.CheckArgumentNull(parserOptions, "parserOptions");
 
            _query = query; 
            _parserOptions = parserOptions;
            yy_reader = new System.IO.StringReader(_query); 
        }

        /// 
        /// Creates a new token. 
        /// 
        /// tokenid 
        /// ast node 
        /// 
        static internal Token NewToken( short tokenId, AstNode tokenvalue ) 
        {
            return new Token(tokenId, tokenvalue);
        }
 
        /// 
        /// Creates a new token representing a terminal. 
        ///  
        /// tokenid
        /// lexical value 
        /// 
        static internal Token NewToken( short tokenId, TerminalToken termToken )
        {
            return new Token(tokenId, termToken); 
        }
 
        ///  
        /// Represents a token to be used in parser stack.
        ///  
        internal class Token
        {
            private short _tokenId;
            private object _tokenValue; 

            internal Token( short tokenId, AstNode tokenValue ) 
            { 
                _tokenId = tokenId;
                _tokenValue = tokenValue; 
            }

            internal Token( short tokenId, TerminalToken terminal )
            { 
                _tokenId = tokenId;
                _tokenValue = terminal; 
            } 

            internal short TokenId 
            {
                get { return _tokenId; }
            }
 
            internal object Value
            { 
                get { return _tokenValue; } 
            }
        } 

        /// 
        /// Represents a terminal token
        ///  
        internal class TerminalToken
        { 
            string _token; 
            int _iPos;
 
            internal TerminalToken( string token, int iPos )
            {
                _token = token;
                _iPos = iPos; 
            }
 
            internal int IPos 
            {
                get { return _iPos; } 
            }

            internal string Token
            { 
                get { return _token; }
            } 
        } 

        internal static class yy_translate 
        {
            internal static char translate( char c )
            #region TRANSLATE
            { 
                if (Char.IsWhiteSpace(c)||Char.IsControl(c))
                { 
                    if (IsNewLine(c)) 
                    {
                        return '\n'; 
                    }
                    return ' ';
                }
 
                if (c < 0x007F)
                { 
                    return c; 
                }
 
                if (Char.IsLetter(c)||Char.IsSymbol(c)||Char.IsNumber(c))
                {
                    return 'a';
                } 

                // 
                // otherwise pass dummy 'marker' char so as we can continue 'extracting' tokens. 
                //
                return '`'; 
            }
            #endregion
        }
 

        ///  
        /// Returns current lexeme 
        /// 
        internal string YYText 
        {
            get { return yytext(); }
        }
 
        /// 
        /// Returns current input position 
        ///  
        internal int IPos
        { 
            get { return _iPos; }
        }

        ///  
        /// Advances input position.
        ///  
        /// updated input position 
        internal int AdvanceIPos()
        { 
            _iPos += YYText.Length;
            return _iPos;
        }
 
        /// 
        /// returns true if given term is a eSql keyword 
        ///  
        /// 
        ///  
        internal static bool IsReservedKeyword( string term )
        {
            return CqlLexer.InternalKeywordDictionary.ContainsKey(term);
        } 

        ///  
        /// Map lexical symbols to respective identifier or kword. 
        /// 
        /// lexeme 
        /// Token
        internal Token MapIdentifierOrKeyword( string symbol )
        {
            if (symbol[0] == '[' && symbol.Length > 1) 
            {
                if (symbol[symbol.Length - 1] == ']') 
                { 
                    Identifier id = new Identifier(symbol, true, _query, _iPos);
                    id.ErrCtx.ErrorContextInfo = EntityRes.CtxEscapedIdentifier; 
                    return NewToken(CqlParser.ESCAPED_IDENTIFIER, id);
                }
                else
                { 
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifier(symbol), _iPos);
                } 
            } 

            // look ahead to see if keyword could be used as function 
            yy_mark_end();
            Char ch = yy_advance();
            while (ch != YY_EOF && (Char.IsWhiteSpace(ch) || IsNewLine(ch)))
            { 
                ch = yy_advance();
            } 
            yy_to_mark(); 

            if (ch == '(' && _functionKeywords.Contains(symbol)) 
            {
                return NewToken(CqlParser.IDENTIFIER, new Identifier(symbol, false, _query, _iPos));
            }
 
            if ((!_identifierState && !_aliasIdentifierState && ch != '.') && CqlLexer.InternalKeywordDictionary.ContainsKey(symbol))
            { 
                ResetKeywordAsIdentifierState(); 

                if (symbol.Equals("AS", StringComparison.OrdinalIgnoreCase)) 
                {
                    _aliasIdentifierState = true;
                }
 
                return NewToken(CqlLexer.InternalKeywordDictionary[symbol], new TerminalToken(symbol, _iPos));
            } 
            else 
            {
                ResetKeywordAsIdentifierState(); 

                if (InternalInvalidAliasNameDictionary.Contains(symbol))
                {
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidAliasName(symbol), _iPos); 
                }
 
                Identifier id = new Identifier(symbol, false, _query, _iPos); 
                id.ErrCtx.ErrorContextInfo = EntityRes.CtxIdentifier;
                return NewToken(CqlParser.IDENTIFIER, id); 
            }
        }

        ///  
        /// Maps operator to respective token
        ///  
        /// operator lexeme 
        /// Token
        internal Token MapOperator( string oper ) 
        {
            if (InternalOperatorDictionary.ContainsKey(oper))
            {
                return NewToken(InternalOperatorDictionary[oper], new TerminalToken(oper, _iPos)); 
            }
            else 
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidOperatorSymbol, _iPos);
            } 
        }

        /// 
        /// Maps puctuator to respective token 
        /// 
        /// punctuator 
        /// Token 
        internal Token MapPunctuator( string punct )
        { 
            if (InternalPunctuatorDictionary.ContainsKey(punct))
            {
                ResetKeywordAsIdentifierState();
 
                if (punct.Equals(".", StringComparison.OrdinalIgnoreCase))
                { 
                    _identifierState = true; 
                }
 
                return NewToken(InternalPunctuatorDictionary[punct], new TerminalToken(punct, _iPos));
            }
            else
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidPunctuatorSymbol, _iPos);
            } 
        } 

        ///  
        /// Maps double quoted string to ids or literal strings
        /// 
        /// 
        /// Token 
        internal Token MapDoubleQuotedString( string symbol )
        { 
            if (_parserOptions.AllowQuotedIdentifiers) 
            {
                return NewToken(CqlParser.ESCAPED_IDENTIFIER, new Identifier(symbol, true, _query, _iPos)); 
            }
            else
            {
                LiteralKind literalKind = LiteralKind.NonUnicodeString; 
                if ('N' == symbol[0])
                { 
                    literalKind = LiteralKind.UnicodeString; 
                }
 
                return NewToken(CqlParser.LITERAL, new Literal(symbol, literalKind, _query, _iPos));
            }
        }
 
        /// 
        /// Creates literal token 
        ///  
        /// literal
        /// literal kind 
        /// Literal Token
        internal Token NewLiteralToken( string literal, LiteralKind literalKind )
        {
            string literalValue = literal; 
            switch (literalKind)
            { 
                case LiteralKind.Binary: 
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidBinaryValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("binary", literalValue), _iPos);
                    }
                    break; 

                case LiteralKind.String: 
                    literalKind = LiteralKind.NonUnicodeString; 
                    if ('N' == literal[0])
                    { 
                        literalKind = LiteralKind.UnicodeString;
                    }
                    break;
 
                case LiteralKind.DateTime:
                    literalValue = GetLiteralSingleQuotePayload(literal); 
                    if (!IsValidDateTimeValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("datetime", literalValue), _iPos); 
                    }
                    break;

                case LiteralKind.Time: 
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidTimeValue(literalValue)) 
                    { 
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("time", literalValue), _iPos);
                    } 
                    break;
                case LiteralKind.DateTimeOffset:
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidDateTimeOffsetValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("datetimeoffset", literalValue), _iPos); 
                    } 
                    break;
 

                case LiteralKind.Guid:
                    literalValue = GetLiteralSingleQuotePayload(literal);
                    if (!IsValidGuidValue(literalValue)) 
                    {
                        throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidLiteralFormat("guid", literalValue), _iPos); 
                    } 
                    break;
            } 

            return NewToken(CqlParser.LITERAL, new Literal(literalValue, literalKind, _query, _iPos));
        }
 
        /// 
        /// Creates parameter token 
        ///  
        /// param
        /// Parameter Token 
        internal Token NewParameterToken( string param )
        {
            return NewToken(CqlParser.PARAMETER, new Parameter(param, _query, _iPos));
        } 

        ///  
        /// handles escaped identifiers 
        /// ch will always be translated i.e. normalized.
        ///  
        /// 
        internal Token HandleEscapedIdentifiers()
        {
            char ch = YYText[0]; 
            int count = -1;
            while (ch != YY_EOF) 
            { 
                if (ch == YY_EOF)
                { 
                    throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifierEOF, _iPos);
                }
                else if (ch == ']')
                { 
                    count++;
                    yy_mark_end(); 
                    ch = yy_advance(); 
                    if (ch == ']') count--;
                    if (ch != ']') break; 
                }
                ch = yy_advance();
            }
 
            if (0 != count)
            { 
                throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.InvalidEscapedIdentifierUnbalanced(YYText), _iPos); 
            }
 
            yy_to_mark();

            ResetKeywordAsIdentifierState();
 
            return MapIdentifierOrKeyword(YYText.Replace("]]","]"));
        } 
 
        static internal bool IsLetterOrDigitOrUnderscore( string symbol , out bool isIdentifierASCII )
        { 
            isIdentifierASCII = true;
            for (int i = 0 ; i < symbol.Length ; i++)
            {
                isIdentifierASCII = isIdentifierASCII && symbol[i] < 0x80; 
                if (!isIdentifierASCII && !IsLetter(symbol[i]) && !IsDigit(symbol[i]) && (symbol[i] != '_'))
                { 
                    return false; 
                }
            } 
            return true;
        }

        private void ResetKeywordAsIdentifierState() 
        {
            _identifierState = _aliasIdentifierState = false; 
        } 

        private void ResetIndetifierState() 
        {
            _identifierState = false;
        }
 
        static private bool IsLetter( char c )
        { 
            return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); 
        }
 
        static private bool IsDigit( char c )
        {
            return (c >= '0' && c <= '9');
        } 

        static bool isHexDigit( char c ) 
        { 
            return (IsDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'));
        } 

        /// 
        /// Returns true if given char is a new line character defined by
        /// UNICODE 5.0, section 5.8 Newline Guidelines. 
        /// These are 'mandatory' line breaks. NOTE that CRLF is treated as a
        /// composite 'character' and was intentionaly omitted in the character set bellow. 
        ///  
        /// 
        ///  
        internal static bool IsNewLine(Char c)
        {
            for(int i=0; i < _newLineCharacters.Length; i++)
            { 
                if ( c == _newLineCharacters[i] )
                { 
                    return true; 
                }
            } 
            return false;
        }

        ///  
        /// extracts single quoted literal 'payload'. literal MUST BE normalized.
        ///  
        ///  
        /// 
        static private string GetLiteralSingleQuotePayload(string literal) 
        {
            Debug.Assert(-1 != literal.IndexOf('\''), "quoted literal value must have single quotes");
            Debug.Assert(-1 != literal.LastIndexOf('\''), "quoted literal value must have single quotes");
            Debug.Assert(literal.IndexOf('\'') != literal.LastIndexOf('\''), "quoted literal value must have 2 single quotes"); 
            Debug.Assert(literal.Split(new char[] { '\'' }).Length == 3, "quoted literal value must have 2 single quotes");
 
            // NOTE: this is not a precondition validation. This validation is for security purposes based on the 
            // paranoid assumption that all input is evil. we should not see this exception under normal
            // conditions. 
            if ((literal.Split(new char[] { '\'' }).Length != 3) || (-1 == literal.IndexOf('\'')) || (-1 == literal.LastIndexOf('\'')))
            {
                throw EntityUtil.EntitySqlError(System.Data.Entity.Strings.MalformedSingleQuotePayload);
            } 

            int startIndex = literal.IndexOf('\''); 
 
            string literalPayload = literal.Substring(startIndex + 1, literal.Length - (startIndex + 2));
 
            Debug.Assert(literalPayload.IndexOf('\'') == -1, "quoted literal payload must not have single quotes");
            Debug.Assert(literalPayload.LastIndexOf('\'') == -1, "quoted literal payload must not have single quotes");

            // NOTE: this is not a precondition validation. This validation is for security purposes based on the 
            // paranoid assumption that all input is evil. we should not see this exception under normal
            // conditions. 
            if (literalPayload.Split(new char[] { '\'' }).Length != 1) 
            {
                throw EntityUtil.EntitySqlError(System.Data.Entity.Strings.MalformedSingleQuotePayload); 
            }

            return literalPayload;
        } 

        ///  
        /// returns true if guid literal value format is valid 
        /// 
        ///  
        /// 
        static bool IsValidGuidValue( string guidValue )
        {
            int startIndex = 0; 
            int endIndex = guidValue.Length - 1;
            if ((endIndex - startIndex) + 1 != 36) 
            { 
                return false;
            } 

            int i = 0;
            bool bValid = true;
            while (bValid && i < 36) 
            {
                if ((i == 8) || (i == 13) || (i == 18) || (i == 23)) 
                { 
                    bValid = (guidValue[startIndex + i] == '-');
                } 
                else
                {
                    bValid = isHexDigit(guidValue[startIndex + i]);
                } 
                i++;
            } 
            return bValid; 
        }
 
        /// 
        /// returns true if binary literal value format is valid
        /// 
        ///  
        /// 
        static bool IsValidBinaryValue( string binaryValue ) 
        { 
            Debug.Assert(null != binaryValue, "binaryValue must not be null");
 
            if (String.IsNullOrEmpty(binaryValue))
            {
                return true;
            } 

            int i = 0; 
            bool bValid = binaryValue.Length > 0; 
            while (bValid && i < binaryValue.Length)
            { 
                bValid = isHexDigit(binaryValue[i++]);
            }

            return bValid; 
        }
 
        ///  
        /// Returns true if datetime literal value format is valid
        /// allowed format is: dddd-d?d-d?d{space}+d?d:d?d(:d?d(.d?d?d)?)? 
        /// where d is any decimal digit.
        /// 
        /// 
        ///  
        static bool IsValidDateTimeValue( string datetimeValue )
        { 
            if (null == _reDateTimeValue) 
            {
                _reDateTimeValue = new Regex(_datetimeValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant); 
            }
            return _reDateTimeValue.IsMatch(datetimeValue);
        }
 
        /// 
        /// Returns true if time literal value format is valid 
        /// allowed format is: +d?d:d?d(:d?d(.d?d?d)?)? 
        /// where d is any decimal digit.
        ///  
        /// 
        /// 
        static bool IsValidTimeValue(string timeValue)
        { 
            if (null == _reTimeValue)
            { 
                _reTimeValue = new Regex(_timeValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant); 
            }
            return _reTimeValue.IsMatch(timeValue); 
        }

        /// 
        /// Returns true if datetimeoffset literal value format is valid 
        /// allowed format is: dddd-d?d-d?d{space}+d?d:d?d(:d?d(.d?d?d)?)?([+-]d?d:d?d)?
        /// where d is any decimal digit. 
        ///  
        /// 
        ///  
        static bool IsValidDateTimeOffsetValue(string datetimeOffsetValue)
        {
            if (null == _reDateTimeOffsetValue)
            { 
                _reDateTimeOffsetValue = new Regex(_datetimeOffsetValueRegularExpression, RegexOptions.Singleline | RegexOptions.CultureInvariant);
            } 
            return _reDateTimeOffsetValue.IsMatch(datetimeOffsetValue); 
        }
 

        private static Dictionary InternalKeywordDictionary
        {
            get 
            {
                if (null == _keywords) 
                { 
                    #region eSql Keywords
                    Dictionary keywords = new Dictionary(60, _stringComparer); 
                    keywords.Add("all", CqlParser.ALL);
                    keywords.Add("and", CqlParser.AND);
                    keywords.Add("anyelement", CqlParser.ANYELEMENT);
                    keywords.Add("apply", CqlParser.APPLY); 
                    keywords.Add("as", CqlParser.AS);
                    keywords.Add("asc", CqlParser.ASC); 
                    keywords.Add("between", CqlParser.BETWEEN); 
                    keywords.Add("by", CqlParser.BY);
                    keywords.Add("case", CqlParser.CASE); 
                    keywords.Add("cast", CqlParser.CAST);
                    keywords.Add("collate", CqlParser.COLLATE);
                    keywords.Add("createref", CqlParser.CREATEREF);
                    keywords.Add("cross", CqlParser.CROSS); 
                    keywords.Add("deref", CqlParser.DEREF);
                    keywords.Add("desc", CqlParser.DESC); 
                    keywords.Add("distinct", CqlParser.DISTINCT); 
                    keywords.Add("element", CqlParser.ELEMENT);
                    keywords.Add("else", CqlParser.ELSE); 
                    keywords.Add("end", CqlParser.END);
                    keywords.Add("escape", CqlParser.ESCAPE);
                    keywords.Add("except", CqlParser.EXCEPT);
                    keywords.Add("exists", CqlParser.EXISTS); 
                    keywords.Add("flatten", CqlParser.FLATTEN);
                    keywords.Add("from", CqlParser.FROM); 
                    keywords.Add("full", CqlParser.FULL); 
                    keywords.Add("group", CqlParser.GROUP);
                    keywords.Add("having", CqlParser.HAVING); 
                    keywords.Add("in", CqlParser.IN);
                    keywords.Add("inner", CqlParser.INNER);
                    keywords.Add("intersect", CqlParser.INTERSECT);
                    keywords.Add("is", CqlParser.IS); 
                    keywords.Add("join", CqlParser.JOIN);
                    keywords.Add("key", CqlParser.KEY); 
                    keywords.Add("left", CqlParser.LEFT); 
                    keywords.Add("like", CqlParser.LIKE);
                    keywords.Add("limit", CqlParser.LIMIT); 
                    keywords.Add("multiset", CqlParser.MULTISET);
                    keywords.Add("navigate", CqlParser.NAVIGATE);
                    keywords.Add("not", CqlParser.NOT);
                    keywords.Add("null", CqlParser.NULL); 
                    keywords.Add("of", CqlParser.OF);
                    keywords.Add("oftype", CqlParser.OFTYPE); 
                    keywords.Add("on", CqlParser.ON); 
                    keywords.Add("only", CqlParser.ONLY);
                    keywords.Add("or", CqlParser.OR); 
                    keywords.Add("order", CqlParser.ORDER);
                    keywords.Add("outer", CqlParser.OUTER);
                    keywords.Add("overlaps", CqlParser.OVERLAPS);
                    keywords.Add("ref", CqlParser.REF); 
                    keywords.Add("relationship", CqlParser.RELATIONSHIP);
                    keywords.Add("right", CqlParser.RIGHT); 
                    keywords.Add("row", CqlParser.ROW); 
                    keywords.Add("select", CqlParser.SELECT);
                    keywords.Add("set", CqlParser.SET); 
                    keywords.Add("skip", CqlParser.SKIP);
                    keywords.Add("then", CqlParser.THEN);
                    keywords.Add("top", CqlParser.TOP);
                    keywords.Add("treat", CqlParser.TREAT); 
                    keywords.Add("union", CqlParser.UNION);
                    keywords.Add("using", CqlParser.USING); 
                    keywords.Add("value", CqlParser.VALUE); 
                    keywords.Add("when", CqlParser.WHEN);
                    keywords.Add("where", CqlParser.WHERE); 
                    keywords.Add("with", CqlParser.WITH);
                    _keywords = keywords;
                    #endregion
                } 
                return _keywords;
            } 
 
        }
 
        private static HashSet InternalInvalidAliasNameDictionary
        {
            get
            { 
                if (null == _invalidAliasName)
                { 
                    #region Invalid Aliases 
                    HashSet invalidAliasName = new HashSet(_stringComparer);
                    invalidAliasName.Add("all"); 
                    invalidAliasName.Add("and");
                    invalidAliasName.Add("apply");
                    invalidAliasName.Add("as");
                    invalidAliasName.Add("asc"); 
                    invalidAliasName.Add("between");
                    invalidAliasName.Add("by"); 
                    invalidAliasName.Add("case"); 
                    invalidAliasName.Add("cast");
                    invalidAliasName.Add("collate"); 
                    invalidAliasName.Add("createref");
                    invalidAliasName.Add("deref");
                    invalidAliasName.Add("desc");
                    invalidAliasName.Add("distinct"); 
                    invalidAliasName.Add("element");
                    invalidAliasName.Add("else"); 
                    invalidAliasName.Add("end"); 
                    invalidAliasName.Add("escape");
                    invalidAliasName.Add("except"); 
                    invalidAliasName.Add("exists");
                    invalidAliasName.Add("flatten");
                    invalidAliasName.Add("from");
                    invalidAliasName.Add("group"); 
                    invalidAliasName.Add("having");
                    invalidAliasName.Add("in"); 
                    invalidAliasName.Add("inner"); 
                    invalidAliasName.Add("intersect");
                    invalidAliasName.Add("is"); 
                    invalidAliasName.Add("join");
                    invalidAliasName.Add("like");
                    invalidAliasName.Add("multiset");
                    invalidAliasName.Add("navigate"); 
                    invalidAliasName.Add("not");
                    invalidAliasName.Add("null"); 
                    invalidAliasName.Add("of"); 
                    invalidAliasName.Add("oftype");
                    invalidAliasName.Add("on"); 
                    invalidAliasName.Add("only");
                    invalidAliasName.Add("or");
                    invalidAliasName.Add("overlaps");
                    invalidAliasName.Add("ref"); 
                    invalidAliasName.Add("relationship");
                    invalidAliasName.Add("select"); 
                    invalidAliasName.Add("set"); 
                    invalidAliasName.Add("then");
                    invalidAliasName.Add("treat"); 
                    invalidAliasName.Add("union");
                    invalidAliasName.Add("using");
                    invalidAliasName.Add("when");
                    invalidAliasName.Add("where"); 
                    invalidAliasName.Add("with");
                    _invalidAliasName = invalidAliasName; 
                    #endregion 
                }
                return _invalidAliasName; 
            }
        }

        private static Dictionary InternalOperatorDictionary 
        {
            get 
            { 
                if (null == _operators)
                { 
                    #region Initializes operator dictionary
                    Dictionary operators = new Dictionary(16, _stringComparer);
                    operators.Add("==", CqlParser.OP_EQ);
                    operators.Add("!=", CqlParser.OP_NEQ); 
                    operators.Add("<>", CqlParser.OP_NEQ);
                    operators.Add("<", CqlParser.OP_LT); 
                    operators.Add("<=", CqlParser.OP_LE); 
                    operators.Add(">", CqlParser.OP_GT);
                    operators.Add(">=", CqlParser.OP_GE); 
                    operators.Add("&&", CqlParser.AND);
                    operators.Add("||", CqlParser.OR);
                    operators.Add("!", CqlParser.NOT);
                    operators.Add("+", CqlParser.PLUS); 
                    operators.Add("-", CqlParser.MINUS);
                    operators.Add("*", CqlParser.STAR); 
                    operators.Add("/", CqlParser.FSLASH); 
                    operators.Add("%", CqlParser.PERCENT);
                    _operators = operators; 
                    #endregion
                }
                return _operators;
            } 
        }
 
        private static Dictionary InternalPunctuatorDictionary 
        {
            get 
            {
                if (null == _punctuators)
                {
                    #region Initializes punctuators dictionary 
                    Dictionary punctuators = new Dictionary(16, _stringComparer);
                    punctuators.Add(",", CqlParser.COMMA); 
                    punctuators.Add(":", CqlParser.COLON); 
                    punctuators.Add(".", CqlParser.DOT);
                    punctuators.Add("?", CqlParser.QMARK); 
                    punctuators.Add("(", CqlParser.L_PAREN);
                    punctuators.Add(")", CqlParser.R_PAREN);
                    punctuators.Add("[", CqlParser.L_BRACE);
                    punctuators.Add("]", CqlParser.R_BRACE); 
                    punctuators.Add("{", CqlParser.L_CURLY);
                    punctuators.Add("}", CqlParser.R_CURLY); 
                    punctuators.Add(";", CqlParser.SCOLON); 
                    punctuators.Add("=", CqlParser.EQUAL);
                    _punctuators = punctuators; 
                    #endregion
                }
                return _punctuators;
            } 
        }
 
        ///  
        /// Initializes function keyword dictionary
        ///  
        private static HashSet InitializeFunctionKeywords()
        {
            HashSet functionKeywords = new HashSet(_stringComparer);
            functionKeywords.Add("left"); 
            functionKeywords.Add("right");
            return functionKeywords; 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK