Exemple #1
0
void TmpArguments::ArgsFromTuple(AstNode* node, Args& args)
{
	if (node == NULL)
	{
		args.clear();
		return;
	}

	Tuple *tuple = dynamic_cast<Tuple*>(node);

	if (tuple == NULL)
	{
		throw syntax_error(node->loc, "AstNode must be a tuple");
	}

	args.clear();
	args.reserve(tuple->items.size());

	for (AstNodes::const_iterator i = tuple->items.begin();
			i != tuple->items.end(); ++i)
	{
		Arg *arg = dynamic_cast<Arg*>(*i);
		if (arg == NULL)
		{
			throw syntax_error((*i)->loc, "argument must be an arg type");
		}

		args.push_back(arg);
	}
}
Exemple #2
0
int InputParser::parse(istream &input, Args &args)
{
    reset();
    args.clear();

    int lines = 0;

    getline(input, line_);
    ++lines;
    for(; (size_t)pos_ < line_.length(); ++pos_) {
        char c = line_[pos_];
        switch(c) {
        case '\\': {
            if(pos_ == line_.length() - 1) {
                // Escaped newline, get next line of input
                nextLine(input, args);
                ++lines;
            }
            else {
                escapedCharacter();
            }
            break;
        }
        case ' ':
        case '\t':
        case '\n':
        case '\r': {
            whitespace(args);
            break;
        }
        case '\'':
        case '"': {
            quote(args, c);
            break;
        }
        case '{': {
            openCurly();
            break;
        }
        case '}': {
            closeCurly();
            break;
        }
        case '#': {
            if (!inQuotes())
                pos_ = line_.length();
            break; // force end of parse for this line
        }
        default: {
            character();
            break;
        }
        }

        if(inQuotes() && pos_ == line_.length() - 1) {
            // We have an unfinished quote, so get the next line
            nextLine(input, args);
            ++lines;
        }
    }
    endOfArg(args);

    line_ = "";

    return lines;
}