Standalone user-defined keyword doesn't work as expected

According to the SysML2 spec (7.27.4), a user-defined keyword may also be used without using any language-defined keyword, like using

#instact def ProcessingStart;

instead of

#instact action def ProcessingStart;

However, after declaring

action def InstantaneousAction { redefines start = done; }
action instantaneousActions[0..*]: InstantaneousAction;
metadata def <instact> InstantaneousActionType :> SemanticMetadata {
:>> baseType = instantaneousActions meta SysML::Usage;
}

I cannot use the keyword “#instact” without “action”. For instance, while

#instact action def ProcessingStart {
in ws: WorkStation;
assign ws.inputBufferLength := ws.inputBufferLength + 1;
}

is okay, the following creates the error “Unexpected reserved keyword ‘assign’”:

#instact def ProcessingStart {
in ws: WorkStation;
assign ws.inputBufferLength := ws.inputBufferLength + 1;
}

despite the fact that also in the second case, ProcessingStart is an action definition.

Despite the specification using the term “user-defined keyword”, it is not in fact a keyword, it has no effect on the element type. In this case ProcessingStart is just a Definition, for it to be an ActionDefinition you need to use action def regardless of #instact. SemanticMetadata only makes the annotated element specialize the value of its baseType.

However, you can also make it emit diagnostics when metadata is applied to an incompatible element type through annotatedElement types, e.g.

metadata def  InstantaneousActionType :> SemanticMetadata {
   :>> annotatedElement : SysML::ActionUsage;
   :>> baseType = instantaneousActions meta SysML::Usage;
}

This will emit a diagnostic on #instact def ProcessingStart; because ProcessingStart is not an ActionDefinition.

User-defined keywords must resolve to a metadata usage (feature) identifier. In your case, there is no instact metadata in the scope. Fix is simple:

action def InstantaneousAction { redefines start = done; }
action instantaneousActions[0..*]: InstantaneousAction;
metadata def <instact> InstantaneousActionType :> SemanticMetadata {
   :>> baseType = instantaneousActions meta SysML::Usage;
}

Because the annotated element ProcessingStart is supposed to specialize the annotation metadata definition’s baseType instantaneousActions it should also specialize the action definition InstantaneousAction. Therefore, declaring #instact def ProcessingStart should make ProcessingStart an action definition.

Notice that in my post, I mistakenly deleted <instact> from the metadata definition.

The SysML2 spec presents the following example:

occurrence def Situation;
occurrence situations : Situation[0..*] nonunique;
metadata def <situation> SituationMetadata :> SemanticMetadata {
   :>> baseType = situations meta SysML::Usage;
}
#situation def Failure;

Failure is a plain Definition according to ExtendedDefinition parse rule:

ExtendedDefinition : Definition =
    BasicDefinitionPrefix? DefinitionExtensionKeyword+
    'def' Definition
Parse tree
Namespace [0, 0] - [6, 0]
 children: OwningMembership [0, 0] - [0, 25]
   target: OccurrenceDefinition [0, 0] - [0, 25]
     declared_name: NAME [0, 15] - [0, 24]
 children: OwningMembership [1, 0] - [1, 50]
   target: OccurrenceUsage [1, 0] - [1, 50]
     declared_name: NAME [1, 11] - [1, 21]
     heritage: FeatureTyping [1, 24] - [1, 33]
       target: TypeReference [1, 24] - [1, 33]
         segment: NAME [1, 24] - [1, 33]
     multiplicity: OwningMembership [1, 33] - [1, 39]
       target: MultiplicityRange [1, 33] - [1, 39]
         bounds_expression: OwningMembership [1, 34] - [1, 38]
           target: OperatorExpression [1, 34] - [1, 38]
             children: ParameterMembership [1, 34] - [1, 35]
               target: Feature [1, 34] - [1, 35]
                 feature_value: FeatureValue [1, 34] - [1, 35]
                   target: LiteralInteger [1, 34] - [1, 35]
                     value: DECIMAL_VALUE [1, 34] - [1, 35]
             children: ParameterMembership [1, 37] - [1, 38]
               target: Feature [1, 37] - [1, 38]
                 feature_value: FeatureValue [1, 37] - [1, 38]
                   target: LiteralInfinity [1, 37] - [1, 38]
 children: OwningMembership [2, 0] - [4, 1]
   target: MetadataDefinition [2, 0] - [4, 1]
     declared_short_name: NAME [2, 14] - [2, 23]
     declared_name: NAME [2, 25] - [2, 42]
     heritage: Subclassification [2, 46] - [2, 62]
       target: ClassifierReference [2, 46] - [2, 62]
         segment: NAME [2, 46] - [2, 62]
     children: FeatureMembership [3, 3] - [3, 47]
       target: ReferenceUsage [3, 3] - [3, 47]
         heritage: Redefinition [3, 7] - [3, 15]
           target: FeatureReference [3, 7] - [3, 15]
             segment: NAME [3, 7] - [3, 15]
         feature_value: FeatureValue [3, 16] - [3, 46]
           target: OperatorExpression [3, 18] - [3, 46]
             children: ParameterMembership [3, 18] - [3, 28]
               target: Feature [3, 18] - [3, 28]
                 feature_value: FeatureValue [3, 18] - [3, 28]
                   target: MetadataAccessExpression [3, 18] - [3, 28]
                     referenced_element: Membership [3, 18] - [3, 28]
                       target: ElementReference [3, 18] - [3, 28]
                         segment: NAME [3, 18] - [3, 28]
             children: ReturnParameterMembership [3, 34] - [3, 46]
               target: Feature [3, 34] - [3, 46]
                 heritage: FeatureTyping [3, 34] - [3, 46]
                   target: TypeReference [3, 34] - [3, 46]
                     segment: NAME [3, 34] - [3, 39]
                     segment: NAME [3, 41] - [3, 46]
 children: OwningMembership [5, 0] - [5, 23]
   target: Definition [5, 0] - [5, 23]
     prefixes: OwningMembership [5, 0] - [5, 10]
       target: MetadataUsage [5, 0] - [5, 10]
         heritage: FeatureTyping [5, 1] - [5, 10]
           target: MetaclassReference [5, 1] - [5, 10]
             segment: NAME [5, 1] - [5, 10]
     declared_name: NAME [5, 15] - [5, 22]  "Failure"

Element types are fixed at parse time (here, Definition) and cannot be modified by resolving semantic metadata in a later pass.

Thanks Daumantas.

I’ve posted this as an issue to the SysML v2 Release Google Group forum.