我的类型类似于:
type ID is new String (1 .. 7);
-- Example: 123-456
如何使用Ada或SPARK在代码中指定该格式?
我在考虑Static_Predicate
,但是字符串必须以3个正整数开头,后跟短划线后跟另一组3个正整数的条件不能用Static_Predicate
表达式来描述
答案 0 :(得分:5)
您必须使用Dynamic_Predicate
:
type ID is new String (1 .. 7)
with Dynamic_Predicate => (for all I in ID'Range =>
(case I is
when 1 .. 3 | 5 .. 7 => ID (I) in '0' .. '9',
when 4 => ID (I) in '-'));
我自己使用了这个,但我主要使用String
的类型子类型而不是实际的新类型。