
//  -*- c++ -*-

#ifndef XPATH_PARSER_H
#define XPATH_PARSER_H

#include <dom/dom_node.h>

namespace XPath {

/**
 * Base-class of nodes in an XPath expression AST.
 */
class XPathNode
{
public:
    enum NodeType {
	NullNode, AxisNode, BinaryOpNode, FunctionCallNode, LiteralNode,
	LocationPathNode, NodeTestNode, UnaryOpNode, VariableRefNode
    };

    XPathNode();
    XPathNode( const XPathNode &node );
    XPathNode( XPathNode::NodeType nodeType );

    virtual ~XPathNode();

    XPathNode::NodeType nodeType() const { return type; }

    virtual QString qstring() const;

private:
    NodeType type;
};

/**
 * Represents an XPath location path.
 */
class LocationPath : public XPathNode
{
public:
    enum LocationPathType {
	Relative, Absolute, AbbrevRelative, AbbrevAbsolute
    };

private:
    LocationPathType ptype;
};

/**
 * Represents an XPath variable reference.
 */
class VariableRef : public XPathNode
{
public:
};

/**
 * Represents an XPath binary operator.
 */
class BinaryOp : public XPathNode
{
public:
    enum BinaryOpType {
	NullBinaryOp,
	Or, And, Equality,
	LessThan, GreaterThan, LessThanEqual, GreaterThanEqual,
	Plus, Minus, Mul, Div, Mod,
	Union
    };

    BinaryOp();
    BinaryOp( const BinaryOp &node );
    BinaryOp( ushort bop );
    virtual ~BinaryOp();

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort op;
};

/**
 * Represents an XPath unary operator.
 */
class UnaryOp : public XPathNode
{
public:
    enum UnaryOpType {
	UnaryMinus
    };

private:
    UnaryOpType optype;
};

/**
 * Represents an XPath node test.
 */
class NodeTest : public XPathNode
{
public:
    enum NodeTestId {
	AnyName, NCName, QName,
	CommentNode, TextNode, ProcessInstructNode, NodeNode
    };

private:
    ushort id;
};

/**
 * Represents an XPath function call.
 */
class FunctionCall : public XPathNode
{
public:
    enum FunctionId {
	NullFunction,

	// node-set functions
	Last, Position, Count,
	Id, LocalName, NamespaceURI, Name,

	// string functions
	String,	Concat, StartsWith, Contains,
	SubStringBefore, SubStringAfter, SubString,
	StringLength, NormalizeSpace, Translate,

	// boolean functions
	Boolean, Not, True, False, Lang,

	// number functions
	Number, Sum, Floor, Ceiling, Round,

	// Reserves space for XPath. (XSLT needs to add new funcs).
	LastReserved = 256
    };

    FunctionCall();
    FunctionCall( const FunctionCall &node );
    FunctionCall( ushort fid );
    virtual ~FunctionCall();

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort id;
};

/**
 * Represents a reference to an XPath axis.
 */
class Axis : public XPathNode
{
public:
    enum Id {
	NullAxis,
	Child, Descendent, Parent, Ancestor,
	FollowingSibling, PrecedingSibling,
	Following, Preceding,
	Attribute, Namespace,
	Self, DescendentOrSelf, AncestorOrSelf
    };

    Axis();
    Axis( const Axis &node );
    Axis( ushort fid );
    virtual ~Axis();

    virtual QString name() const;
    virtual QString qstring() const;

private:
    ushort id;
};

}; // namespace XPath

#endif // XPATH_PARSER_H

// Local Variables:
// c-basic-offset: 4
// End:

