O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

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

10.6. Alternation Matching

An alternation is a collection of parsers, any of which may match against an assembly. As with the Sequence class, the primary service of the Alternation class is matching, as Figure 10.5 shows.

Figure 10.5. The Alternation class. Alternation implements match() so that matching succeeds against any of the parsers in the collection of parsers it inherits from CollectionParser.

An Alternation object matches each of its subparsers against the collection of assemblies that match() receives. The Alternation object accumulates the results of each match into an output final state. Here it is in pseudocode:

 out = new state; ...

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