// Arg(ControllerName),Param(..),.. -> Arg(ControllerName),Arg('Index'),...
        public static IList<Token> Rewrite(IList<Token> tokens)
        {
            //"--command"
            if (tokens.Count() >= 2
                && tokens[0].TokenType==TokenType.Argument
                && tokens[0].Value.EqualsIC(Conventions.Help)
                && tokens[1].TokenType==TokenType.Argument)
            {
                tokens[1] = new Token(tokens[1].Value,TokenType.ParameterValue,tokens[1].Index);
                tokens.Insert(1,new Token("command",TokenType.Parameter,1));
                //index:2
                if (tokens.Count() >= 4) { tokens[3] = new Token(tokens[3].Value, TokenType.ParameterValue, tokens[1].Index); }
                tokens.Insert(3, new Token("action", TokenType.Parameter, 2));
            }
            //help maps to index (should have routing here)
            if (tokens.Count() == 0)
            {
                tokens.Add(new Token(Conventions.Help,TokenType.Argument,0));
            }

            //Index rewrite:
            var indexToken= new Token(Conventions.Index, TokenType.Argument,1);
            if (tokens.Count()>=2
                && tokens[1].TokenType!=TokenType.Argument
                && tokens[0].TokenType==TokenType.Argument)
            {
                tokens.Insert(1,indexToken);
            }
            else if (tokens.Count()==1
                && tokens[0].TokenType==TokenType.Argument)
            {
                tokens.Add(indexToken);
            }
            return tokens;
        }
Example #2
0
 private void InferParameter(List<int> recognizedIndexes, IList<RecognizedArgument> recognized, Token current)
 {
     Argument argumentWithOptions;
     argumentWithOptions = _argumentWithOptions
         .Where((argopt, i) => i == current.Index).SingleOrDefault();
     if (null != argumentWithOptions)
     {
         recognizedIndexes.Add(current.Index);
         recognized.Add(new RecognizedArgument(
                            argumentWithOptions,
                            current.Index,
                            argumentWithOptions.Name,
                            current.Value) { InferredOrdinal = true });
     }
 }
Example #3
0
 public bool Equals(Token other)
 {
     return Equals(other.Value, Value) && Equals(other.TokenType, TokenType);
 }