You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by vi...@apache.org on 2003/04/01 01:05:55 UTC

cvs commit: xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser SimpleNode.java

villard     2003/03/31 15:05:54

  Modified:    java/xpath_rwapi/src2/org/apache/xpath/impl Tag: xslt20
                        FunctionCallImpl.java OperatorImpl.java
               java/xpath_rwapi/src2/org/apache/xpath/test Tag: xslt20
                        TestSamples.xml TestSamples.java
               java/xpath_rwapi/src2/org/apache/xpath/impl/parser Tag:
                        xslt20 SimpleNode.java
  Log:
  - Implementation of patterns. From the API point of view, a pattern is a regular expression.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +2 -0      xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/FunctionCallImpl.java
  
  Index: FunctionCallImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/FunctionCallImpl.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- FunctionCallImpl.java	27 Mar 2003 21:53:24 -0000	1.1.2.4
  +++ FunctionCallImpl.java	31 Mar 2003 23:05:52 -0000	1.1.2.5
  @@ -68,6 +68,8 @@
    */
   public class FunctionCallImpl extends OperatorImpl implements FunctionCall {
   
  +	// TODO: Define (at least) two functions: id and key (used for patterns)
  +
   	/**
   	 * Name of the function
   	 */
  
  
  
  1.1.2.4   +11 -3     xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/OperatorImpl.java
  
  Index: OperatorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/Attic/OperatorImpl.java,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- OperatorImpl.java	28 Mar 2003 22:47:40 -0000	1.1.2.3
  +++ OperatorImpl.java	31 Mar 2003 23:05:52 -0000	1.1.2.4
  @@ -127,18 +127,22 @@
                   break;
   
               case XPathTreeConstants.JJTPATHEXPR:
  +            case XPathTreeConstants.JJTPATHPATTERN:
                   m_exprType = PATH_EXPR;
                   m_opType = SLASH_STEP;
   
                   break;
   
               case XPathTreeConstants.JJTUNIONEXPR:
  +			case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR:
  +            case XPathTreeConstants.JJTPATTERN:
                   m_exprType = COMBINE_EXPR;
   
                   // opType is not known yet
                   break;
   
               case XPathTreeConstants.JJTFUNCTIONCALL:
  +            case XPathTreeConstants.JJTIDKEYPATTERN:
   
                   // ignore : see FunctionCallImpl subclass
                   break;
  @@ -200,7 +204,7 @@
           m_exprType = expr.m_exprType;
           m_opType = expr.m_opType;
   
  -       m_children = expr.cloneChildren();
  +        m_children = expr.cloneChildren();
       }
   
       /**
  @@ -323,9 +327,12 @@
           {
               if (((SimpleNode) n).canBeReduced())
               {
  -                if ((m_exprType == SEQUENCE_EXPR)
  +                if (((m_exprType == SEQUENCE_EXPR)
                           && (n.jjtGetNumChildren() > 0)
                           && (n.jjtGetChild(0).getId() == XPathTreeConstants.JJTEXPRSEQUENCE))
  +                        || ((id == XPathTreeConstants.JJTPATTERN)
  +                        && (n.jjtGetNumChildren() > 0)
  +                        && (n.jjtGetChild(0).getId() == XPathTreeConstants.JJTPATTERN)))
                   {
                       super.jjtInsertNodeChildren(n.jjtGetChild(0));
                   }
  @@ -346,10 +353,11 @@
        */
       public boolean canBeReduced()
       {
  -        if (m_exprType == SEQUENCE_EXPR)
  +        if (m_exprType == SEQUENCE_EXPR || id == XPathTreeConstants.JJTPATTERN)
           {
               return (m_children == null) || (m_children.length <= 1);
           }
  +        		
   
           return super.canBeReduced();
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.8   +41 -1     xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.xml
  
  Index: TestSamples.xml
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.xml,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- TestSamples.xml	27 Mar 2003 21:53:25 -0000	1.1.2.7
  +++ TestSamples.xml	31 Mar 2003 23:05:53 -0000	1.1.2.8
  @@ -988,7 +988,47 @@
   			</node>			
   		</ast>
   	</expr-->
  -
  +	
  +	
  +	<!-- Match pattern expr -->
  +	
  +	<expr value="a" pattern="true">
  +		<ast>
  +			<node name="PathPattern">
  +				<node name="PatternStep">
  +					<node name="NameTest"/>	
  +				</node>			
  +			</node>
  +		</ast>
  +	</expr>
  +		
  +	
  +	<expr value="a|b" pattern="true">
  +		<ast>
  +			<node name="Pattern">
  +				<node name="PathPattern">
  +					<node name="PatternStep">
  +						<node name="NameTest"/>	
  +					</node>
  +				</node>
  +				<node name="PathPattern">
  +					<node name="PatternStep">
  +						<node name="NameTest"/>	
  +					</node>
  +				</node>
  +			</node>
  +		</ast>
  +	</expr>
  +	
  +	<expr value="id('a')" pattern="true">
  +		<ast>
  +			<node name="IdKeyPattern">
  +				<node name="StringLiteral"/>	
  +			</node>
  +		</ast>
  +	</expr>
  +	
  +	
   	<!-- Semantically invalid expression (parser should return an error) -->	
   	
   	<expr value="toto/(45+23)" valid="false"/>
  
  
  
  1.1.2.7   +109 -73   xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.java
  
  Index: TestSamples.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/test/Attic/TestSamples.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- TestSamples.java	27 Mar 2003 21:53:25 -0000	1.1.2.6
  +++ TestSamples.java	31 Mar 2003 23:05:53 -0000	1.1.2.7
  @@ -85,6 +85,7 @@
   import org.xml.sax.InputSource;
   
   import java.io.StringReader;
  +
   import java.math.BigInteger;
   
   import javax.xml.parsers.DocumentBuilder;
  @@ -161,17 +162,18 @@
                   + pathExpr.getString(false));
   
               StepExpr se = (StepExpr) pathExpr.getOperand(0); // first step
  -            se.appendPredicate(exprFct.createIntegerLiteralExpr(BigInteger.valueOf(50)));
  +            se.appendPredicate(exprFct.createIntegerLiteralExpr(
  +                    BigInteger.valueOf(50)));
               System.out.println("/toto[50]/descendant::titi =? "
                   + pathExpr.getString(true));
               System.out.println("/child::toto[50]/descendant::titi =? "
                   + pathExpr.getString(false));
  -                
  +
               pathExpr.removeOperand(se);
  -			System.out.println("/descendant::titi =? "
  -							+ pathExpr.getString(true));
  -						System.out.println("/descendant::titi =? "
  -							+ pathExpr.getString(false));
  +            System.out.println("/descendant::titi =? "
  +                + pathExpr.getString(true));
  +            System.out.println("/descendant::titi =? "
  +                + pathExpr.getString(false));
   
               // Test visitor - anonymous class used
               pathExpr.visit(new Visitor()
  @@ -270,106 +272,131 @@
           SimpleNode tree;
           XPath parser;
   
  +        parser = new XPath(new StringReader(xpathString));
  +
  +        boolean isPattern = "true".equals(((Element) node).getAttribute(
  +                    "pattern"));
  +
           try
           {
  -            parser = new XPath(new StringReader(xpathString));
  -
  -            try
  +            if (isPattern)
  +            {
  +                tree = parser.MatchPattern();
  +            }
  +            else
               {
                   tree = parser.XPath2();
  +            }
   
  -                if ("false".equals(((Element) node).getAttribute("valid")))
  +            if ("false".equals(((Element) node).getAttribute("valid")))
  +            {
  +                // the parser should have raise an exception
  +                System.err.println(
  +                    "The expression has not been detected as invalid!");
  +                testOK = false;
  +            }
  +            else
  +            {
  +                if (SimpleNode.PRODUCE_RAW_TREE)
                   {
  -                    // the parser should have raise an exception
  -                    System.err.println(
  -                        "The expression has not been detected as invalid!");
  -                    testOK = false;
  +                    //  if (dumpTree)
  +                    //{
  +                    tree.dump("|");
  +
  +                    //   }
                   }
                   else
                   {
  -                    if (SimpleNode.PRODUCE_RAW_TREE)
  -                    {
  -                        //  if (dumpTree)
  -                        //{
  -                        tree.dump("|");
  +                    Expr expr = (Expr) tree.jjtGetChild(0);
   
  -                        //   }
  -                    }
  -                    else
  -                    {
  -                        Expr expr = (Expr) tree.jjtGetChild(0);
  +                    // Gets the reference AST to compare with
  +                    NodeList astNodes = ((Element) node).getElementsByTagName(
  +                            "ast");
   
  -                        // Gets the reference AST to compare with
  -                        NodeList astNodes = ((Element) node)
  -                            .getElementsByTagName("ast");
  +                    if ((astNodes != null) && (astNodes.getLength() >= 1))
  +                    {
  +                        Node astNode = astNodes.item(0);
   
  -                        if ((astNodes != null) && (astNodes.getLength() >= 1))
  +                        if (!checkAST((SimpleNode) expr,
  +                                    (Element) ((Element) astNode).getElementsByTagName(
  +                                        "node").item(0)))
                           {
  -                            Node astNode = astNodes.item(0);
  +                            System.err.println(
  +                                "Generated AST doesn't match the reference one");
   
  -                            if (!checkAST((SimpleNode) expr,
  -                                        (Element) ((Element) astNode).getElementsByTagName(
  -                                            "node").item(0)))
  -                            {
  -                                System.err.println(
  -                                    "Generated AST doesn't match the reference one");
  +                            tree.dump("|");
   
  -                                tree.dump("|");
  +                            // Produce the raw tree
  +                            System.err.println("Raw tree is");
   
  -                                // Produce the raw tree
  -                                System.err.println("Raw tree is");
  +                            SimpleNode.PRODUCE_RAW_TREE = true;
   
  -                                SimpleNode.PRODUCE_RAW_TREE = true;
  +                            parser = new XPath(new StringReader(xpathString));
   
  -                                parser = new XPath(new StringReader(xpathString));
  +                            if (isPattern)
  +                            {
  +                                tree = parser.MatchPattern();
  +                            }
  +                            else
  +                            {
                                   tree = parser.XPath2();
  -                                tree.dump("|");
  -
  -                                SimpleNode.PRODUCE_RAW_TREE = false;
                               }
  +
  +                            tree.dump("|");
  +
  +                            SimpleNode.PRODUCE_RAW_TREE = false;
                           }
  -                        else
  -                        {
  -                            System.err.println("No reference AST provided");
  -                        }
  +                    }
  +                    else
  +                    {
  +                        System.err.println("No reference AST provided");
  +                    }
   
  -                        String ab = expr.getString(true);
  +                    String ab = expr.getString(true);
   
  -                        String norm = ((Element) node).getAttribute(
  -                                "normalized-round-trip");
  +                    String norm = ((Element) node).getAttribute(
  +                            "normalized-round-trip");
   
  -                        if ("".equals(norm))
  -                        {
  -                            norm = xpathString;
  -                        }
  +                    if ("".equals(norm))
  +                    {
  +                        norm = xpathString;
  +                    }
   
  -                        if (!ab.equals(norm))
  -                        {
  -                            System.err.print(
  -                                "Bad external or internal representation: ");
  -                            System.err.println(ab + "  !=  " + xpathString);
  +                    if (!ab.equals(norm))
  +                    {
  +                        System.err.print(
  +                            "Bad external or internal representation: ");
  +                        System.err.println(ab + "  !=  " + xpathString);
   
  -                            tree.dump("|");
  +                        tree.dump("|");
   
  -                            // Produce the raw tree
  -                            System.err.println("Raw tree is");
  +                        // Produce the raw tree
  +                        System.err.println("Raw tree is");
   
  -                            SimpleNode.PRODUCE_RAW_TREE = true;
  +                        SimpleNode.PRODUCE_RAW_TREE = true;
   
  -                            parser = new XPath(new StringReader(xpathString));
  -                            tree = parser.XPath2();
  -                            tree.dump("|");
  +                        parser = new XPath(new StringReader(xpathString));
   
  -                            SimpleNode.PRODUCE_RAW_TREE = false;
  -                            testOK = false;
  +                        if (isPattern)
  +                        {
  +                            tree = parser.MatchPattern();
                           }
  +                        else
  +                        {
  +                            tree = parser.XPath2();
  +                        }
  +
  +                        tree.dump("|");
  +
  +                        SimpleNode.PRODUCE_RAW_TREE = false;
  +                        testOK = false;
                       }
                   }
               }
  -            catch (ParseException e)
  -            {
  -                System.err.println("Parsing error occurs: " + e.getMessage());
  -            }
  +        }
  +        catch (ParseException e)
  +        {
  +            System.err.println("Parsing error occurs: " + e.getMessage());
           }
           catch (RuntimeException e)
           {
  @@ -379,7 +406,16 @@
               SimpleNode.PRODUCE_RAW_TREE = true;
   
               parser = new XPath(new StringReader(xpathString));
  -            tree = parser.XPath2();
  +
  +            if (isPattern)
  +            {
  +                tree = parser.MatchPattern();
  +            }
  +            else
  +            {
  +                tree = parser.XPath2();
  +            }
  +
               tree.dump("|");
   
               SimpleNode.PRODUCE_RAW_TREE = false;
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.8   +21 -19    xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/SimpleNode.java
  
  Index: SimpleNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/xpath_rwapi/src2/org/apache/xpath/impl/parser/Attic/SimpleNode.java,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- SimpleNode.java	27 Mar 2003 21:53:25 -0000	1.1.2.7
  +++ SimpleNode.java	31 Mar 2003 23:05:53 -0000	1.1.2.8
  @@ -102,6 +102,7 @@
                   break;
   
               case XPathTreeConstants.JJTSTEPEXPR:
  +			case XPathTreeConstants.JJTPATTERNSTEP:            
                   newNode = nodeFactory.createStepNode(id);
   
                   if (newNode == null)
  @@ -166,6 +167,7 @@
                   break;
   
               case XPathTreeConstants.JJTPATHEXPR:
  +			case XPathTreeConstants.JJTPATHPATTERN:
                   newNode = nodeFactory.createPathNode(id);
   
                   if (newNode == null)
  @@ -184,6 +186,8 @@
               case XPathTreeConstants.JJTOREXPR:
               case XPathTreeConstants.JJTANDEXPR:
               case XPathTreeConstants.JJTCOMPARISONEXPR:
  +			case XPathTreeConstants.JJTPATTERN: 
  +			case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR:   
                   newNode = nodeFactory.createOperatorNode(id);
   
                   if (newNode == null)
  @@ -194,6 +198,7 @@
                   break;
   
               case XPathTreeConstants.JJTFUNCTIONCALL:
  +			case XPathTreeConstants.JJTIDKEYPATTERN:
                   newNode = nodeFactory.createFunctionCallNode(id);
   
                   if (newNode == null)
  @@ -274,12 +279,13 @@
   
                   break;
   
  -            case XPathTreeConstants.JJTXPATH:
  +            case XPathTreeConstants.JJTXPATH:         
                   newNode = XPathNode.m_singleton;
   
                   break;
   
               case XPathTreeConstants.JJTXPATH2:
  +			case XPathTreeConstants.JJTMATCHPATTERN:
                   newNode = XPath2Node.m_singleton;
   
                   break;
  @@ -447,28 +453,24 @@
                   break;
   
               // Below: xpath grammar unit not implemented yet
  -            case XPathTreeConstants.JJTMATCHPATTERN:
  -            case XPathTreeConstants.JJTPATTERN:
  -            case XPathTreeConstants.JJTPATHPATTERN:
  -            case XPathTreeConstants.JJTVOID:
  -            case XPathTreeConstants.JJTPATTERNSTEP:
  -            case XPathTreeConstants.JJTIDKEYPATTERN:
  +            case XPathTreeConstants.JJTVOID: //?
               case XPathTreeConstants.JJTRETURN:
               case XPathTreeConstants.JJTSOME:
               case XPathTreeConstants.JJTEVERY:
               case XPathTreeConstants.JJTIN:
  -            case XPathTreeConstants.JJTSATISFIES:
  -            case XPathTreeConstants.JJTINTERSECTEXCEPTEXPR: //37;           
  -            case XPathTreeConstants.JJTVALIDATEEXPR: //44;
  -            case XPathTreeConstants.JJTRBRACE: //47;
  -            case XPathTreeConstants.JJTSCHEMACONTEXT: //84;
  -            case XPathTreeConstants.JJTSCHEMAGLOBALCONTEXT: //85;
  -            case XPathTreeConstants.JJTSCHEMACONTEXTSTEP: //87;
  -            case XPathTreeConstants.JJTUNTYPED: //99;
  -            case XPathTreeConstants.JJTATOMICVALUE: //100;
  -            case XPathTreeConstants.JJTELEMORATTRTYPE: //101;
  -            case XPathTreeConstants.JJTSCHEMATYPE: //102;
  -            case XPathTreeConstants.JJTOFTYPE: //103;
  +            case XPathTreeConstants.JJTSATISFIES:           
  +            case XPathTreeConstants.JJTVALIDATEEXPR: 
  +            case XPathTreeConstants.JJTRBRACE: 
  +            
  +            // types..
  +            case XPathTreeConstants.JJTSCHEMACONTEXT: 
  +            case XPathTreeConstants.JJTSCHEMAGLOBALCONTEXT: 
  +            case XPathTreeConstants.JJTSCHEMACONTEXTSTEP: 
  +            case XPathTreeConstants.JJTUNTYPED:
  +            case XPathTreeConstants.JJTATOMICVALUE: 
  +            case XPathTreeConstants.JJTELEMORATTRTYPE: 
  +            case XPathTreeConstants.JJTSCHEMATYPE: 
  +            case XPathTreeConstants.JJTOFTYPE: 
   
               default:
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org