Esempio n. 1
0
 public Parser(Token[] tokens, List<Option> options)
 {
     this.tokens = new Tokens(tokens);
     this.options = options;
     Parameters = new List<string>();
     ParsedOption = new List<Option>();
 }
Esempio n. 2
0
        void ParseOption(Token token)
        {
            lastOption = GetOptionByToken(token);
            Token nextToken = tokens.NextToken();

            if (nextToken == null)
            {
                CheckSaturation(lastOption);
                lastOption.AddArgumentValue("true");
                ParsedOption.Add(lastOption);
            }
            else if (nextToken is OptionToken)
            {
                CheckSaturation(lastOption);
                lastOption.AddArgumentValue("true");
                ParsedOption.Add(lastOption);
                ParseOption(nextToken);
            }
            else if (nextToken is ArgumentToken)
            {
                if (IsFullSaturated(lastOption))
                {
                    ParseOptionArguments(nextToken);
                }
                else
                {
                    lastOption.AddArgumentValue("true");
                    ParsedOption.Add(lastOption);
                    ParseParameters(nextToken);
                }
            }
            else if (nextToken is TreatAsArgumentToken)
            {
                CheckSaturation(lastOption);
                lastOption.AddArgumentValue("true");
                ParsedOption.Add(lastOption);
                ParseParameters(tokens.NextToken());
            }
        }
Esempio n. 3
0
 Option GetOptionByToken(Token token)
 {
     return options.Where(opt => opt.Switches.Contains(token.Value)).FirstOrDefault();
 }
Esempio n. 4
0
 public Tokens(Token[] tokens)
 {
     this.tokenNum = 0;
     this.tokens = tokens;
 }
Esempio n. 5
0
        void ParseParameters(Token token)
        {
            Parameters.Add(token.Value);
            // determine next way
            Token nextToken = tokens.NextToken();

            if (nextToken == null)
            {
                return;
            }
            else if (nextToken is ArgumentToken)
            {
                ParseParameters(nextToken);
            }
            else if (nextToken is TreatAsArgumentToken)
            {
                ParseParameters(tokens.NextToken());
            }
            else if (nextToken is OptionToken)
            {
                ParseOption(nextToken);
            }
        }
Esempio n. 6
0
        void ParseOptionArguments(Token token)
        {
            if (!lastOption.ValueType.Validate(token.Value))
            {
                throw new ArgumentValidityException();
            }

            lastOption.AddArgumentValue(token.Value);
            Token nextToken = tokens.NextToken();
            if (nextToken == null)
            {
                CheckSaturation(lastOption);
                ParsedOption.Add(lastOption);
            }
            else if (nextToken is OptionToken)
            {
                CheckSaturation(lastOption);
                ParsedOption.Add(lastOption);
                ParseOption(nextToken);
            }
            else if (nextToken is ArgumentToken)
            {
                if (IsFullSaturated(lastOption))
                {
                    ParseOptionArguments(nextToken);
                }
                else
                {
                    ParsedOption.Add(lastOption);
                    ParseParameters(nextToken);
                }
            }
            else if (nextToken is TreatAsArgumentToken)
            {
                CheckSaturation(lastOption);
                ParsedOption.Add(lastOption);
                ParseParameters(tokens.NextToken());
            }
        }