Best way to handle generation of optional values

Hi,

I've a optional field.

Counter concept
concept Counter ...            

  children: 
  start        : IntegerProperty[0..1]       
  ...
  numberFormat : StringProperty[0..1]


StringProperty is a abstract concept that is extended by StringLiteral and StringExpression.

In generator I want the following:
  • if numberFormat is set, then generate the value
  • if numberFormat is not set, use "" (empty string)


Currently I use $COPY_SRC$ [ "" ], and "mapped node" is customized as
{ 
  if (node.maximum.isNull) { return <"">; } 
  node.maximum; 
}


Is it a proper way to handle missing values?

Are there any short-cuts for if (node.maximum.isNull) { return <"">; }   ?

I know of pre-processing scripts. However wonder what are the possibilities.
0
4 comments
You may use the $IF$ node macro, I guess.
0
I just thought there might be some secret "use this if empty" COPY_SRC (or whatever) setting.

I might try implementing $COPY_SRC_DEF$ [ node ] that will basically be rewritten to $IF node.isNotNull$ then { $COPY_SRC#[node] } else { node }

Well, it does look natural to use "wrapped node as is if "mapped node" turned out to be empty, doesn't it?
0
You may use the $IF$ node macro, I guess


That's quite a few of $IF$/else <T T> macros. I wish MPS could use "wrapped" node in case context is empty.
0

Please sign in to leave a comment.