Пример #1
0
        static CommandLine()
        {
            using (StringReader stringReader = new StringReader(Environment.CommandLine))
            using (BasicReader reader = new BasicReader(stringReader, StringComparer.Ordinal, disposeReader: false))
            {
                // just in case
                reader.AdvanceWhitespace();
                char first;
                if (reader.TryPeek(out first))
                {
                    if (first == '"')
                    {
                        reader.Skip(1);
                        Path = reader.ReadUntil(c => c == '"');
                        reader.Skip(1);
                    }
                    else
                        Path = reader.ReadUntil(char.IsWhiteSpace);

                    // skip whitespace
                    if (!reader.Eof)
                        reader.Skip(1);

                    // dirty hack to read to eof
                    Arguments = reader.ReadUntil(c => false);
                }
            }
        }
Пример #2
0
        private void ParseOne(TokenWriter tokenWriter, BasicReader reader)
        {
            reader.AdvanceWhitespace();

            if (reader.StartsWith(ParameterIndicator))
                this.ParseParameter(tokenWriter, reader);
            else
                this.ParseValue(tokenWriter, reader);
        }
Пример #3
0
        protected virtual void ParseDictionary(TokenWriter tokenWriter, BasicReader reader)
        {
            if (!reader.StartsWith(DictionaryStart))
                throw new InvalidOperationException(String.Format("Cannot parse dictionary, expected {0}.", DictionaryStart));

            tokenWriter.Add(new Token(TokenType.DictionaryStart, DictionaryStart, reader.Position, DictionaryStart.Length));                    

            // skip
            reader.Skip(DictionaryStart.Length);

            while (!reader.StartsWith(DictionaryEnd) && !reader.Eof)
            {
                // trim ws
                reader.AdvanceWhitespace();

                // parse dict-key
                this.ParseValue(tokenWriter, reader);

                // trim ws
                reader.AdvanceWhitespace();

                // read seperator
                if (reader.StartsWith(DictionaryValueSeperator))
                {
                    // we no longer emit these tokens
                    ////tokenWriter.Add(new Token
                    ////                    {
                    ////                        Position = reader.Position,
                    ////                        Length = DictionaryValueSeperator.Length,
                    ////                        Type = TokenType.DictionaryValueSeperator,
                    ////                        Value = DictionaryValueSeperator
                    ////                    });

                    reader.Skip(DictionaryValueSeperator.Length);
                }
                else
                {
                    throw new Exception("Expected key seperator");
                }

                // trim ws
                reader.AdvanceWhitespace();

                // parse dict-value
                this.ParseValue(tokenWriter, reader);

                // trim ws
                reader.AdvanceWhitespace();

                // read seperator
                if (reader.StartsWith(DictionaryKeySeperator))
                {
                    // we no longer emit these tokens
                    ////tokenWriter.Add(new Token
                    ////                    {
                    ////                        Position = reader.Position,
                    ////                        Length = DictionaryKeySeperator.Length,
                    ////                        Type = TokenType.DictionaryKeySeperator,
                    ////                        Value = DictionaryKeySeperator
                    ////                    });

                    reader.Skip(DictionaryKeySeperator.Length);
                }
                else
                    break;
            }

            if (!reader.Eof && reader.StartsWith(DictionaryEnd))
            {
                tokenWriter.Add(new Token(TokenType.DictionaryEnd, DictionaryEnd, reader.Position, DictionaryEnd.Length));
                                    
                reader.Skip(DictionaryEnd.Length);
            }
            else
            {
                throw new Exception("Expected end of dictionary");
            }
        }
Пример #4
0
        protected virtual void ParseList(TokenWriter tokenWriter, BasicReader reader)
        {
            if (!reader.StartsWith(ListStart))
                throw new InvalidOperationException(String.Format("Cannot parse list, expected {0}.", ListStart));


            tokenWriter.Add(new Token(TokenType.ListStart, ListStart, reader.Position, ListStart.Length));
            
            // skip it
            reader.Skip(ListStart.Length);

            // trim ws
            reader.AdvanceWhitespace();

            while (!reader.StartsWith(ListEnd) && !reader.Eof)
            {
                // parse list value
                this.ParseValue(tokenWriter, reader);

                // trim ws
                reader.AdvanceWhitespace();

                // read seperator
                if (reader.StartsWith(ListValueSeperator))
                {
                    // don't output these anymore
                    ////tokenWriter.Add(new Token
                    ////                    {
                    ////                        Position = reader.Position,
                    ////                        Length = ListValueSeperator.Length,
                    ////                        Type = TokenType.ListValueSeperator,
                    ////                        Value = ListValueSeperator
                    ////                    });

                    reader.Skip(ListValueSeperator.Length);
                }
                else if (!reader.StartsWith(ListEnd))
                {
                    throw new Exception("Expected value seperator or end of list.");
                }

                // trim ws
                reader.AdvanceWhitespace();
            }



            if (reader.StartsWith(ListEnd))
            {
                tokenWriter.Add(new Token(TokenType.ListEnd, ListEnd, reader.Position, ListEnd.Length));
                    
                reader.Skip(ListEnd.Length);
            }
            else
            {
                throw new Exception("Expected end of list");
            }
        }
Пример #5
0
        protected virtual void ParseDictionary(TokenWriter tokenWriter, BasicReader reader)
        {
            if (!reader.StartsWith(DictionaryStart))
                throw new InvalidOperationException($"Cannot parse dictionary, expected {DictionaryStart}.");

            tokenWriter.Add(new Token(TokenType.DictionaryStart, DictionaryStart, reader.Position, DictionaryStart.Length));

            // skip
            reader.Skip(DictionaryStart.Length);

            while (!reader.StartsWith(DictionaryEnd) && !reader.Eof)
            {
                // trim ws
                reader.AdvanceWhitespace();

                // parse dict-key
                this.ParseValue(tokenWriter, reader);

                // trim ws
                reader.AdvanceWhitespace();

                // read seperator
                if (reader.StartsWith(DictionaryValueSeperator))
                    reader.Skip(DictionaryValueSeperator.Length);
                else
                    throw new Exception("Expected key seperator");

                // trim ws
                reader.AdvanceWhitespace();

                // parse dict-value
                this.ParseValue(tokenWriter, reader);

                // trim ws
                reader.AdvanceWhitespace();

                // read seperator
                if (reader.StartsWith(DictionaryKeySeperator))
                    reader.Skip(DictionaryKeySeperator.Length);
                else
                    break;
            }

            if (!reader.Eof && reader.StartsWith(DictionaryEnd))
            {
                tokenWriter.Add(new Token(TokenType.DictionaryEnd, DictionaryEnd, reader.Position, DictionaryEnd.Length));

                reader.Skip(DictionaryEnd.Length);
            }
            else
                throw new Exception("Expected end of dictionary");
        }