Example #1
0
        public override Vector2 Parse(CommandParser tokenizer)
        {
            var float0 = tokenizer.AsValue <float>();

            tokenizer.Require(',', true);
            var float1 = tokenizer.AsValue <float>();

            return(new Vector2
            {
                x = float0,
                y = float1
            });
        }
Example #2
0
        public bool Run(string commandString)
        {
            var parser      = new CommandParser(commandString, parserContext);
            var commandName = parser.AsValue(new StringLiteralParser());

            // Select command
            if (!Container.ContainsCommand(commandName))
            {
                output.Print($"Command: \"{commandName}\" doesn't exist", OutputColor.warning);
                return(false);
            }

            var command = Container.GetCommand(commandName);

            return(Run(command, parser));
        }
Example #3
0
        internal static void Parameterize(Command command, CommandParser parser)
        {
            var position = 1;

            foreach (var item in command.Context.arguments)
            {
                var argument        = item.Value;
                var argumentContext = argument.Context;

                parser.RemovePadding();

                if (parser.IsEOF)
                {
                    if (argumentContext.Required)
                    {
                        var message = $"Required argument with name: \"{item.Key}\" is not set";
                        throw new ParameterizationException(message);
                    }
                    else
                    {
                        return;
                    }
                }

                try
                {
                    TypeParser typeParser = null;

                    if (argumentContext.CustomParser != null)
                    {
                        typeParser = parser.context.GetTypeParser(argumentContext.CustomParser);
                    }

                    var parsedObj = parser.AsValue(argumentContext.PropertyType, typeParser);
                    argument.SetValue(command, parsedObj);
                }
                catch (InputFormatException e)
                {
                    var message = $"Error while parsing property {item.Key} (parameter position: {position}): {e.Message}";
                    throw new ParameterizationException(message);
                }

                position++;
            }
        }