Runtime Entities
Register
A register is a special variable that is implicitly passed to a command and modified by this command. In the example below, you can see how the contents of the register gets changed depending on the iteration step.
For example, we have the following HTML code on the page:
<ul>
<li>Some text</li>
<li>Another text</li>
<li>A bit more text</li>
</ul>
If we search for page elements using the path ul > li, the Find command will find 3 blocks and will iterate over them from the first:
- find:
path: ul > li
do:
- parse
# NOW WE ARE IN THE FIRST LI ELEMENT
- parse
# THERE WILL BE "Some text" VALUE IN THE REGISTER
# NOW WE ARE IN THE SECOND LI ELEMENT
- parse
# THERE WILL BE "Another text" VALUE IN THE REGISTER
# NOW WE ARE FINALLY IN THE THIRD LI ELEMENT
- parse
# THERE WILL BE "A bit more text" VALUE IN THE REGISTER
Now let's try to create a small digger and we'll see what happens in the debugging log when we run it.
---
config:
agent: Firefox
debug: 2
do:
- walk:
to: https://www.diggernaut.com/sandbox/meta-lang-register-en.html
do:
- find:
path: ul > li
do:
- parse
Let's change digger mode to Debug and then start the digger. Wait for completions and lets look into the log.
The register values when digger is resided in specific block are highlighted in green.
Statements execution order is indicated by an orange arrow.
Pay attention to five main points about the register:
- This entity stores the data in the block context
- Almost all commands of the block context takes the current value of the register as the input argument for their operations
- Almost all commands of the block context returns the result of their work to the register
- The register is context-sensitive, so when digger gets to new block, the register is initialized with an empty value
- During iterations over blocks, at the moment of entering each block, the register is initialized with an empty value