Ejemplo n.º 1
0
        internal SqlTokenInfo(SqlTokenKind kind, char value)
        {
            Kind = kind;
            ReadOnlySpan <char> ca = stackalloc char[1] {
                value
            };

            Value = new string(ca);
        }
Ejemplo n.º 2
0
 internal SqlTokenInfo(SqlTokenKind kind, ReadOnlySpan <char> value)
 {
     Kind  = kind;
     Value = new string(value);
 }
Ejemplo n.º 3
0
 internal SqlTokenInfo(SqlTokenKind kind, StringBuilder value)
 {
     Kind  = kind;
     Value = value?.ToString();
 }
Ejemplo n.º 4
0
 internal SqlTokenInfo(SqlTokenKind kind, string value)
 {
     Kind  = kind;
     Value = value;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Tokenizes the provided sql statement.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="skipSundry">Do not emit sundry tokens (such as comments and whitespace) in the output.</param>
        private static IReadOnlyCollection <SqlTokenInfo> Tokenize(SqlCharReader reader, bool skipSundry)
        {
            Debug.Assert(!(reader is null));
            Span <char> peekBuffer = stackalloc char[2];

            var tokens = new List <SqlTokenInfo>();

            while (true)
            {
                reader.FillLength(peekBuffer, peekBuffer.Length, out var peekLength);
                if (peekLength <= 0)
                {
                    break;
                }

                SqlTokenInfo token;
                SqlTokenKind kind = Peek(peekBuffer.Slice(0, peekLength));
                switch (kind)
                {
                case SqlTokenKind.Whitespace:
                    token = ReadWhitespace(peekBuffer, peekLength, reader, skipSundry);
                    if (skipSundry)
                    {
                        continue;
                    }
                    break;

                case SqlTokenKind.LineComment:
                    token = ReadLineComment(reader, skipSundry);
                    if (skipSundry)
                    {
                        continue;
                    }
                    break;

                case SqlTokenKind.BlockComment:
                    token = ReadBlockComment(reader, skipSundry);
                    if (skipSundry)
                    {
                        continue;
                    }
                    break;

                case SqlTokenKind.Literal:
                    token = ReadLiteral(peekBuffer, peekLength, reader);
                    break;

                case SqlTokenKind.Symbol:
                    token = ReadSymbol(peekBuffer, peekLength, reader);
                    break;

                case SqlTokenKind.SquareString:
                    token = ReadSquareString(peekBuffer, peekLength, reader);
                    break;

                case SqlTokenKind.QuotedString:
                    token = ReadQuotedString(peekBuffer, peekLength, reader);
                    break;

                default:
                    throw new InvalidOperationException($"Unknown {nameof(SqlTokenKind)}: {kind}");
                }

                tokens.Add(token);
            }

            return(tokens);
        }
Ejemplo n.º 6
0
 internal SqlTokenInfo(SqlTokenKind kind, char[] value, int offset, int count)
 {
     Kind  = kind;
     Value = new string(value, offset, count);
 }
Ejemplo n.º 7
0
 internal SqlTokenInfo(SqlTokenKind kind, params char[] value)
 {
     Kind  = kind;
     Value = value == null ? null : new string(value);
 }