Beispiel #1
0
void ArgumentParser::parse(const QStringList& args)
{
    ArgumentScanner scanner;
    scanner.scan(args);
    const auto tokens = scanner.tokens();

    int i = 0;
    do
    {
        if (int tokensConsumed = parseCommand(tokens, i))
        {
            i += tokensConsumed;
            continue;
        }

        if (int tokensConsumed = parseLongOption(tokens, i))
        {
            i += tokensConsumed;
            continue;
        }

        if (int tokensConsumed = parseShortOption(tokens, i))
        {
            i += tokensConsumed;
            continue;
        }

        i += parseOther(tokens, i);
    } while (i < tokens.size());
}
Beispiel #2
0
static void cArgRead (cookedArgs *const current)
{
	char* item;

	Assert (current != NULL);
	if (! argOff (current->args))
	{
		item = argItem (current->args);
		current->shortOptions = NULL;
		Assert (item != NULL);
		if (strncmp (item, "--", (size_t) 2) == 0)
		{
			current->isOption = TRUE;
			current->longOption = TRUE;
			parseLongOption (current, item + 2);
			Assert (current->item != NULL);
			Assert (current->parameter != NULL);
		}
		else if (*item == '-')
		{
			current->isOption = TRUE;
			current->longOption = FALSE;
			current->shortOptions = item + 1;
			parseShortOption (current);
		}
		else
		{
			current->isOption = FALSE;
			current->longOption = FALSE;
			current->item = item;
			current->parameter = NULL;
		}
	}
}
Beispiel #3
0
bool pscli::LexParser::parseOne(std::string input){
    if(input.size() < 1)
        return true;
    
    bool success = true;

    if(input.size() >= 2 && input[0] == '-' && input[1] != '-'){
        success &= parseShortOption(input.substr(1));
    }else if(input.size() >= 4 && input[0] == '-' && input[1] == '-'){
        success &= parseLongOption(input.substr(2));
    }else if(input[0] != '-'){
        success &= parseParameter(input);
    }else{
        pscli::Error::syntaxError();
        return false;
    }

    return success;
}