When outputting a
name from the model, we may thus need to apply a ?¬?lter to it that replaces
nonalphanumerics with underscores.
A simpli?¬?ed process for building a generator is thus:
(1) Paste the desired output code as the entire content of the generator.
(2) Reduce each repeated section in the output code into one occurrence, with a
generator loop that visits each model structure for which the section should
occur.
(3) For sections that have one or more alternative forms, surround them with
generator code that chooses the correct form based on a condition in the
model.
(4) Replace those parts of the output that match property values in the model with
generator code that outputs those property values, ?¬?ltered as necessary.
???HERE??™S ONE I MADE EARLIER??? 269
In practice, steps 2??“4 are often best performed in parallel on each chunk of output
in turn.
This section has described the basic process of building a generator, regardless of
the kind of model, output language, and language for writing generators. To give more
detailed advice on building generators, we ?¬?rst need to know what kind of generator
language we have.
11.2 TYPES OF GENERATOR FACILITIES
Czarnecki and Helsen (2003) identi?¬?ed two main approaches for generating code or
other text from models: visitor-based and template-based.
Pages:
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496