Skip to content

Parser Requirements and Post Processing Information

Entity parsing

The entity parser is responsible for creating a map of entities, along with their slots, annotations, values and operations. In addition, various post-processing steps are executed, mainly to make the language easier and more comfortable to use. Finally, source info is collected regarding the entities, currently required by the LSP.

Entities, slots, annotations and operations

The parser handles the following cases:

  • Create the map of entities
  • Create a map of operations
  • Create a list of contracts
  • Create and maintain package info: imported packages, parent package, contained packages and contained entities, for every package
  • If a slot does not have a given meta, the meta should be the entity "Bootstrap.Slot"
  • If a slot has a given meta, and the new keyword was not used, then the meta slot must be omitted in the entity (omit annotation must be generated). If the new keyword was used, it does not have to be omitted
  • Operations are wrapped in implicitly generated container slots. This should be changed: operations should not be wrapped in slots, instead, they should be collected in the slot refined from Base.Operations
  • Return types of operations must be stored, to be used by node parsing later

Inline entity values

It is possible to define entities inline and assign them to the value of slots: https://github.com/bmeaut/DMLA3.0/issues/69

  • The syntax is the following: slot SSP : ProductSpecificationType.SSP = {Currency = EUR} : CurrencyValue;
  • An implicit entity is generated with the given meta, and it is stored in the entity map. TODO: should it be stored?
  • Appropriate slots are generated for this entity, filled in with the given values
  • The ID of this generated entity is added to the slot

Entity resolution

All references in entities (values, meta, annotations) that are not fully qualified must be resolved automatically, based on the current package and the imported packages. If no match or multiple matches are found, an error must be given.

Post processing

The following steps must be executed after all the entities have already been resolved. It would be desirable to handle as many of these steps during parsing as possible, for post-processing tends to result in a rigid, hard-to-use parser architecture.

  • It is checked whether the instantiation-chain of entities contains a cycle
  • The operation table is built, which contains all the explicit and implicit callable operations for every entity. Overriding operations are also checked and reinforced.
  • The meta of annotations are found and connected automatically. If there exists a type of annotation up on the meta-chain, that also exists in the entity, then the meta of the annotation in the entity must be set to the closest annotation of the same type on the meta-chain.
  • Entity ID-s in the values of all entities are replaced with a reference to the entities themselves.
  • Implicit slots of annotations are handled: https://github.com/bmeaut/DMLA3.0/issues/67 . If an annotation is defined with the syntax "@MyAnnotation = SomeValue", then the annotation type @MyAnnotation must contain exactly one slot. This slot is cloned and the value of this slot must be set to the given value.
  • If the meta of a slot is not given explicitly, then it is found automatically, bound by the name of the slot.

SourceInfo map building

  • In addition to the low level entity map (ID, meta, attributes, values), there exists a high-level SourceInfo map
  • The SourceInfo map is built during entity parsing, each SourceInfo has an ANTLR ParserRuleContext associated with it
  • SourceInfo is needed by the Language Server (for editor features) and to create more accurate exceptions (due to line / column in the ParserRuleContext)
  • Every SourceInfo has the following main attributes:
    • name - the local name (ID) of the reference (variable, entity, operation, slot, parameter, etc.)
    • context - the ParserRuleContext from ANTLR, used for text position (line / column) mostly
    • name context - the context to which references will be given in the LSP-based editor, typically a name
    • document URI - the URI of the document the element is from
    • package name - the package of the element
  • The element represented by a SourceInfo can be the following:
    • entity - also has operations, slots, and meta entity
    • slot - also has container entity and meta slot
    • operation - also has parameters, variables (defined in the operation), and a container entity
    • operation parameters and variables - paired with a TypedSymbol (name, type, isNullable)
    • unknown - default SourceInfo for exception handling
  • These high-level relations (e.g. entity operations) are not covered by the low-level map, this is why the SourceInfo map is needed (in addition to storing ParserRuleContexts)

Node parsing TODO