18.07.2013, 17:50
Hi guys, I'm building cool tool (which I'll be releasing on github soon), and I need some help with catching all corner cases.
This code tries to check all possible argument combinations.
We are talking about valid pawn code, and not about macro substitutions (using <> and other things).
Now, except for elipsis, I think that covers a most of possible stuff. Did I miss something?
PHP код:
protected function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setRequired(array(
'name',
));
$resolver->setDefaults(array(
'tag' => null,
'reference' => false,
'arrayDimension' => 0,
'arrayEnumerator' => array(),
'default' => null,
'operator' => null,
));
$resolver->setAllowedTypes(array(
'reference' => 'boolean',
//'tag' => '', @TODO
'arrayDimension' => 'int',
'arrayEnumerator' => 'array',
'operator' => 'array',
));
$resolver->setAllowedValues(array(
'arrayDimension' => range(0, 3),
//'arrayEnumerator' => array(), @TODO
'operator' => array('const', 'sizeof', 'tagof'),
));
$resolver->setNormalizers(array(
'reference' => function (Options $options, $value) {
//If array dimensions are passed, it's a constant, or sizeof/tagof, the value is or cannot be passed by reference
return empty($options['operator']);
},
'arrayDimension' => function (Options $options, $value) {
$numberOfEnumerators = count($options['arrayEnumerator']);
return max(array($numberOfEnumerators, $value));
},
));
}
pawn Код:
Float:Value = 5.0
CUSTOM_TAG:Something[CUSTOM_SOMETHING][][]
&number
const somestring[]
tagof something
Now, except for elipsis, I think that covers a most of possible stuff. Did I miss something?