Classes to collect and store information from the parsing process, perform checking on the information for being correct, and construct an AST as result along with a log of found diagnostics.

The AstBuilder operates at top section level (types, verbs, relation definitions, and component definitions). It leaves all the details of each section to dedicated child builders (thus creating a highly modular checker), and acts as call dispatcher and global controller in the type-checking and ast building process once parsing has finished.

Notable parts in the class are - Child builders for each top section part. - Diagnostics store shared with all the child builders. - Storage of doc-comments in the input for attaching them to the correct parts of the

produced specification after parsing.

  • Call dispatcher for the child builders that a new top or sub-section has been found, allowing them to clean up processing if needed.

  • Entry points for the parser to push found information to the child builders.

  • The ‘finish_parse’ entry point to perform all type checking, and produce the AST and found diagnostics.

Module Contents#



Builder to collect information from the parse process, perform type

class raesl.compile.typechecking.ast_builder.AstBuilder(diag_store: raesl.compile.diagnostics.DiagnosticStore)#

Builder to collect information from the parse process, perform type checking, and produce an AST and reported diagnostics.


diag_store – Storage for diagnostics while building the AST.


Object that distributes doc comments to interested elements of the specification.


Builders to notify of a new section.


Builder for constructing types.


Builder for constructing verb/prepositions.


Builder for constructing relations.


Builder for constructing components.

add_typedef(type_name: raesl.compile.scanner.Token, parent_name: raesl.compile.scanner.Token | None, enum_spec: List[raesl.compile.ast.exprs.Value] | None, unit_spec: List[raesl.compile.scanner.Token] | None, ival_spec: List[Tuple[raesl.compile.ast.exprs.Value | None, raesl.compile.ast.exprs.Value | None]] | None, cons_spec: raesl.compile.ast.exprs.Value | None)#

Forward call to type builder.

new_bundle_type(bundle_name: raesl.compile.scanner.Token)#

Forward call to type builder.

add_bundle_field(field_name: raesl.compile.scanner.Token, type_name: raesl.compile.scanner.Token | None)#

Forward call to type builder.

add_verbdef(verb_tok: raesl.compile.scanner.Token, prepos_tok: raesl.compile.scanner.Token)#

Forward call to verb definition builder.

add_reldef(name: raesl.compile.scanner.Token)#

Forward call to relation definition builder.

reldef_param_header(header_tok: raesl.compile.scanner.Token, direction: str)#

Forward call to relation definition builder.

reldef_add_param(name: raesl.compile.scanner.Token, type_name: raesl.compile.scanner.Token, multi: bool)#

Forward call to relation definition builder.


Entry point for a child builder to declare interest in receiving notifications about new sections in the file.

notify_new_section(tok: raesl.compile.scanner.Token | None, new_top_section: bool)#

Parser has started a new section, finish all ‘in-progress’ definitions.

  • tok – Token indicating the position of the new section. None is used for EOF.

  • new_top_section – If set, a new type, verbs, or component definition has been found, else a new section within a component has been detected.

finish_parse(doc_comments: List[raesl.compile.scanner.Token]) raesl.compile.ast.specification.Specification | None#

Finish processing the collected information, that is, perform type checking.


doc_comments – Raw documentation comments rescued from the scanner.