Пример #1
0
        public int keywordFromText(string name)
        {
            // (My)SQL only uses ASCII chars for keywords so we can do a simple downcase here for comparison.
            string transformed;

            transformed = name.ToLower();

            if (!MySQLSymbolInfo.isKeyword(transformed, MySQLSymbolInfo.numberToVersion(serverVersion)))
            {
                return(int.MaxValue - 1); // INVALID_INDEX alone can be interpreted as EOF.
            }
            // Generate string -> enum value map, if not yet done.
            if (!_symbols.Any())
            {
                Vocabulary vocabulary = this.Vocabulary as Vocabulary;
                var        max        = vocabulary.getMaxTokenType();
                for (var i = 0; i <= max; ++i)
                {
                    _symbols[vocabulary.GetSymbolicName(i)] = i;
                }
            }

            // Here we know for sure we got a keyword.
            bool found = _symbols.TryGetValue(transformed, out int symbol);

            if (!found)
            {
                return(int.MaxValue - 1);
            }
            return(symbol);
        }
Пример #2
0
        public bool isIdentifier(int type)
        {
            if ((type == MySQLLexer.IDENTIFIER) || (type == MySQLLexer.BACK_TICK_QUOTED_ID))
            {
                return(true);
            }

            // Double quoted text represents identifiers only if the ANSI QUOTES sql mode is active.
            if (((sqlMode & SqlMode.AnsiQuotes) != 0) && (type == MySQLLexer.DOUBLE_QUOTED_TEXT))
            {
                return(true);
            }

            string symbol = Vocabulary.GetSymbolicName(type);

            if (!string.IsNullOrEmpty(symbol) && !MySQLSymbolInfo.isReservedKeyword(symbol, MySQLSymbolInfo.numberToVersion(serverVersion)))
            {
                return(true);
            }

            return(false);
        }