Chapter 13. Context Variable

Use a variable to hold context required during a parse.

image

Imagine you are parsing a list of items, capturing data about each one. Each bit of information about an item can be captured independently, but you also need to know which particular item you are capturing information for.

A Context Variable does this by keeping the current item in a variable and reassigning it as you move to a new one.

13.1 How It Works

You have a Context Variable whenever you have a variable named something like currentItem which you update periodically during the parse as you move from one item to another in the input script.

A Context ...

Get Domain Specific Languages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.