alpag.net manual
Integration / Code generation
< Error codes | Examples >

Code generation

Code generated by Alpag can customized in a number of ways. User can modify hierarchy of generated classes, produced files, and placement of particular code elements.

This chapter provides an overview of most important options.

Common options

Some code generation options are common for lexer and parser.

Output files

Output.Dir

This option specifies base directory for generated output. It is equivalent to --odir command line option.

Output.FileNamePrefix

Sets prefix which will be prepended to all generated code files.

Comments

Code.UserComments

When set to On, user comments from input file are copied to generated code files.

Only comments starting with three slashes (///…) placed on separate lines immediately before commented element (like rule or production) are handled this way.

Code.UserCommentsDecoration

Comment formatting. Behavior is language dependent

Code.AppComments

Enables comments added by Alpag generated from grammar definitions. Possible settings are: Off, Basic, Detailed.

Code.HeaderComment

Text of comment to be placed in all generated files.

To aid debugging additional comments can be generated using Lexer.Debug.Comments and Parser.Debug.Comments options. These require AppComments to be enabled.

Class and file options

Code generated by Alpag is object-oriented. It can be placed in a single monolithic class or multiple smaller classes. Generated classes can be placed in individual files or, sometimes, combined in a single file.

Exact configuration options available depend on target language.

Option groups

Options controlling class and file generation are placed in groups related to individual fragments of generated code. These option groups are:

Code.Base

Settings for base class common for lexer and parser

Lexer.Code.BaseDefs

Settings for base lexer definitions. These can be placed in separate file and shared by multiple lexers.

Lexer.Code.BaseClass

Settings for optional lexer base class.

Lexer.Code.Lexer

Settings for lexer class

Parser.Code.Exports

Settings for placement of parser exports, i.e. terminal symbol definitions which can be referenced from lexer

Parser.Code.BaseDefs

Settings for base parser definitions which can be placed in separate file and shared by multiple parsers.

Parser.Code.Parser

Settings for parser class

LexerParser.Code

Settings for combined lexer-parser class if one is used

Options

Options available for individual files and groups are:

Emit

When set to false, given file is not generated. Disabling Emit does not move code to other file. Also other files and classes referencing this code are not adjusted in any way. This code is simply not produced.

OwnFile

When set to true, code is saved in own dedicated file. Otherwise it is merged with nearest logically matching file. This option is available only for some classes.

WithBase

Controls adding code together with base or derived class. Available for definitions which can be placed either way. Interpreted only if OwnFile is disabled.

FileName

Name of generated file (without extension)

FileSuffix

File name suffix (not extension) which is appended to lexer or parser base name to generate output file. This option is ignored if FileName is set.

Namespace

Default namespace for the file. If not set, it is inherited from base options.

Using

Adds a reference to external namespace (import declaration). Multiple occurrences of this option are allowed for a single file. Using this option prevents multiple import declarations for the same namespace.

OwnClass

When set, a separate class is created for given functionality or code. Otherwise code is placed inside another class. This option is available only for optional classes.

ClassName

Name of generated class

ClassAccess

Access modifiers of generated class (depends on language)

Modifs

Declaration modifiers of generated class (depends on language)

BaseClassName

Name of base class. Applies only to classes that do not have implicit base class resulting from class hierarchy

< Error codes | Examples >
Alpag Manual