|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > String commands > String Operations |
MiniRobotLanguage (MRL)
Working with Blocks
A guide to parsing structured and nested text.
What is a Block?
In MiniRobotLanguage, a "block" is any piece of text that starts with a specific start delimiter and ends with a specific end delimiter.
A simple example is an Text like
where "[BEG]" is the start delimiter and "[END]" is the end delimiter.
The real power of block commands comes from their ability to understand nesting. This means if you have a structure like the one below, the commands are smart enough to correctly match the outer `[START]` with the final `[END]`, ignoring the ones in between.
[START] This is the parent block [NESTED] ... [/NESTED] [END]
What are Blocks good for?
Block commands are essential for working with any kind of structured text, which is very common in automation and data processing. Use cases include:
•Parsing HTML and XML files to extract specific data.
•Extracting information from complex log files that use bracketed sections.
•Working with structured data formats like JSON.
•Manipulating text that contains nested parentheses or brackets.
How Blocks are Counted
All block commands (`GetNth`, `Count`, `ReplaceNth`, etc.) operate on top-level blocks only. They count blocks from left to right, but will only increment the count for a block that is not inside another block. This ensures predictable and reliable parsing.
How Top-Level Blocks are Counted
(1) (2) (3)
│ │ │
Top-Level Scan: └─────┴─────┘ └─────┴───────────────────┘ └─────┴─────┘
┌───────────┐ ┌───────────────────────────┐ ┌───────────┐
Source String: [A]...[/A] [A]...[A]...[/A]...[/A] [A]...[/A]
└───────────┘ └───────────────────────────┘ └───────────┘
└─────┴─────┘
│
Nested Scan: (Ignored in top-level count)
Result: The STR.BlockCount command correctly identifies 3 top-level blocks.
In this example, STR.BlockCount would return 2, because only the two outer blocks are at the top level.
The Block Command Suite
Below is a list of all available block commands. Click any command to see its detailed help page with syntax and examples.
•STR.BlockGetFirst - Gets the first complete top-level block.
•STR.BlockGetFirstEx - Gets the first block with extended info (content, position, status).
•STR.BlockGetNth - Gets the Nth complete top-level block.
•STR.BlockGetNthEx - Gets the Nth block with extended info.
•STR.BlockGetAll - Gets all top-level blocks into an ARR array.
•STR.BlockGetAllContent - Gets all block contents into an ARR array.
•STR.BlockGetNestedNth - Gets a specific nested block within a parent.
•STR.BlockCount - Counts the number of top-level blocks.
•STR.BlockValidate - Checks if all block delimiters are balanced.
•STR.BlockRepair - Repairs strings with unclosed/mismatched blocks.
•STR.BlockReplaceContent - Replaces the content inside the Nth block.
•STR.BlockReplaceBlock - Replaces the entire Nth block.
•STR.BlockRemoveContent - Removes the content from inside the Nth block.
•STR.BlockRemoveBlock - Removes the entire Nth block.