[XML-SIG] Announcing PyXPath 1.2

Jeremy Kloth jeremy.kloth@fourthought.com
Thu, 18 Jan 2001 20:09:41 -0700


"Martin v. Loewis" wrote:
> module XPath{
> 
>   typedef wstring DOMString;
> 
>   const unsigned short ABSOLUTE_LOCATION_PATH = 1;
>   const unsigned short ABBREVIATED_ABSOLUTE_LOCATION_PATH = 2;
>   const unsigned short RELATIVE_LOCATION_PATH = 3;
>   const unsigned short ABBREVIATED_RELATIVE_LOCATION_PATH = 4;
>   const unsigned short STEP_EXPR = 5; // STEP would conflict with Step in case
>   const unsigned short NODE_TEST = 6;
>   const unsigned short NAME_TEST = 7;

>   const unsigned short BINARY_EXPR = 8;
Since there are two basic types of binary expressions, I suggest
splitting this into a BOOLEAN_EXPR and NUMERIC_EXPR.  They do offer
quite different functionality.

>   const unsigned short UNARY_EXPR = 9;
This would be considered a NUMERIC_EXPR.

>   const unsigned short PATH_EXPR = 10;
>   const unsigned short ABBREVIATED_PATH_EXPR = 11; // filter '//' path
>   const unsigned short FILTER_EXPR = 12;
>   const unsigned short VARIABLE_REFERENCE = 13;
>   const unsigned short LITERAL_EXPR = 14;
>   const unsigned short NUMBER_EXPR = 15;
>   const unsigned short FUNCTION_CALL = 16;
> 
>   interface Expr{
>     readonly attribute unsigned short exprType;
>   };
> 
>   interface AbsoluteLocationPath;
>   interface AbbreviatedAbsoluteLocationPath;
>   interface RelativeLocationPath;
>   interface Step;
>   interface AxisSpecifier;
>   interface NodeTest;
>   typedef sequence<Expr> PredicateList, ExprList;
>   interface NameTest;
>   interface BinaryExpr;
>   interface UnaryExpr;
>   interface UnionExpr;
>   interface PathExpr;
>   interface FilterExpr;
>   interface VariableReference;
>   interface Literal;
>   interface Number;
>   interface FunctionCall;
> 
>   interface ExprFactory{
>     AbsoluteLocationPath createAbsoluteLocationPath(in RelativeLocationPath p);
>     AbsoluteLocationPath createAbbreviatedAbsoluteLocationPath(in RelativeLocationPath p);
>     RelativeLocationPath createRelativeLocationPath(in RelativeLocationPath left,
>                                                     in Step right);
>     RelativeLocationPath createAbbreviatedRelativeLocationPath(in RelativeLocationPath left,
>                                                                in Step right);
> 
>     Step createStep(in AxisSpecifier axis, in NodeTest test, in PredicateList predicates);
>     // . is represented as self::node(); .. as parent::node()
>     Step createAbbreviatedStep(in boolean dotdot); // false for .; true for ..
>     // An omitted axisname is created as CHILD; @ is created as ATTRIBUTE
> 
>     AxisSpecifier createAxisSpecifier(in unsigned short name);
> 
>     NodeTest createNodeTest(in unsigned short type);
>     NameTest createNameTest(in DOMString prefix, in DOMString localName);
> 

>     BinaryExpr createBinaryExpr(in unsigned short operator, in Expr left, in Expr right);
> 
>     UnaryExpr createUnaryExpr(in Expr exp);
> 

See above for Binary and Unary expressions.

>     PathExpr createPathExpr(in Expr filter, in Expr path);
>     // filter '//' path
>     PathExpr createAbbreviatedPathExpr(in Expr filter, in Expr path);
> 
>     FilterExpr createFilterExpr(in Expr filter, in Expr predicate);
> 
>     // the name must still contain the leading $
>     VariableReference createVariableReference(in DOMString name);

name can be a qualified name.  use prefix, localname

> 
>     Literal createLiteral(in DOMString literal);
>     Number createNumber(in DOMString value);
>     FunctionCall createFunctionCall(in DOMString name, in ExprList args);

See createVariableReference

>   };
> 
>   interface Parser{
>     Expr parseLocationPath(in DOMString path); // returns absolute or relative path, or step
>   };

This should probably be parseExpression, since the Expr is the primary
construct.  (See XPath spec - sect 1)

> 
>   interface AbsoluteLocationPath:Expr{
>     /* '/' relative-opt, or '//' relative */
>     readonly attribute Expr relative; // step or relative path

relative may be null  (case of '/')

>   };
> 
>   interface RelativeLocationPath:Expr{
>     readonly attribute Expr left; // step or relative path
>     readonly attribute Step right;
>   };
> 
>   interface Step:Expr{
>     readonly attribute AxisSpecifier axis;
>     readonly attribute NodeTest test;
>     readonly attribute PredicateList predicates;
>   };
> 
>   const unsigned short ANCESTOR = 1;
>   const unsigned short ANCESTOR_OR_SELF = 2;
>   const unsigned short _ATTRIBUTE = 3; // attribute is a keyword
>   const unsigned short CHILD = 4;
>   const unsigned short DESCENDANT = 5;
>   const unsigned short DESCENDANT_OR_SELF = 6;
>   const unsigned short FOLLOWING = 7;
>   const unsigned short FOLLOWING_SIBLING = 8;
>   const unsigned short NAMESPACE = 9;
>   const unsigned short PARENT = 10;
>   const unsigned short PRECEDING = 11;
>   const unsigned short PRECEDING_SIBLING = 12;
>   const unsigned short SELF = 13;

Maybe suffix the types with '_AXIS'?

>   interface AxisSpecifier:Expr{
>     readonly attribute unsigned short name;

Should we use axisType just for consistancy?

>   };
> 
>   const unsigned short COMMENT = 1;
>   const unsigned short TEXT = 2;
>   const unsigned short PROCESSING_INSTRUCTION = 3;
>   const unsigned short NODE = 4;

suffix of '_NODE_TEST' ??

>   interface NodeTest:Expr{
>     readonly attribute unsigned short test;

testType ??

>     readonly attribute DOMString literal; // only for PROCESSING_INSTRUCTION
>   };
> 
>   interface NameTest:Expr{
>     readonly attribute DOMString prefix; // may be null
>     readonly attribute DOMString localName; // may be "*"
>   };
> 
>   const unsigned short BINOP_OR = 1;
>   const unsigned short BINOP_AND = 2;
>   const unsigned short BINOP_EQ = 3;
>   const unsigned short BINOP_NEQ = 4;
>   const unsigned short BINOP_LT = 5;
>   const unsigned short BINOP_GT = 6;
>   const unsigned short BINOP_LE = 7;
>   const unsigned short BINOP_GE = 8;
>   const unsigned short BINOP_PLUS = 9;
>   const unsigned short BINOP_MINUS = 10;
>   const unsigned short BINOP_TIMES = 11;
>   const unsigned short BINOP_DIV = 12;
>   const unsigned short BINOP_MOD = 13;
>   const unsigned short BINOP_UNION = 14;

possibly ??_OPERATOR as apposed to BINOP_??

>   interface BinaryExpr:Expr{
>     readonly attribute unsigned short operator;
>     readonly attribute Expr left,right;
>   };

> 
>     UnaryExpr createUnaryExpr(in Expr exp);
> 
See factory functions above.

>   interface PathExpr:Expr{
>     readonly attribute Expr filter;
>     readonly attribute Expr path;
>   };
> 
>   interface FilterExpr:Expr{
>     readonly attribute Expr filter;
>     readonly attribute Expr predicate;
>   };
> 
>   interface VariableReference:Expr{
>     readonly attribute DOMString name;
>   };
> 
>   interface Literal:Expr{
>     readonly attribute DOMString value;
>   };
> 
>   interface Number:Expr{
>     readonly attribute double value;
>   };
> 
>   interface FunctionCall:Expr{
>     readonly attribute DOMString name;
>     readonly attribute ExprList args;
>   };
> 
> };
> 
> _______________________________________________
> XML-SIG maillist  -  XML-SIG@python.org
> http://www.python.org/mailman/listinfo/xml-sig

-- 
Jeremy Kloth                             Consultant
jeremy.kloth@fourthought.com             (303)583-9900 x 105
Fourthought, Inc.                        http://www.fourthought.com
Software-engineering, knowledge-management, XML, CORBA, Linux, Python