// 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("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("help",TokenType.Argument,0));
            }

            //Index rewrite:
            var indexToken= new Token("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;
        }
Ejemplo n.º 2
0
 private void InferParameter(List<int> recognizedIndexes, IList<RecognizedArgument> recognized, Token current)
 {
     ArgumentWithOptions 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.Argument.LongAlias(),
                            current.Value) {InferredOrdinal = true});
     }
 }
Ejemplo n.º 3
0
 public bool Equals(Token other)
 {
     return Equals(other.Value, Value) && Equals(other.TokenType, TokenType);
 }