eclipse-esmf / esmf-semantic-aspect-meta-model

Formal and textual specification of the Semantic Aspect Meta Model (SAMM)
https://eclipse-esmf.github.io/samm-specification/snapshot/index.html
Mozilla Public License 2.0
46 stars 9 forks source link

[Task] Define how to specify optional elements in a Structured Value #107

Open georgschmidtdumont opened 2 years ago

georgschmidtdumont commented 2 years ago

Is your task related to a problem? Please describe. In some cases one might want to define a Structured Value which contains optional elements. Lets take the example with the date. If, instead of a date, one would describe a date-time in the same fashion the deconstruction rule may look as follows:

(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})

And the elements list would be:

( :year "-" :month "-" :day "T" :hours ":" :minutes ":" seconds )

However, the time sections of the date-time could be optional. Defining a capture group in the deconstruction rule as optional is straight forward. But the mapping between the capture groups and the properties in the elements list is not clear. In case the deconstruction rule contains multiple optional capture groups, at runtime it might not be clear which element is omitted. The semantics about which Property in the elements list is optional is also not clearly defined. Since the mapping between the capture groups and the Properties in the element list are mapped based on the capture group number and the position of the Property in the list, it is only implicitly defined that a specific Property is to be treated as being optional.

Describe the solution you'd like The semantics of optional elements in a Structured Value can be captured by using named capture groups and explicitly defining which Properties are optional in the context of a Structured Value.

The use of named capture groups would allow the mapping of capture group and element to be done using the name of the capture group and the name of the Property, instead of the position of the Property in the element list. The name of the capture group and the name of the corresponding Property must be equal of course. Using named capture groups, the deconstruction rule above would look as follows:

(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hours>\d{2})?:(?<minutes>\d{2})?:(?<seconds>\d{2})?

To clearly state which elements are optional, the Properties can be referenced as follows:

:DateTime a bamm-c:StructuredValue ;
bamm-c:element :year
...
bamm-c:element [ bamm:property :hours ; bamm:optional true ]
...

Additional context Named capture groups have different syntax depending on the programming language being used to process the regular expression. A good overview of which flavors are supported by the different programming languages can be found here. In the context of this task, a decision must be taken on which flavor of regex will be used for named capture groups in Aspect Models.

The validation rule which checks whether the number of capture groups is equal to the number of elements remains. Testing the construction and deconstruction of the value when an example value is provided also remains. An additional validation rule would need to be implemented which ensures that the element for an optional capture group is defined as being optional. In order to realize this, it would be necessary to disallow nested capture groups.

BirgitBoss commented 2 years ago

SDS Meeting 2022-04-21 In general we approve of the concept. However, we still have some questions. Question: Seconds should only be present if theres are minutes and so on. We feel that the example would not ensure this? But would your proposal allow it?