class Pegasus::Generators::Api::PegasusOptionParser(C, I)

Overview

High-level class for constructing parser generators that are configurable from the command line.

This class uses Input to read a value of type I, then uses the registered FileGenerator instances to produce output via an OutputMode. All of these listed classes are registered with Crystal's native OptionParser, which serves to provide a user with configuration options.

The #output_file_names and #input_file_names hashes store the names of target output files and input files, respectively. These are updated by the Input and FileGenerators, as well as through user-supplied command-line options.

Defined in:

generators/generators.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(input_method : Input(I), context : C = C.new) #

Create a new PegasusOptionParser with the given input method and context.


[View source]

Instance Method Detail

def context : C #

The context class (which must implement the add_option method) is included with the generator to store and retrieve parser-specific options. FileGenerator#context is used within a generator to access this value.


[View source]
def file_gens : Array(FileGenerator(C, I)) #

The list of registered file generators.


[View source]
def input : I | Nil #

The input gathered from the Input class. This starts uninitialized, but is set partway through #run.


[View source]
def option_parser : OptionParser #

The Crystal-native OptionParser used to actually print options to the console.


[View source]
def output_file_names : Hash(String, String) #

Hash that stores the configured file names of the various FileGenerator instances, associated with their internal names. The file names are kept outside their generators so that two generators that depend on one another (like a source file including a header file) can know each other's names.


[View source]
def run #

Run the command line program, and the constructed generator.


[View source]