Not part of regular build. Removed WildCardExpr, updated all necessary files.

Removed Token::WILD_CARD. Wild cards are handled in ElementExpr and
AttributeExpr accordingly.
This commit is contained in:
kvisco%ziplink.net 2001-01-22 09:36:19 +00:00
parent f11de4ec67
commit 2dd9ef3e86
16 changed files with 267 additions and 323 deletions

View File

@ -21,28 +21,29 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: AttributeExpr.cpp,v 1.2 2001/01/12 20:06:30 axel%pike.org Exp $
* $Id: AttributeExpr.cpp,v 1.3 2001/01/22 09:36:12 kvisco%ziplink.net Exp $
*/
#include "Expr.h"
/**
* This class represents a ElementExpr as defined by the XSL
* Working Draft
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.2 $ $Date: 2001/01/12 20:06:30 $
**/
/*
This class represents a Attribute Expression as defined by the XPath
1.0 Recommendation
*/
const String AttributeExpr::WILD_CARD = "*";
//- Constructors -/
AttributeExpr::AttributeExpr() {
this->isWild = MB_FALSE;
this->isNameWild = MB_FALSE;
this->isNamespaceWild = MB_FALSE;
} //-- AttributeExpr
AttributeExpr::AttributeExpr(String& name) {
//-- copy name
this->name = name;
this->isWild = MB_FALSE;
this->isNameWild = MB_FALSE;
this->isNamespaceWild = MB_FALSE;
setName(name);
} //-- AttributeExpr
/**
@ -68,13 +69,17 @@ ExprResult* AttributeExpr::evaluate(Node* context, ContextState* cs) {
if ( !context ) return nodeSet;
NamedNodeMap* atts = context->getAttributes();
if ( atts ) {
for (UInt32 i = 0; i < atts->getLength(); i++ ) {
Attr* attr = (Attr*)atts->item(i);
if ( isWild ) nodeSet->add(attr);
else {
String attName = attr->getName();
if ( name.isEqual(attName) ){
UInt32 i = 0;
if ( isNameWild && isNamespaceWild ) {
for ( ; i < atts->getLength(); i++ )
nodeSet->add(atts->item(i));
}
else {
for ( ; i < atts->getLength(); i++ ) {
Node* attr = atts->item(i);
if (matches(attr, context, cs)) {
nodeSet->add(attr);
if (!isNameWild) break;
}
}
}
@ -101,12 +106,30 @@ const String& AttributeExpr::getName() {
} //-- getName
void AttributeExpr::setName(const String& name) {
this->name.clear();
this->name.append(name);
if (name.isEqual(WILD_CARD)) {
this->isNameWild = MB_TRUE;
this->isNamespaceWild = MB_TRUE;
return;
}
int idx = name.indexOf(':');
if ( idx >= 0 )
name.subString(0,idx, this->prefix);
else
idx = -1;
name.subString(idx+1, this->name);
//-- set flags
this->isNamespaceWild = MB_FALSE;
this->isNameWild = this->name.isEqual(WILD_CARD);
} //-- setName
void AttributeExpr::setWild(MBool isWild) {
this->isWild = isWild;
this->isNameWild = isWild;
this->isNamespaceWild = isWild;
} //-- setWild
//-----------------------------/
//- Methods from NodeExpr.cpp -/
@ -125,9 +148,33 @@ short AttributeExpr::getType() {
* the given context
**/
MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( (node) && (node->getNodeType() == Node::ATTRIBUTE_NODE) ) {
if ( isWild ) return MB_TRUE;
const String nodeName = ((Attr*)node)->getName();
if ( (!node) || (node->getNodeType() != Node::ATTRIBUTE_NODE) )
return MB_FALSE;
if ( isNameWild && isNamespaceWild ) return MB_TRUE;
const String nodeName = ((Attr*)node)->getName();
int idx = nodeName.indexOf(':');
if (idx >= 0) {
String prefixForNode;
nodeName.subString(0,idx,prefixForNode);
String localName;
nodeName.subString(idx+1, localName);
if (isNamespaceWild) return localName.isEqual(this->name);
String nsForNode;
Node* parent = cs->getParentNode(node);
if (parent) XMLDOMUtils::getNameSpace(prefixForNode, (Element*)parent, nsForNode);
String nsForTest;
cs->getNameSpaceURIFromPrefix(this->prefix,nsForTest);
if (!nsForTest.isEqual(nsForNode)) return MB_FALSE;
return localName.isEqual(this->name);
}
else {
if (isNamespaceWild) return nodeName.isEqual(this->name);
String nsForTest;
cs->getNameSpaceURIFromPrefix(this->prefix, nsForTest);
if (nsForTest.length() > 0) return MB_FALSE;
return nodeName.isEqual(this->name);
}
return MB_FALSE;
@ -144,7 +191,11 @@ MBool AttributeExpr::matches(Node* node, Node* context, ContextState* cs) {
**/
void AttributeExpr::toString(String& dest) {
dest.append('@');
if (isWild) dest.append('*');
else dest.append(this->name);
if (isNameWild && isNamespaceWild) dest.append('*');
else {
dest.append(this->prefix);
dest.append(':');
dest.append(this->name);
}
} //-- toString

View File

@ -24,7 +24,7 @@
* Marina Mechtcheriakova, mmarina@mindspring.com
* -- added lang() implementation
*
* $Id: BooleanFunctionCall.cpp,v 1.5 2000/06/11 11:41:34 Peter.VanderBeken%pandora.be Exp $
* $Id: BooleanFunctionCall.cpp,v 1.6 2001/01/22 09:36:13 kvisco%ziplink.net Exp $
*/
#include "FunctionLib.h"
@ -32,7 +32,7 @@
/**
* Creates a default BooleanFunctionCall, which always evaluates to False
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.5 $ $Date: 2000/06/11 11:41:34 $
* @version $Revision: 1.6 $ $Date: 2001/01/22 09:36:13 $
**/
BooleanFunctionCall::BooleanFunctionCall() : FunctionCall(XPathNames::FALSE_FN) {
this->type = TX_FALSE;
@ -72,7 +72,7 @@ BooleanFunctionCall::BooleanFunctionCall(short type) : FunctionCall()
**/
ExprResult* BooleanFunctionCall::evaluate(Node* context, ContextState* cs) {
BooleanResult* result = new BooleanResult();
MBool result = MB_FALSE;
ListIterator* iter = params.iterator();
int argc = params.getLength();
Expr* param = 0;
@ -84,7 +84,7 @@ ExprResult* BooleanFunctionCall::evaluate(Node* context, ContextState* cs) {
if ( requireParams(1,1,cs) ) {
param = (Expr*)iter->next();
ExprResult* exprResult = param->evaluate(context, cs);
result->setValue(exprResult->booleanValue());
result = exprResult->booleanValue();
delete exprResult;
}
break;
@ -95,25 +95,24 @@ ExprResult* BooleanFunctionCall::evaluate(Node* context, ContextState* cs) {
lang = ((Element*)context)->getAttribute(LANG_ATTR);
arg1.toUpperCase(); // case-insensitive comparison
lang.toUpperCase();
result->setValue((MBool)(lang.indexOf(arg1) == 0));
result = (MBool)(lang.indexOf(arg1) == 0);
}
break;
case TX_NOT :
if ( requireParams(1,1,cs) ) {
param = (Expr*)iter->next();
ExprResult* exprResult = param->evaluate(context, cs);
result->setValue(!exprResult->booleanValue());
result = (MBool)(!exprResult->booleanValue());
delete exprResult;
}
break;
case TX_TRUE :
result->setValue(MB_TRUE);
result = MB_TRUE;
break;
default:
result->setValue(MB_FALSE);
break;
}
delete iter;
return result;
return new BooleanResult(result);
} //-- evaluate

View File

@ -21,14 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: BooleanResult.cpp,v 1.5 2000/06/11 11:41:38 Peter.VanderBeken%pandora.be Exp $
* $Id: BooleanResult.cpp,v 1.6 2001/01/22 09:36:14 kvisco%ziplink.net Exp $
*/
/**
/*
* Boolean Expression result
* @author <A href="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.5 $ $Date: 2000/06/11 11:41:38 $
**/
*/
#include "ExprResult.h"
@ -59,22 +57,6 @@ MBool BooleanResult::getValue() const {
return this->value;
} //-- getValue
/**
* Sets the value of this BooleanResult
* @param boolean the MBool to use for this BooleanResult's value
**/
void BooleanResult::setValue(MBool boolean) {
this->value = boolean;
} //-- setValue
/**
* Sets the value of this BooleanResult
* @param boolResult the BooleanResult to use for setting this BooleanResult's value
**/
void BooleanResult::setValue(const BooleanResult& boolResult) {
this->value = boolResult.getValue();
} //-- setValue
/*
* Virtual Methods from ExprResult
*/

View File

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: ElementExpr.cpp,v 1.3 2001/01/12 20:06:31 axel%pike.org Exp $
* $Id: ElementExpr.cpp,v 1.4 2001/01/22 09:36:14 kvisco%ziplink.net Exp $
*/
#include "Expr.h"
@ -41,21 +41,7 @@ ElementExpr::ElementExpr() {
} //-- ElementExpr
ElementExpr::ElementExpr(String& name) {
//-- copy name
int idx = name.indexOf(':');
if ( idx >= 0 )
name.subString(0,idx, this->prefix);
else
idx = -1;
name.subString(idx+1, this->name);
//-- set flags
this->isNamespaceWild = (this->prefix.length() == 0);
//-- I know...this should be done is WildCardExpr or someplace
//-- else but I need a fix for now.
this->isNameWild = this->name.isEqual(WILD_CARD);
setName(name);
} //-- ElementExpr
/**
@ -97,6 +83,7 @@ ExprResult* ElementExpr::evaluate(Node* context, ContextState* cs) {
* ContextState then Negative Infinity is returned.
**/
double ElementExpr::getDefaultPriority(Node* node, Node* context, ContextState* cs) {
if (isNameWild) return -0.5;
return 0.0;
} //-- getDefaultPriority
@ -109,8 +96,16 @@ const String& ElementExpr::getName() {
} //-- getName
void ElementExpr::setName(const String& name) {
this->name.clear();
this->name.append(name);
int idx = name.indexOf(':');
if ( idx >= 0 )
name.subString(0,idx, this->prefix);
else
idx = -1;
name.subString(idx+1, this->name);
//-- set flags
this->isNameWild = this->name.isEqual(WILD_CARD);
this->isNamespaceWild = (isNameWild && (this->prefix.length() == 0));
} //-- setName
@ -131,38 +126,39 @@ short ElementExpr::getType() {
* the given context
**/
MBool ElementExpr::matches(Node* node, Node* context, ContextState* cs) {
if ( node) {
if ( node->getNodeType() == Node::ELEMENT_NODE ) {
const String nodeName = node->getNodeName();
int idx = nodeName.indexOf(':');
if ((!node) || (node->getNodeType() != Node::ELEMENT_NODE ))
return MB_FALSE;
if (!isNamespaceWild) {
//-- compare namespaces
String nsURI;
cs->getNameSpaceURIFromPrefix(this->prefix, nsURI);
if (isNamespaceWild && isNameWild) return MB_TRUE;
String nsURI2;
String prefix2;
if (idx > 0) nodeName.subString(0, idx, prefix2);
cs->getNameSpaceURIFromPrefix(prefix2, nsURI2);
const String nodeName = node->getNodeName();
if (!nsURI.isEqual(nsURI2)) return MB_FALSE;
int idx = nodeName.indexOf(':');
}
if (!isNamespaceWild) {
//-- compare namespaces
String nsURI;
// use context to get namespace for testing against
cs->getNameSpaceURIFromPrefix(this->prefix, nsURI);
if (this->isNameWild) return MB_TRUE;
String nsURI2;
String prefix2;
if (idx > 0) nodeName.subString(0, idx, prefix2);
// use source tree to aquire namespace for node
XMLDOMUtils::getNameSpace(prefix2, (Element*) node, nsURI2);
//-- compare local names
if (idx < 0) return nodeName.isEqual(this->name);
else {
String local;
nodeName.subString(idx+1, local);
return local.isEqual(this->name);
}
}
if (!nsURI.isEqual(nsURI2)) return MB_FALSE;
}
if (this->isNameWild) return MB_TRUE;
//-- compare local names
if (idx < 0) return nodeName.isEqual(this->name);
else {
String local;
nodeName.subString(idx+1, local);
return local.isEqual(this->name);
}
return MB_FALSE;
} //-- matches

View File

@ -25,7 +25,7 @@
* - changed constant short declarations in many of the classes
* with enumerations, commented with //--LF
*
* $Id: Expr.h,v 1.8 2000/11/07 10:49:06 kvisco%ziplink.net Exp $
* $Id: Expr.h,v 1.9 2001/01/22 09:36:14 kvisco%ziplink.net Exp $
*/
@ -41,11 +41,12 @@
#include "MITREObject.h"
#include "primitives.h"
#include "NamespaceResolver.h"
#include "XMLDOMUtils.h"
/*
XPath class definitions.
Much of this code was ported from XSL:P.
@version $Revision: 1.8 $ $Date: 2000/11/07 10:49:06 $
@version $Revision: 1.9 $ $Date: 2001/01/22 09:36:14 $
*/
#ifndef TRANSFRMX_EXPR_H
@ -489,8 +490,13 @@ public:
private:
static const String WILD_CARD;
String prefix;
String name;
MBool isWild;
MBool isNameWild;
MBool isNamespaceWild;
}; //-- AttributeExpr
@ -773,61 +779,6 @@ public:
}; //-- TextExpr
/**
* This class represents a WildCardExpr as defined by the XSL
* Working Draft
**/
class WildCardExpr : public NodeExpr {
public:
//------------------/
//- Public Methods -/
//------------------/
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr
* @param ps the ContextState containing the stack information needed
* for evaluation
* @return the result of the evaluation
**/
virtual ExprResult* evaluate(Node* context, ContextState* cs);
/**
* Returns the default priority of this Pattern based on the given Node,
* context Node, and ContextState.
* If this pattern does not match the given Node under the current context Node and
* ContextState then Negative Infinity is returned.
**/
virtual double getDefaultPriority(Node* node, Node* context, ContextState* cs);
/**
* Returns the type of this NodeExpr
* @return the type of this NodeExpr
**/
virtual short getType();
/**
* Determines whether this NodeExpr matches the given node within
* the given context
**/
virtual MBool matches(Node* node, Node* context, ContextState* cs);
/**
* Returns the String representation of this NodeExpr.
* @param dest the String to use when creating the String
* representation. The String representation will be appended to
* any data in the destination String, to allow cascading calls to
* other #toString() methods for Expressions.
* @return the String representation of this NodeExpr.
**/
virtual void toString(String& dest);
}; //-- WildCardExpr
/**
* Represents an ordered list of Predicates,
* for use with Step and Filter Expressions
@ -1088,7 +1039,7 @@ public:
private:
NumberResult numberResult;
double _value;
};
/**

View File

@ -29,13 +29,13 @@
* -- Fixed bug in parse method so that we make sure we check for
* axis identifier wild cards, such as ancestor::*
*
* $Id: ExprLexer.cpp,v 1.10 2001/01/12 20:06:31 axel%pike.org Exp $
* $Id: ExprLexer.cpp,v 1.11 2001/01/22 09:36:15 kvisco%ziplink.net Exp $
*/
/**
* Lexical analyzer for XPath expressions
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.10 $ $Date: 2001/01/12 20:06:31 $
* @version $Revision: 1.11 $ $Date: 2001/01/22 09:36:15 $
**/
#include "ExprLexer.h"
@ -367,9 +367,6 @@ MBool ExprLexer::matchDelimiter(UNICODE_CHAR ch) {
case VERT_BAR:
tokenType = Token::UNION_OP;
break;
case ASTERIX:
tokenType = Token::WILD_CARD;
break;
case AT_SIGN:
tokenType = Token::AT_SIGN;
break;
@ -669,7 +666,8 @@ void ExprLexer::parse(const String& pattern) {
case Token::NULL_TOKEN:
case Token::L_PAREN:
case Token::L_BRACKET:
matchDelimiter(ch);
tokenBuffer.append(ch);
//matchDelimiter(ch);
break;
default:
if ( isOperatorToken(prevToken) ) {

View File

@ -25,7 +25,7 @@
* -- changed constant short declarations in Token and ExprLexer to
* enumerations, commented with //--LF
*
* $Id: ExprLexer.h,v 1.4 2001/01/12 20:06:32 axel%pike.org Exp $
* $Id: ExprLexer.h,v 1.5 2001/01/22 09:36:16 kvisco%ziplink.net Exp $
*/
@ -44,7 +44,7 @@
* This class was ported from XSL:P, an open source Java based
* XSLT processor, written by yours truly.
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.4 $ $Date: 2001/01/12 20:06:32 $
* @version $Revision: 1.5 $ $Date: 2001/01/22 09:36:16 $
**/
class Token {
@ -69,7 +69,6 @@ public:
R_BRACKET,
COMMA,
FUNCTION_NAME,
WILD_CARD,
AT_SIGN,
VAR_REFERENCE,
PARENT_NODE,

View File

@ -30,7 +30,7 @@
* -- fixed bug in ::parsePredicates,
* made sure we continue looking for more predicates.
*
* $Id: ExprParser.cpp,v 1.7 2001/01/12 20:06:32 axel%pike.org Exp $
* $Id: ExprParser.cpp,v 1.8 2001/01/22 09:36:16 kvisco%ziplink.net Exp $
*/
/**
@ -38,7 +38,7 @@
* This class is used to parse XSL Expressions
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @see ExprLexer
* @version $Revision: 1.7 $ $Date: 2001/01/12 20:06:32 $
* @version $Revision: 1.8 $ $Date: 2001/01/22 09:36:16 $
**/
#include "ExprParser.h"
@ -516,65 +516,84 @@ LocationStep* ExprParser::createLocationStep(ExprLexer& lexer) {
//-- get Axis Identifier, if present
Token* tok = lexer.peek();
MBool setDefaultAxis = MB_TRUE;
if ( tok->type == Token::AXIS_IDENTIFIER ) {
//-- eat token
lexer.nextToken();
setDefaultAxis = MB_FALSE;
//-- should switch to a hash here for speed if necessary
if ( ANCESTOR_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ANCESTOR_AXIS;
else if ( ANCESTOR_OR_SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS;
else if ( ATTRIBUTE_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
else if ( CHILD_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::CHILD_AXIS;
else if ( DESCENDANT_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::DESCENDANT_AXIS;
else if ( DESCENDANT_OR_SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS;
else if ( FOLLOWING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::FOLLOWING_AXIS;
else if ( FOLLOWING_SIBLING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS;
else if ( NAMESPACE_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::NAMESPACE_AXIS;
else if ( PARENT_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PARENT_AXIS;
else if ( PRECEDING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PRECEDING_AXIS;
else if ( PRECEDING_SIBLING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS;
else if ( SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::SELF_AXIS;
//-- child axis is default
else {
//-- handle error gracefully, simply ignore invalid axis and
//-- use default. Add error message when message observer
//-- is implemented
setDefaultAxis = MB_TRUE;
switch (tok->type) {
case Token::AXIS_IDENTIFIER:
{
//-- eat token
lexer.nextToken();
//-- should switch to a hash here for speed if necessary
if ( ANCESTOR_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ANCESTOR_AXIS;
else if ( ANCESTOR_OR_SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ANCESTOR_OR_SELF_AXIS;
else if ( ATTRIBUTE_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
else if ( CHILD_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::CHILD_AXIS;
else if ( DESCENDANT_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::DESCENDANT_AXIS;
else if ( DESCENDANT_OR_SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::DESCENDANT_OR_SELF_AXIS;
else if ( FOLLOWING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::FOLLOWING_AXIS;
else if ( FOLLOWING_SIBLING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::FOLLOWING_SIBLING_AXIS;
else if ( NAMESPACE_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::NAMESPACE_AXIS;
else if ( PARENT_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PARENT_AXIS;
else if ( PRECEDING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PRECEDING_AXIS;
else if ( PRECEDING_SIBLING_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::PRECEDING_SIBLING_AXIS;
else if ( SELF_AXIS.isEqual(tok->value) )
axisIdentifier = LocationStep::SELF_AXIS;
//-- child axis is default
else if (!CHILD_AXIS.isEqual(tok->value)) {
//-- handle error gracefully, simply ignore invalid axis and
//-- use default. Add error message when message observer
//-- is implemented
}
break;
}
case Token::AT_SIGN:
//-- eat token
lexer.nextToken();
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
break;
default:
break;
}
lstep->setAxisIdentifier(axisIdentifier);
NodeExpr* nodeExpr = 0;
tok = lexer.peek();
if (!tok) {
///XXXXX We need to create an ErrorExpr or something to
///XXXXX handle errors
}
// NameTest
else if (tok->type == Token::CNAME) {
//-- handle NameTest
//-- eat token
lexer.nextToken();
if (axisIdentifier == LocationStep::ATTRIBUTE_AXIS)
nodeExpr = new AttributeExpr(tok->value);
else
nodeExpr = new ElementExpr(tok->value);
}
// NodeType
else {
NodeExpr* nodeExpr = createNodeExpr(lexer);
}
//-- parse NodeExpr
NodeExpr* nodeExpr = createNodeExpr(lexer);
lstep->setNodeExpr(nodeExpr);
//-- set default axis identifiers
if ((setDefaultAxis) && (nodeExpr)) {
switch ( nodeExpr->getType() ) {
case NodeExpr::ATTRIBUTE_EXPR:
axisIdentifier = LocationStep::ATTRIBUTE_AXIS;
break;
default:
axisIdentifier = LocationStep::CHILD_AXIS;
}
}
lstep->setAxisIdentifier(axisIdentifier);
//-- handle predicates
@ -589,6 +608,10 @@ LocationStep* ExprParser::createLocationStep(ExprLexer& lexer) {
return lstep;
} //-- createLocationPath
/**
* This method only handles comment(), text(), processing-instructing() and node()
*
**/
NodeExpr* ExprParser::createNodeExpr(ExprLexer& lexer) {
//cout << "creating NodeExpr: "<<endl;
@ -605,12 +628,6 @@ NodeExpr* ExprParser::createNodeExpr(ExprLexer& lexer) {
String* errMsg = 0;
switch ( tok->type ) {
case Token::CNAME :
nodeExpr = new ElementExpr(tok->value);
break;
case Token::WILD_CARD:
nodeExpr = new WildCardExpr();
break;
case Token::COMMENT:
nodeExpr = new BasicNodeExpr(NodeExpr::COMMENT_EXPR);
errMsg = parseParameters(&params, lexer);
@ -635,24 +652,8 @@ NodeExpr* ExprParser::createNodeExpr(ExprLexer& lexer) {
//-- ignore errMsg for now
delete errMsg;
break;
case Token::AT_SIGN:
tok = lexer.nextToken();
if ( !tok ) {
//-- handle error
}
else if (tok->type == Token::CNAME) {
nodeExpr = new AttributeExpr(tok->value);
}
else if ( tok->type == Token::WILD_CARD ) {
AttributeExpr* attExpr = new AttributeExpr();
attExpr->setWild(MB_TRUE);
nodeExpr = attExpr;
}
else {
//-- handle error
}
break;
default:
//XXXX ignore error for now
break;
}
return nodeExpr;
@ -795,7 +796,6 @@ MBool ExprParser::isNodeTypeToken(Token* token) {
switch ( token->type ) {
case Token::AT_SIGN:
case Token::CNAME:
case Token::WILD_CARD:
case Token::COMMENT:
case Token::NODE :
case Token::PI :

View File

@ -23,15 +23,15 @@
* Larry Fitzpatrick, OpenText, lef@opentext.com
* -- changed constant short result types to enum
*
* $Id: ExprResult.h,v 1.7 2001/01/12 20:06:33 axel%pike.org Exp $
* $Id: ExprResult.h,v 1.8 2001/01/22 09:36:17 kvisco%ziplink.net Exp $
*/
#include "MITREObject.h"
#include "TxObject.h"
#include "dom.h"
#include "primitives.h"
#ifndef MITREXSL_EXPRRESULT_H
#define MITREXSL_EXPRRESULT_H
#ifndef TRANSFRMX_EXPRRESULT_H
#define TRANSFRMX_EXPRRESULT_H
/*
@ -41,11 +41,9 @@
* BooleanResult, ExprResult, NumberResult, StringResult
* <BR/>
* Note: for NodeSet, see NodeSet.h <BR />
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.7 $ $Date: 2001/01/12 20:06:33 $
*/
class ExprResult : public MITREObject {
class ExprResult : public TxObject {
public:
@ -96,10 +94,6 @@ public:
MBool getValue() const;
void setValue(MBool boolean);
void setValue(const BooleanResult& boolResult);
virtual short getResultType();
virtual void stringValue(String& str);
virtual MBool booleanValue();
@ -118,11 +112,6 @@ public:
NumberResult(const NumberResult& nbrResult);
double getValue() const;
void setValue(double dbl);
void setValue(const NumberResult& nbrResult);
MBool isNaN() const;
virtual short getResultType();
@ -146,7 +135,6 @@ public:
StringResult(const StringResult& strResult);
String& getValue();
void setValue(const String& str);
virtual short getResultType();
virtual void stringValue(String& str);

View File

@ -21,12 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: LocationStep.cpp,v 1.3 2001/01/12 20:06:34 axel%pike.org Exp $
* $Id: LocationStep.cpp,v 1.4 2001/01/22 09:36:17 kvisco%ziplink.net Exp $
*/
/*
Implementation of an XPath LocationStep
@version $Revision: 1.3 $ $Date: 2001/01/12 20:06:34 $
@version $Revision: 1.4 $ $Date: 2001/01/22 09:36:17 $
*/
#include "Expr.h"
@ -281,6 +281,9 @@ void LocationStep::toString(String& str) {
case ANCESTOR_OR_SELF_AXIS :
str.append("ancestor-or-self::");
break;
case ATTRIBUTE_AXIS:
str.append("attribute::");
break;
case DESCENDANT_AXIS:
str.append("descendant::");
break;

View File

@ -42,7 +42,6 @@ XPATH_OBJS = AdditiveExpr.o \
TextExpr.o \
UnionExpr.o \
VariableRefExpr.o \
WildCardExpr.o \
XPathNames.o
FUNCTION_CALL_OBJS = \

View File

@ -21,7 +21,7 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: NumberExpr.cpp,v 1.1 2000/04/06 07:45:34 kvisco%ziplink.net Exp $
* $Id: NumberExpr.cpp,v 1.2 2001/01/22 09:36:18 kvisco%ziplink.net Exp $
*/
#include "Expr.h"
@ -31,11 +31,11 @@
//--------------/
NumberExpr::NumberExpr() {
numberResult.setValue(0.0);
_value = 0.0;
} //-- NumberExpr
NumberExpr::NumberExpr(double dbl) {
numberResult.setValue(dbl);
_value = dbl;
} //-- NumberExpr
NumberExpr::~NumberExpr() {
@ -49,7 +49,7 @@ NumberExpr::~NumberExpr() {
* @return the result of the evaluation
**/
ExprResult* NumberExpr::evaluate(Node* context, ContextState* cs) {
return new NumberResult(numberResult);
return new NumberResult(_value);
} //-- evaluate
/**
@ -61,6 +61,10 @@ ExprResult* NumberExpr::evaluate(Node* context, ContextState* cs) {
* @return the String representation of this Expr.
**/
void NumberExpr::toString(String& str) {
numberResult.stringValue(str);
int intVal = (int)_value;
if (intVal == _value) { //-- no fraction
Integer::toString(intVal, str);
}
else Double::toString(_value, str);
} //-- toString

View File

@ -25,7 +25,7 @@
* Nisheeth Ranjan, nisheeth@netscape.com
* -- implemented rint function, which was not available on Windows.
*
* $Id: NumberFunctionCall.cpp,v 1.10 2001/01/12 20:06:36 axel%pike.org Exp $
* $Id: NumberFunctionCall.cpp,v 1.11 2001/01/22 09:36:18 kvisco%ziplink.net Exp $
*/
/*
@ -89,7 +89,7 @@ static double rint(double r)
* @return the result of the evaluation
**/
ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
NumberResult* result = new NumberResult();
NumberResult* result = 0;
ListIterator* iter = params.iterator();
int argc = params.getLength();
Expr* param = 0;
@ -99,20 +99,20 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
case CEILING :
if ( requireParams(1, 1, cs) ) {
double dbl = evaluateToNumber((Expr*)iter->next(), context, cs);
result->setValue(ceil(dbl));
result = new NumberResult(ceil(dbl));
}
else {
result->setValue(0.0);
}
break;
result = new NumberResult(0.0);
}
break;
case FLOOR :
if ( requireParams(1, 1, cs) ) {
double dbl = evaluateToNumber((Expr*)iter->next(), context, cs);
result->setValue(floor(dbl));
result = new NumberResult(floor(dbl));
}
else {
result->setValue(0.0);
result = new NumberResult(0.0);
}
break;
@ -123,15 +123,14 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
if ((dbl>0.0) && (res == dbl-0.5)) {
// fix for native round function from math library (rint()) which does not
// match the XPath spec for positive half values
result->setValue(res+1.0);
}
else {
result->setValue(res);
result = new NumberResult(res+1.0);
}
else
result = new NumberResult(res);
break;
}
else result->setValue(0.0);
break;
else result = new NumberResult(0.0);
break;
case SUM :
double numResult;
@ -159,7 +158,7 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
if (iter->hasNext()) {
param = (Expr*) iter->next();
ExprResult* exprResult = param->evaluate(context, cs);
result->setValue(exprResult->numberValue());
result = new NumberResult(exprResult->numberValue());
delete exprResult;
}
else {
@ -167,16 +166,16 @@ ExprResult* NumberFunctionCall::evaluate(Node* context, ContextState* cs) {
XMLDOMUtils::getNodeValue(context, &resultStr);
if ( cs->isStripSpaceAllowed(context) &&
XMLUtils::shouldStripTextnode(resultStr)) {
result->setValue(Double::NaN);
result = new NumberResult(Double::NaN);
}
else {
Double dbl(resultStr);
result->setValue(dbl.doubleValue());
result = new NumberResult(dbl.doubleValue());
}
}
}
else {
result->setValue(Double::NaN);
result = new NumberResult(Double::NaN);
}
break;
}

View File

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: NumberResult.cpp,v 1.5 2000/06/11 12:23:11 Peter.VanderBeken%pandora.be Exp $
* $Id: NumberResult.cpp,v 1.6 2001/01/22 09:36:18 kvisco%ziplink.net Exp $
*/
/**
* NumberResult
* Represents the a number as the result of evaluating an Expr
* @author <A HREF="mailto:kvisco@ziplink.net">Keith Visco</A>
* @version $Revision: 1.5 $ $Date: 2000/06/11 12:23:11 $
* @version $Revision: 1.6 $ $Date: 2001/01/22 09:36:18 $
**/
#include "ExprResult.h"
@ -66,21 +66,6 @@ double NumberResult::getValue() const {
MBool NumberResult::isNaN() const {
return Double::isNaN(value);
} //-- isNaN
/**
* Sets the value of this NumberResult
* @param dbl the double to use for this NumberResult's value
**/
void NumberResult::setValue(double dbl) {
this->value = dbl;
} //-- setValue
/**
* Sets the value of this NumberResult
* @param nbrResult the NumberResult to use for setting this NumberResult's value
**/
void NumberResult::setValue(const NumberResult& nbrResult) {
this->value = nbrResult.getValue();
} //-- setValue
/*
* Virtual Methods from ExprResult

View File

@ -21,12 +21,12 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: Parser.cpp,v 1.4 2000/07/23 07:25:29 kvisco%ziplink.net Exp $
* $Id: Parser.cpp,v 1.5 2001/01/22 09:36:19 kvisco%ziplink.net Exp $
*/
/**
* Test App for Expressions
* @version $Revision: 1.4 $ $Date: 2000/07/23 07:25:29 $
* @version $Revision: 1.5 $ $Date: 2001/01/22 09:36:19 $
**/
#include <iostream.h>
@ -52,7 +52,7 @@ void main(int argc, char** argv) {
//String pattern("*[1]foo|*[1]/bar|*[1]/baz");
//-- Current Test
String pattern("(4+5)-(9+9)");
String pattern("*[test()='foo']");
cout <<"Lexically Analyzing: "<<pattern<<endl;
cout<<endl;
@ -120,9 +120,6 @@ void main(int argc, char** argv) {
case Token::FUNCTION_NAME:
cout<<"#FUNCTION_NAME";
break;
case Token::WILD_CARD:
cout << "#WILDCARD";
break;
case Token::NUMBER:
cout << "#NUMBER";
break;
@ -157,7 +154,8 @@ void main(int argc, char** argv) {
ExprParser parser;
Expr* expr = (Expr*)parser.createExpr(pattern);
//Expr* expr = (Expr*)parser.createExpr(pattern);
Expr* expr = (Expr*)parser.createPatternExpr(pattern);
cout << "Checking result"<<endl;
@ -181,6 +179,7 @@ void main(int argc, char** argv) {
cout << "StringResult: " << strResult.numberValue() << endl;
//-- AttributeValueTemplate test
cout << endl << "----------------------" << endl << endl;
String avt("this is a {text()} of {{{{attr value templates}}}}");
expr = parser.createAttributeValueTemplate(avt);
resultString.clear();

View File

@ -21,14 +21,14 @@
* Keith Visco, kvisco@ziplink.net
* -- original author.
*
* $Id: StringResult.cpp,v 1.5 2000/06/11 12:29:35 Peter.VanderBeken%pandora.be Exp $
* $Id: StringResult.cpp,v 1.6 2001/01/22 09:36:19 kvisco%ziplink.net Exp $
*/
/**
* StringResult
* Represents a String as a Result of evaluating an Expr
* @author <a href="mailto:kvisco@ziplink.net">Keith Visco</a>
* @version $Revision: 1.5 $ $Date: 2000/06/11 12:29:35 $
* @version $Revision: 1.6 $ $Date: 2001/01/22 09:36:19 $
**/
#include "ExprResult.h"
@ -64,15 +64,6 @@ String& StringResult::getValue() {
return this->value;
} //-- getValue
/**
* Sets the value of this StringResult
* @param str the String to use for this StringResult's value
**/
void StringResult::setValue(const String& str){
// copy str
this->value = str;
} //-- setValue
/*
* Virtual Methods from ExprResult
*/