[XML-SIG] XPathGrammar question

Martin v. Loewis martin@v.loewis.de
Fri, 21 Dec 2001 17:17:23 +0100


> Is it in CVS somewhere?

Yes, on my local disk :-) I'll attach another copy now, and perhaps
put it into PyXML later.

> > /descendant-or-self::node()/child::foo
> 
> Okay, but feeding that into the parser gets me:
> 
> createAxisSpecifier 6
> createNodeTest 4
> createStep 6 4 []
> createAxisSpecifier 4
> createNameTest None foo
> createStep 4 (None, 'foo') []
> createRelativeLocationPath (6, 4, []) (4, (None, 'foo'), [])
> createAbsoluteLocationPath ((6, 4, []), (4, (None, 'foo'), []))
> 
> I.e. whatever is the case, this still gives me an axis specifier of 6.
> It looks quite different from the other case..

It creates two axis specifiers: from left to right, it first creates
one for 6 (DESCENDANT_OR_SELF_AXIS), and then for 4 (CHILD_AXIS).  The
interesting part is how those are combined to steps and location
paths. In this case, you get two steps.

> 
> > > createAxisSpecifier 4
> > > createNameTest None foo
> > > createStep 4 (None, 'foo') []
> > > createAbbreviatedAbsoluteLocationPath (4, (None, 'foo'), [])

In this case, you get only one step (for child::foo). The other step
is "hidden" in the abbreviation; this is the one that you expect to be
DESCENDANT_OR_SELF_AXIS. There is no step in the (literal, unexpanded)
input, so the parser does not create one.

It might be appropriate for you to expand the abbreviation in the
implementation of
createAbbreviatedAbsoluteLocationPath. Alternatively, you could return
some representation that allows you faster evaluation of the
abbreviation; that is up to the factory.

> That's a tuple; I let my simple factory return all its arguments as a
> tuple all the time, and the parser passes them in again. I wanted to
> see what the parser did with these, and as I'm exploring what's
> new territory for me that seemed like a good idea. :)

Sounds reasonable; that is how I first 'implemented' the Spark-based
parser.

> Well, but foo//bar gets me this:
> 
> createAxisSpecifier 4
> createNameTest None foo
> createStep 4 (None, 'foo') []
> createAxisSpecifier 4
> createNameTest None bar
> createStep 4 (None, 'bar') []
> createAbbreviatedRelativeLocationPath (4, (None, 'foo'), []) (4, (None, 'bar'), [])

What did you expect instead?

The syntax for this is

Step '//' Step

So it creates two steps, then the abbreviated location path. Notice
that there are only two steps in this syntax, one before the
short-hand, and one after the short-hand //.

> It would seem to me that whatever happens the former should get a 
> descendant-or-self step somewhere in there, so I still don't get it.

In the abbreviation? No, it does not contain a step - it is an
abbreviation. The fact that it is an abbreviation is communicated by
calling createAbbreviatedRelativeLocationPath (for the relative case).

Regards,
Martin