Exemplo n.º 1
0
        protected virtual void ParseQuotedString(TokenWriter tokenWriter, BasicReader reader)
        {
            // record position for later
            int pos = reader.Position;

            // skip leading quote
            char quoteChar = reader.Read();

            StringBuilder val = new StringBuilder();

            // escape char + quote char
            char[] stopChars = new[] { '`', quoteChar };

            do
            {
                string tmp = reader.ReadUntil(stopChars.Contains);
                val.Append(tmp);

                char chr;
                if (reader.TryPeek(out chr))
                {
                    if (chr == '`')
                    {
                        // escape char, so skip one
                        reader.Read();

                        // then process the next
                        val.Append(reader.Read());
                    }
                    else if (chr == quoteChar)
                    {
                        break; // exit
                    }
                }
                else
                {
                    throw new Exception("Premature end of stream");
                }
            }
            while (!reader.Eof);

            // skip trailing quote
            reader.Skip(1);

            tokenWriter.Add(new Token(TokenType.StringValue, val.ToString(), pos, reader.Position - pos));
        }
Exemplo n.º 2
0
        protected virtual void ParseUnquotedString(TokenWriter tokenWriter, BasicReader reader)
        {
            // record position for later
            int pos = reader.Position;

            StringBuilder val = new StringBuilder();

            // escape char + stop chars
            char[] stopChars = new[] { '`', ' ', '\t', '\r', '\n', '}', ')', '=' };

            do
            {
                string tmp = reader.ReadUntil(stopChars.Contains);
                val.Append(tmp);

                char chr;
                if (reader.TryPeek(out chr))
                {
                    if (chr == '`')
                    {
                        // escape char, so skip one
                        reader.Read();

                        // then process the next
                        val.Append(reader.Read());
                    }
                    else
                    {
                        break; // exit
                    }
                }
            }
            while (!reader.Eof);

            tokenWriter.Add(new Token(TokenType.StringValue, val.ToString(), pos, reader.Position - pos));
        }
Exemplo n.º 3
0
        protected virtual void ParseParameter(TokenWriter tokenWriter, BasicReader reader)
        {
            if (!reader.StartsWith(ParameterIndicator))
                throw new InvalidOperationException(String.Format("Cannot parse paramer, expected {0}.", ParameterIndicator));

            reader.Skip(1);

            int startPos = reader.Position;
            StringBuilder name = new StringBuilder();
            char next;
            while (reader.TryPeek(out next) && next != ':' && !char.IsWhiteSpace(next))
            {
                name.Append(reader.Read());
            }

            if (!reader.Eof && next == ':')
            {
                tokenWriter.Add(new Token(TokenType.SwitchParameter, name.ToString(), startPos, reader.Position - startPos));
                reader.Skip(1); // skip the :
                this.ParseOne(tokenWriter, reader);
            }
            else
                tokenWriter.Add(new Token(TokenType.ParameterName, name.ToString(), startPos, reader.Position - startPos));
        }