raesl.compile.typechecking.ast_builder#

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#

Classes#

AstBuilder

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.

Parameters:

diag_store – Storage for diagnostics while building the AST.

doc_distributor#

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

section_notify_list#

Builders to notify of a new section.

type_builder#

Builder for constructing types.

verb_builder#

Builder for constructing verb/prepositions.

reldef_builder#

Builder for constructing relations.

compdef_builder#

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.

register_new_section(other_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.

Parameters:
  • 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.

Parameters:

doc_comments – Raw documentation comments rescued from the scanner.