Example #1
0
ExprTree *ClassAdXMLParser::
ParseBool(void)
{
	ExprTree         *tree;
	XMLLexer::Token  token;

	tree = NULL;
	lexer.ConsumeToken(&token);
	assert(token.tag_id == XMLLexer::tagID_Bool);

	Value  value;
	string truth_value = token.attributes["v"];

	if (truth_value == "t" || truth_value == "T") {
		value.SetBooleanValue(true);
	} else {
		value.SetBooleanValue(false);
	}
	tree = Literal::MakeLiteral(value);

	if (token.tag_type == XMLLexer::tagType_Start) {
        SwallowEndTag(XMLLexer::tagID_Bool);
	}
	
	return tree;
}
Example #2
0
ExprTree *ClassAdXMLParser::
ParseExpr(void)
{
	bool             have_token;
	ExprTree         *tree;
	XMLLexer::Token  token;

	// Get start tag
	tree = NULL;
	have_token = lexer.ConsumeToken(&token);
	assert(have_token && token.tag_id == XMLLexer::tagID_Expr);

	// Get text of expression
	have_token = lexer.PeekToken(&token);
	if (have_token && token.token_type == XMLLexer::tokenType_Text) {
		lexer.ConsumeToken(&token);
		ClassAdParser  parser;
		
		tree = parser.ParseExpression(token.text);
	}

    SwallowEndTag(XMLLexer::tagID_Expr);

	return tree;
}
Example #3
0
ExprTree *ClassAdXMLParser::
ParseNumberOrString(XMLLexer::TagID tag_id)
{

	bool             have_token;
	ExprTree         *tree;
	XMLLexer::Token  token;

	// Get start tag
	tree = NULL;
	have_token = lexer.ConsumeToken(&token);
	assert(have_token && token.tag_id == tag_id);

	// Get text of number or string
	have_token = lexer.PeekToken(&token);

	if (have_token && token.token_type == XMLLexer::tokenType_Text) {
		lexer.ConsumeToken(&token);
		Value value;
		if (tag_id == XMLLexer::tagID_Integer) {
			long long number;
			sscanf(token.text.c_str(), "%lld", &number);
			value.SetIntegerValue(number);
		}
		else if (tag_id == XMLLexer::tagID_Real) {
			double real;
            real = strtod(token.text.c_str(), NULL);
            value.SetRealValue(real);
        }
		else {        // its a string
			bool validStr = true;
			token.text += " ";
			convert_escapes(token.text, validStr );
			if(!validStr) {  // invalid string because it had /0 escape sequence
				return NULL;
			} else {
				value.SetStringValue(token.text);
			}
		}
	
		  tree = Literal::MakeLiteral(value);
		
	} else if (tag_id == XMLLexer::tagID_String) {
		// We were expecting text and got none, so we had
		// the empty string, which was skipped by the lexer.
		Value  value;
		value.SetStringValue("");
		tree = Literal::MakeLiteral(value);
	}

    SwallowEndTag(tag_id);

	return tree;
}
Example #4
0
ExprTree *ClassAdXMLParser::
ParseRelTime(void)
{
  	bool             have_token;
	ExprTree         *tree;
	XMLLexer::Token  token;

	tree = NULL;
	lexer.ConsumeToken(&token);
	assert(token.tag_id == XMLLexer::tagID_RelativeTime);
	have_token = lexer.PeekToken(&token);
	if (have_token && token.token_type == XMLLexer::tokenType_Text) {
		lexer.ConsumeToken(&token);
		tree = Literal::MakeRelTime(token.text);
	}
    SwallowEndTag(XMLLexer::tagID_RelativeTime);
	return tree;
}
Example #5
0
ExprTree *ClassAdXMLParser::
ParseAttribute(
	string    &attribute_name)
{
	ExprTree         *tree;
	XMLLexer::Token  token;

	tree = NULL;
	lexer.ConsumeToken(&token);
	assert(token.tag_id == XMLLexer::tagID_Attribute);

	if (token.tag_type != XMLLexer::tagType_Start) {
		attribute_name = "";
	} else {
		attribute_name = token.attributes["n"];
		if (attribute_name != "") {
			tree = ParseThing();
		}

        SwallowEndTag(XMLLexer::tagID_Attribute);
	}
	return tree;
}
Example #6
0
ExprTree *ClassAdXMLParser::
ParseUndefinedOrError(XMLLexer::TagID tag_id)
{
	ExprTree         *tree;
	XMLLexer::Token  token;

	tree = NULL;
	lexer.ConsumeToken(&token);
	assert(token.tag_id == tag_id);

	Value value;
	if (tag_id == XMLLexer::tagID_Undefined) {
		value.SetUndefinedValue();
	} else {
		value.SetErrorValue();
	}
	tree = Literal::MakeLiteral(value);

	if (token.tag_type == XMLLexer::tagType_Start) {
        SwallowEndTag(tag_id);
	}

	return tree;
}
Example #7
0
ExprTree *ClassAdXMLParser::
ParseNumberOrString(XMLLexer::TagID tag_id)
{

	bool             have_token;
	ExprTree         *tree;
	XMLLexer::Token  token;

	// Get start tag
	tree = NULL;
	have_token = lexer.ConsumeToken(&token);
	assert(have_token && token.tag_id == tag_id);

	// Get text of number or string
	have_token = lexer.PeekToken(&token);

	if (have_token && token.token_type == XMLLexer::tokenType_Text) {
		lexer.ConsumeToken(&token);
		Value value;
		if (tag_id == XMLLexer::tagID_Integer) {
			long long number;
			char * pend;
			const char * pnum = token.text.c_str();
			number = strtoll(pnum, &pend, 10);
			if ( ! number && (pend == pnum)) {
				value.SetErrorValue();
			} else {
				value.SetIntegerValue(number);
			}
		}
		else if (tag_id == XMLLexer::tagID_Real) {
			double real;
			char * pend;
			const char * pnum = token.text.c_str();
			real = strtod(pnum, &pend);
			if (pend == pnum) {
				value.SetErrorValue();
			} else {
				value.SetRealValue(real);
			}
		}
		else {        // its a string
			bool validStr = true;
			//token.text.push_back('\0'); // force an explicit null terminator (because that's that the normal lexer does.)
			convert_escapes(token.text, validStr );
			if(!validStr) {  // invalid string because it had /0 escape sequence
				return NULL;
			} else {
				value.SetStringValue(token.text);
			}
		}
	
		  tree = Literal::MakeLiteral(value);
		
	} else if (tag_id == XMLLexer::tagID_String) {
		// We were expecting text and got none, so we had
		// the empty string, which was skipped by the lexer.
		Value  value;
		value.SetStringValue("");
		tree = Literal::MakeLiteral(value);
	}

    SwallowEndTag(tag_id);

	return tree;
}