Exemple #1
0
CfgValue* CfgValue::ParseValue (InputBuffer& buf)
{
	CfgValue *v = 0;

	if (buf.SkipWhitespace ()) {
		buf.Expecting ("Value");
		return 0;
	}

	for (unsigned int a=0;a<classes.size();a++)
	{
		if (classes[a]->Identify (buf))
		{
			v = classes[a]->Create ();

			if (!v->Parse (buf)) {
				delete v;
				return 0;
			}

			return v;
		}
	}

	// parse standard value types:
	char r = Lookahead (buf);

	if(buf.CompareIdent ("file"))
	{
		// load a nested config file
		return LoadNestedFile (buf);
	}
	else if(isalpha (*buf)) {
		v = new CfgLiteral;
		((CfgLiteral*)v)->ident = true;
	}
	else if(isdigit (r) || *buf == '.' || *buf == '-')
		v = new CfgNumeric;
	else if(*buf == '"')
		v = new CfgLiteral;
	else if(*buf == '{')
		v = new CfgList;

	if (v && !v->Parse (buf))
	{
		delete v;
		return 0;
	}

	return v;
}
Exemple #2
0
CfgValue* CfgValue::ParseValue (InputBuffer& buf)
{
	CfgValue *v = 0;

	if (buf.skipWhitespace ())
		buf.expecting ("Value");

	// parse value types:
	int token = nextToken (buf);

	switch (token) {
		case CT_LIST:
			v = new CfgList();
			break;
		case CT_NUMERIC:
			v = new CfgNumeric();
			break;
		case CT_LITERAL:
			v = new CfgLiteral();
			break;
		case CT_COMMAND: {
			++buf;
			std::string cmd = buf.parseIdent();
			d_trace("Cmd: %s\n", cmd.c_str());
			if (cmd == "include") {
				return LoadNestedFile(buf);
			} else {
				throw ContentException(SPrintf("%s. Unknown command: %s", buf.location().c_str() ,cmd.c_str()));
			}
		}
		case CT_IDENT:
			throw ContentException(buf.location() + SPrintf("Unexpected identifier: '%s'", buf.parseIdent()) );
	}

	if (v) {
		try {
			v->Parse(buf);
			v->cfgFilePath = buf.filename;
		} catch(const ContentException& e) {
			delete v;
			throw e;
		}
	}
	return v;
}