本文整理汇总了C++中txExprLexer::nextToken方法的典型用法代码示例。如果您正苦于以下问题:C++ txExprLexer::nextToken方法的具体用法?C++ txExprLexer::nextToken怎么用?C++ txExprLexer::nextToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txExprLexer
的用法示例。
在下文中一共展示了txExprLexer::nextToken方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createLocationStep
nsresult
txExprParser::createFilterOrStep(txExprLexer& lexer, txIParseContext* aContext,
Expr** aResult)
{
*aResult = nsnull;
nsresult rv = NS_OK;
Token* tok = lexer.nextToken();
nsAutoPtr<Expr> expr;
switch (tok->mType) {
case Token::FUNCTION_NAME_AND_PAREN:
lexer.pushBack();
rv = createFunctionCall(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
break;
case Token::VAR_REFERENCE :
{
nsCOMPtr<nsIAtom> prefix, lName;
PRInt32 nspace;
nsresult rv = resolveQName(tok->Value(), getter_AddRefs(prefix),
aContext, getter_AddRefs(lName),
nspace);
NS_ENSURE_SUCCESS(rv, rv);
expr = new VariableRefExpr(prefix, lName, nspace);
NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY);
}
break;
case Token::L_PAREN:
rv = createExpr(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
if (lexer.nextToken()->mType != Token::R_PAREN) {
lexer.pushBack();
return NS_ERROR_XPATH_PAREN_EXPECTED;
}
break;
case Token::LITERAL :
expr = new txLiteralExpr(tok->Value());
NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY);
break;
case Token::NUMBER:
{
expr = new txLiteralExpr(Double::toDouble(tok->Value()));
NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY);
break;
}
default:
lexer.pushBack();
return createLocationStep(lexer, aContext, aResult);
}
if (lexer.peek()->mType == Token::L_BRACKET) {
nsAutoPtr<FilterExpr> filterExpr(new FilterExpr(expr));
NS_ENSURE_TRUE(filterExpr, NS_ERROR_OUT_OF_MEMORY);
expr.forget();
//-- handle predicates
rv = parsePredicates(filterExpr, lexer, aContext);
NS_ENSURE_SUCCESS(rv, rv);
expr = filterExpr.forget();
}
*aResult = expr.forget();
return NS_OK;
}
示例2: createFilterOrStep
/**
* Creates a PathExpr using the given txExprLexer
* @param lexer the txExprLexer for retrieving Tokens
*/
nsresult
txExprParser::createPathExpr(txExprLexer& lexer, txIParseContext* aContext,
Expr** aResult)
{
*aResult = nsnull;
nsAutoPtr<Expr> expr;
Token* tok = lexer.peek();
// is this a root expression?
if (tok->mType == Token::PARENT_OP) {
lexer.nextToken();
if (!isLocationStepToken(lexer.peek())) {
*aResult = new RootExpr();
NS_ENSURE_TRUE(*aResult, NS_ERROR_OUT_OF_MEMORY);
return NS_OK;
}
lexer.pushBack();
}
// parse first step (possibly a FilterExpr)
nsresult rv = NS_OK;
if (tok->mType != Token::PARENT_OP &&
tok->mType != Token::ANCESTOR_OP) {
rv = createFilterOrStep(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
// is this a singlestep path expression?
tok = lexer.peek();
if (tok->mType != Token::PARENT_OP &&
tok->mType != Token::ANCESTOR_OP) {
*aResult = expr.forget();
return NS_OK;
}
}
else {
expr = new RootExpr();
NS_ENSURE_TRUE(expr, NS_ERROR_OUT_OF_MEMORY);
#ifdef TX_TO_STRING
static_cast<RootExpr*>(expr.get())->setSerialize(PR_FALSE);
#endif
}
// We have a PathExpr containing several steps
nsAutoPtr<PathExpr> pathExpr(new PathExpr());
NS_ENSURE_TRUE(pathExpr, NS_ERROR_OUT_OF_MEMORY);
rv = pathExpr->addExpr(expr, PathExpr::RELATIVE_OP);
NS_ENSURE_SUCCESS(rv, rv);
expr.forget();
// this is ugly
while (1) {
PathExpr::PathOperator pathOp;
tok = lexer.nextToken();
switch (tok->mType) {
case Token::ANCESTOR_OP :
pathOp = PathExpr::DESCENDANT_OP;
break;
case Token::PARENT_OP :
pathOp = PathExpr::RELATIVE_OP;
break;
default:
lexer.pushBack();
*aResult = pathExpr.forget();
return NS_OK;
}
rv = createLocationStep(lexer, aContext, getter_Transfers(expr));
NS_ENSURE_SUCCESS(rv, rv);
rv = pathExpr->addExpr(expr, pathOp);
NS_ENSURE_SUCCESS(rv, rv);
expr.forget();
}
NS_NOTREACHED("internal xpath parser error");
return NS_ERROR_UNEXPECTED;
}
示例3: while
nsresult
txExprParser::createExpr(txExprLexer& lexer, txIParseContext* aContext,
Expr** aResult)
{
*aResult = nsnull;
nsresult rv = NS_OK;
MBool done = MB_FALSE;
nsAutoPtr<Expr> expr;
txStack exprs;
txStack ops;
while (!done) {
MBool unary = MB_FALSE;
while (lexer.peek()->mType == Token::SUBTRACTION_OP) {
unary = !unary;
lexer.nextToken();
}
rv = createUnionExpr(lexer, aContext, getter_Transfers(expr));
if (NS_FAILED(rv)) {
break;
}
if (unary) {
Expr* unaryExpr = new UnaryExpr(expr);
if (!unaryExpr) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
expr.forget();
expr = unaryExpr;
}
Token* tok = lexer.nextToken();
short tokPrecedence = precedence(tok);
if (tokPrecedence != 0) {
while (!exprs.isEmpty() && tokPrecedence
<= precedence(static_cast<Token*>(ops.peek()))) {
// can't use expr as argument due to order of evaluation
nsAutoPtr<Expr> left(static_cast<Expr*>(exprs.pop()));
nsAutoPtr<Expr> right(expr);
rv = createBinaryExpr(left, right,
static_cast<Token*>(ops.pop()),
getter_Transfers(expr));
if (NS_FAILED(rv)) {
done = PR_TRUE;
break;
}
}
exprs.push(expr.forget());
ops.push(tok);
}
else {
lexer.pushBack();
done = PR_TRUE;
}
}
while (NS_SUCCEEDED(rv) && !exprs.isEmpty()) {
nsAutoPtr<Expr> left(static_cast<Expr*>(exprs.pop()));
nsAutoPtr<Expr> right(expr);
rv = createBinaryExpr(left, right, static_cast<Token*>(ops.pop()),
getter_Transfers(expr));
}
// clean up on error
while (!exprs.isEmpty()) {
delete static_cast<Expr*>(exprs.pop());
}
NS_ENSURE_SUCCESS(rv, rv);
*aResult = expr.forget();
return NS_OK;
}
示例4: if
nsresult
txExprParser::createLocationStep(txExprLexer& lexer, txIParseContext* aContext,
Expr** aExpr)
{
*aExpr = nsnull;
//-- child axis is default
LocationStep::LocationStepType axisIdentifier = LocationStep::CHILD_AXIS;
nsAutoPtr<txNodeTest> nodeTest;
//-- get Axis Identifier or AbbreviatedStep, if present
Token* tok = lexer.peek();
switch (tok->mType) {
case Token::AXIS_IDENTIFIER:
{
//-- eat token
lexer.nextToken();
nsCOMPtr<nsIAtom> axis = do_GetAtom(tok->Value());
if (axis == txXPathAtoms::ancestor) {
axisIdentifier = LocationStep::ANCESTOR_AXIS;
}
else if (axis == txXPathAtoms::ancestorOrSelf) {
axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS;
}
else if (axis == txXPathAtoms::attribute) {
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
}
else if (axis == txXPathAtoms::child) {
axisIdentifier = LocationStep::CHILD_AXIS;
}
else if (axis == txXPathAtoms::descendant) {
axisIdentifier = LocationStep::DESCENDANT_AXIS;
}
else if (axis == txXPathAtoms::descendantOrSelf) {
axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS;
}
else if (axis == txXPathAtoms::following) {
axisIdentifier = LocationStep::FOLLOWING_AXIS;
}
else if (axis == txXPathAtoms::followingSibling) {
axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS;
}
else if (axis == txXPathAtoms::_namespace) {
axisIdentifier = LocationStep::NAMESPACE_AXIS;
}
else if (axis == txXPathAtoms::parent) {
axisIdentifier = LocationStep::PARENT_AXIS;
}
else if (axis == txXPathAtoms::preceding) {
axisIdentifier = LocationStep::PRECEDING_AXIS;
}
else if (axis == txXPathAtoms::precedingSibling) {
axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS;
}
else if (axis == txXPathAtoms::self) {
axisIdentifier = LocationStep::SELF_AXIS;
}
else {
return NS_ERROR_XPATH_INVALID_AXIS;
}
break;
}
case Token::AT_SIGN:
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
break;
case Token::PARENT_NODE :
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::PARENT_AXIS;
nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE);
NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY);
break;
case Token::SELF_NODE :
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::SELF_AXIS;
nodeTest = new txNodeTypeTest(txNodeTypeTest::NODE_TYPE);
NS_ENSURE_TRUE(nodeTest, NS_ERROR_OUT_OF_MEMORY);
break;
default:
break;
}
//-- get NodeTest unless an AbbreviatedStep was found
nsresult rv = NS_OK;
if (!nodeTest) {
tok = lexer.nextToken();
if (tok->mType == Token::CNAME) {
// resolve QName
nsCOMPtr<nsIAtom> prefix, lName;
PRInt32 nspace;
rv = resolveQName(tok->Value(), getter_AddRefs(prefix),
aContext, getter_AddRefs(lName),
nspace, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
nodeTest =
//.........这里部分代码省略.........
示例5: createUnionPattern
nsresult txPatternParser::createUnionPattern(txExprLexer& aLexer,
txIParseContext* aContext,
txPattern*& aPattern)
{
nsresult rv = NS_OK;
txPattern* locPath = 0;
rv = createLocPathPattern(aLexer, aContext, locPath);
if (NS_FAILED(rv))
return rv;
Token::Type type = aLexer.peek()->mType;
if (type == Token::END) {
aPattern = locPath;
return NS_OK;
}
if (type != Token::UNION_OP) {
delete locPath;
return NS_ERROR_XPATH_PARSE_FAILURE;
}
txUnionPattern* unionPattern = new txUnionPattern();
if (!unionPattern) {
delete locPath;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = unionPattern->addPattern(locPath);
#if 0 // XXX addPattern can't fail yet, it doesn't check for mem
if (NS_FAILED(rv)) {
delete unionPattern;
delete locPath;
return rv;
}
#endif
aLexer.nextToken();
do {
rv = createLocPathPattern(aLexer, aContext, locPath);
if (NS_FAILED(rv)) {
delete unionPattern;
return rv;
}
rv = unionPattern->addPattern(locPath);
#if 0 // XXX addPattern can't fail yet, it doesn't check for mem
if (NS_FAILED(rv)) {
delete unionPattern;
delete locPath;
return rv;
}
#endif
type = aLexer.nextToken()->mType;
} while (type == Token::UNION_OP);
if (type != Token::END) {
delete unionPattern;
return NS_ERROR_XPATH_PARSE_FAILURE;
}
aPattern = unionPattern;
return NS_OK;
}
示例6: createStepPattern
nsresult txPatternParser::createStepPattern(txExprLexer& aLexer,
txIParseContext* aContext,
txPattern*& aPattern)
{
nsresult rv = NS_OK;
MBool isAttr = MB_FALSE;
Token* tok = aLexer.peek();
if (tok->mType == Token::AXIS_IDENTIFIER) {
if (TX_StringEqualsAtom(tok->Value(), nsGkAtoms::attribute)) {
isAttr = MB_TRUE;
}
else if (!TX_StringEqualsAtom(tok->Value(), nsGkAtoms::child)) {
// all done already for CHILD_AXIS, for all others
// XXX report unexpected axis error
return NS_ERROR_XPATH_PARSE_FAILURE;
}
aLexer.nextToken();
}
else if (tok->mType == Token::AT_SIGN) {
aLexer.nextToken();
isAttr = MB_TRUE;
}
tok = aLexer.nextToken();
txNodeTest* nodeTest;
if (tok->mType == Token::CNAME) {
// resolve QName
nsCOMPtr<nsIAtom> prefix, lName;
PRInt32 nspace;
rv = resolveQName(tok->Value(), getter_AddRefs(prefix), aContext,
getter_AddRefs(lName), nspace, PR_TRUE);
if (NS_FAILED(rv)) {
// XXX error report namespace resolve failed
return rv;
}
PRUint16 nodeType = isAttr ?
(PRUint16)txXPathNodeType::ATTRIBUTE_NODE :
(PRUint16)txXPathNodeType::ELEMENT_NODE;
nodeTest = new txNameTest(prefix, lName, nspace, nodeType);
if (!nodeTest) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
else {
aLexer.pushBack();
rv = createNodeTypeTest(aLexer, &nodeTest);
NS_ENSURE_SUCCESS(rv, rv);
}
nsAutoPtr<txStepPattern> step(new txStepPattern(nodeTest, isAttr));
if (!step) {
delete nodeTest;
return NS_ERROR_OUT_OF_MEMORY;
}
rv = parsePredicates(step, aLexer, aContext);
NS_ENSURE_SUCCESS(rv, rv);
aPattern = step.forget();
return NS_OK;
}
示例7: createLocPathPattern
nsresult txPatternParser::createLocPathPattern(txExprLexer& aLexer,
txIParseContext* aContext,
txPattern*& aPattern)
{
nsresult rv = NS_OK;
MBool isChild = MB_TRUE;
MBool isAbsolute = MB_FALSE;
txPattern* stepPattern = 0;
txLocPathPattern* pathPattern = 0;
Token::Type type = aLexer.peek()->mType;
switch (type) {
case Token::ANCESTOR_OP:
isChild = MB_FALSE;
isAbsolute = MB_TRUE;
aLexer.nextToken();
break;
case Token::PARENT_OP:
aLexer.nextToken();
isAbsolute = MB_TRUE;
if (aLexer.peek()->mType == Token::END ||
aLexer.peek()->mType == Token::UNION_OP) {
aPattern = new txRootPattern();
return aPattern ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
break;
case Token::FUNCTION_NAME_AND_PAREN:
// id(Literal) or key(Literal, Literal)
{
nsCOMPtr<nsIAtom> nameAtom =
do_GetAtom(aLexer.nextToken()->Value());
if (nameAtom == nsGkAtoms::id) {
rv = createIdPattern(aLexer, stepPattern);
}
else if (nameAtom == nsGkAtoms::key) {
rv = createKeyPattern(aLexer, aContext, stepPattern);
}
if (NS_FAILED(rv))
return rv;
}
break;
default:
break;
}
if (!stepPattern) {
rv = createStepPattern(aLexer, aContext, stepPattern);
if (NS_FAILED(rv))
return rv;
}
type = aLexer.peek()->mType;
if (!isAbsolute && type != Token::PARENT_OP
&& type != Token::ANCESTOR_OP) {
aPattern = stepPattern;
return NS_OK;
}
pathPattern = new txLocPathPattern();
if (!pathPattern) {
delete stepPattern;
return NS_ERROR_OUT_OF_MEMORY;
}
if (isAbsolute) {
txRootPattern* root = new txRootPattern();
if (!root) {
delete stepPattern;
delete pathPattern;
return NS_ERROR_OUT_OF_MEMORY;
}
#ifdef TX_TO_STRING
root->setSerialize(PR_FALSE);
#endif
rv = pathPattern->addStep(root, isChild);
if (NS_FAILED(rv)) {
delete stepPattern;
delete pathPattern;
delete root;
return NS_ERROR_OUT_OF_MEMORY;
}
}
rv = pathPattern->addStep(stepPattern, isChild);
if (NS_FAILED(rv)) {
delete stepPattern;
delete pathPattern;
return NS_ERROR_OUT_OF_MEMORY;
}
stepPattern = 0; // stepPattern is part of pathPattern now
while (type == Token::PARENT_OP || type == Token::ANCESTOR_OP) {
isChild = type == Token::PARENT_OP;
aLexer.nextToken();
rv = createStepPattern(aLexer, aContext, stepPattern);
if (NS_FAILED(rv)) {
delete pathPattern;
//.........这里部分代码省略.........