evaluation_order - Twinside/Webrexp GitHub Wiki
Right now, two evaluation orders exists, the depth first evaluation order, and the breadth first evaluation order. Understanding them is important if you want to use the webrexp to output some well ordered text.
For the explanation, we will use the following document as "file.xml" :
<?xml version="1.0" encoding="utf-8" ?>
<Items>
<Item>
<Name>Foo</Name>
<Price>15</Price>
<Description>A foo</Description>
</Item>
<Item>
<Name>Bar</Name>
<Price>7</Price>
<Description>A place</Description>
</Item>
<Item>
<Name>Forloi</Name>
<Price>0</Price>
<Description>some descr</Description>
</Item>
</Items>
And we will apply the following webrexp :
"file.xml" >> item ( name ["Name: "; . ; "\n"]
; description ["Description: "; .; "\n"] )
First, we're gonna examine the common part of evaluation.
- We begin the execution with an empty data.
- Then a string is encountered in the expression, it then become the new data.
- The dereference operator load the element pointed by the data in the pipeline.
- Last, we search the tag item in the document, and we find three of them.
We now are at a beginning of a branch in depth first evaluation with 3 elements to evaluate.
- The first element is taken into the beginning of the branch, searching for a name, and finding one.
- Then the element is displayed on screen.
- The evaluator backtrack to the beginning of the branch, re-take the first element and put it in the second part of it.
- A description is searched with one result.
- The description content is displayed on screen.
Finally the same scenario happen with the second and third item. The DFS evaluator when multiple item are found, will pick one element and evaluate it as much as it could. Then it will backtrack to evaluate the left elements.
At the end of the evaluation we're left with the following information on screen :
Name: Foo
Description: A Foo
Name: Bar
Description: A place
Name: Forloi
Description: some descr
We now are at a beginning of a branch in breadth first evaluation with 3 elements to evaluate.
- The evaluator take the three elements and search the element name in each one of them, leaving 3 name elements in the pipeline.
- The action dump all the name content, each element in the pipeline will be dumped in turn.
- As we're in a branch, the evaluator go back to the beginning, take the 3 element and put them in the second branch. Descriptions are searched and 3 are found.
- Every description are outputted at the same time.
At the end of the evaluation we're left with the following information on screen :
Name: Foo
Name: Bar
Name: Forloi
Description: A Foo
Description: A place
Description: some descr