Search code examples
initializationinstance-variablespharopetitparser

Custom instance variables and initializing with PetitParser


As far as I know PetitParser initializes each instance variable with a production method of the same name. What should one do, to add a custom instance variable and initialize it in the initialize method for example?


Solution

  • You can override the class-side method #ignoredNames in subclasses to add your own instance-variables that PetitParser does not touch:

    PPCompositeParser class>>#ignoredNames
        "Answer a collection of instance-variables that should 
         not be automatically initialized with productions, but
         that are used internal to the composite parser."
    
         ^ PPCompositeParser allInstVarNames