O'Reilly logo

Domain Specific Languages by Martin Fowler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required