Once we are satisified with the functionality of a prototype (see the previous chapter) and we decide to continue further, it will become more and more inconvenient to keep code in a form of a playground script.
It is a good practice to define a parser as a class, it allows us to:
manage cyclic dependencies,
simplify testing and
easily extend with new functionality.
1. Hands On
We create a parser by subclassing PP2CompositeNode:
We define a javascipt rule as follows:
We do this by subclassing PP2CompositeParserTest and adding the test method;
In this chapter we have turned the script form the previous chapter into the class, following the practices of PetitParser.
We have also added some tests to verify the rules are working as expected.
This step allows us to add a new functionality as we will do in the next chapter.