Type mapping rules can also affect type modifiers during the type replacement. Type modifier is a small string, which modifies type usage in the typed element. They are used, for example, for specifying arrays during the modeling (e.g., property type = char and type modifier = [30] gives property:char[30]). Type modifiers are
extensively used in SQL models for specifying number field widths and varchar field lengths. For example, phone:varchar”(100)”, where varchar is a type of phone property and “(100)” is a type modifier.

Each type mapping rule can carry a triple <modifier, regexp, replacementregexp> for setting type modifiers during the type replacement. These are specified in the tags on the mapping rule <forwardTypeModifier, forwardTypeModifierRegexp, forwardTypeModifierRegexpReplace> triple for controlling modifiers during
the forward application of type map and correspondingly the <reverseTypeModifier, reverseTypeModifierRegexp, reverseTypeModifierRegexpReplace> triple for controlling modifiers during reverse application of type map.

Any of the components of the triple can be missing, i.e., not specified.

If no tags are specified, then type modifiers are not changed during the type remapping operation (whatever modifier was in the source model, it will be copied into the target model).

If just the modifier is specified for the mapping rule, then modifiers are set during the application of this type rule. This can be used for setting the fixed type modifiers. For example, mapping boolean in the UML model to number(1) in the SQL models (in this case the modifier=”(1)” is used in the type map).

If all three are specified, a modifier, regexp, and regexp replacement, modifier remapping is performed as follows: during the transformation, the existing type modifier is matched against the given regexp. If it does not match, the type modifier is overwritten with the value, specified in the modifier field of the rule. If it does match
regexp, the replacement is run on the match result and produces a type modifier to be set as a result. This allows quite complex rules to be written and executed, however this mandates good knowledge of regexp.

Let’s review the following live example: in the char -> varchar type mapping rule for the UML to SQL transformation, the following triple can be used: modifier="(255)", modifierRegexp="^[\(\[]([0-9]*)[\)\]]$", and modifierRegexpReplace="($1)". This causes the char[20] type usages (type=char, modifier=”[20]”) in the source be changed to varchar(20); char (without modifier) would be remapped to varchar(255).

If regexp replacement is not specified, it is treated as if “$0” was specified: the type modifier is copied from the source, if it does match the regexp.