描述Ada中的String类型

时间:2017-11-05 15:04:28

标签: ada ada2012 spark-2014

我的类型类似于:

type ID is new String (1 .. 7);
-- Example: 123-456

如何使用Ada或SPARK在代码中指定该格式?

我在考虑Static_Predicate,但是字符串必须以3个正整数开头,后跟短划线后跟另一组3个正整数的条件不能用Static_Predicate表达式来描述

1 个答案:

答案 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的类型子类型而不是实际的新类型。