Creator of PEGKit here.
PEGKit (but not ParseKit) has a feature inspired by ANTLR called "Grammar Actions". Grammar Actions are a way to do exactly what you are looking for: inserting arbitrary code in various places in your Parser's .h and .m files. They must be placed at the top of your grammar before any rules are listed.
Use PEGKit tag v0.3.6 or later (or HEAD of master).
Here are all of the Grammar Actions currently available, along with a description of where their bodies are inserted in the source code of your generated parser:
In the .h file:@h
- top of .h file@interface
- inside the@interface
portion of header
@m
- top of .m file@extension
- inside a private@interface MyParser ()
class extension in the .m file@ivars
- private ivars inside the@implementation MyParser {}
in the .m file@implementation
- inside your parser's@implementation
. A place for defining methods.@init
- inside your parser'sinit
method@dealloc
- inside your parser'sdealloc
method if ARC is not enabled@before
- setup code goes here. executed before parsing begins.@after
- tear down code goes here. executed after parsing ends.
(notice that the @before
and @after
Grammar Actions listed here are distinct from the @before
and @after
which may also be placed in each individual rule.)
For your current needs, the @m
Grammar Action is the correct choice. So add this to the top of your grammar:
@m {
#import "MyCoolNewObject.h"
}