| RESTAR_TOK { $kind = CVC4::kind::REGEXP_STAR; }
| REPLUS_TOK { $kind = CVC4::kind::REGEXP_PLUS; }
| REOPT_TOK { $kind = CVC4::kind::REGEXP_OPT; }
+ | RERANGE_TOK { $kind = CVC4::kind::REGEXP_RANGE; }
// NOTE: Theory operators go here
;
RESTAR_TOK : 're.*';
REPLUS_TOK : 're.+';
REOPT_TOK : 're.opt';
+RERANGE_TOK : 're.range';
/**
* A sequence of printable ASCII characters (except backslash) that starts
operator REGEXP_STAR 1 "regexp *"
operator REGEXP_PLUS 1 "regexp +"
operator REGEXP_OPT 1 "regexp ?"
+operator REGEXP_RANGE 2 "regexp range"
#constant REGEXP_EMPTY \
# ::CVC4::RegExp \
typerule REGEXP_STAR ::CVC4::theory::strings::RegExpStarTypeRule
typerule REGEXP_PLUS ::CVC4::theory::strings::RegExpPlusTypeRule
typerule REGEXP_OPT ::CVC4::theory::strings::RegExpOptTypeRule
+typerule REGEXP_RANGE ::CVC4::theory::strings::RegExpRangeTypeRule
typerule STRING_TO_REGEXP ::CVC4::theory::strings::StringToRegExpTypeRule
retNode = NodeManager::currentNM()->mkNode( kind::REGEXP_OR,
NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst( ::CVC4::String("") ) ),
node[0]);
+ } else if(node.getKind() == kind::REGEXP_RANGE) {
+ std::vector< Node > vec_nodes;
+ char c = node[0].getConst<String>().getFirstChar();
+ char end = node[1].getConst<String>().getFirstChar();
+ for(; c<=end; ++c) {
+ Node n = NodeManager::currentNM()->mkNode( kind::STRING_TO_REGEXP, NodeManager::currentNM()->mkConst( ::CVC4::String( c ) ) );
+ vec_nodes.push_back( n );
+ }
+ if(vec_nodes.size() == 1) {
+ retNode = vec_nodes[0];
+ } else {
+ retNode = NodeManager::currentNM()->mkNode( kind::REGEXP_OR, vec_nodes );
+ }
}
Trace("strings-prerewrite") << "Strings::preRewrite returning " << retNode << std::endl;
}
};
+class RegExpRangeTypeRule {
+public:
+ inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check)
+ throw (TypeCheckingExceptionPrivate, AssertionException) {
+ TNode::iterator it = n.begin();
+ TNode::iterator it_end = n.end();
+ char ch[2];
+
+ for(int i=0; i<2; ++i) {
+ TypeNode t = (*it).getType(check);
+ if (!t.isString()) {
+ throw TypeCheckingExceptionPrivate(n, "expecting a string term in regexp range");
+ }
+ if( (*it).getKind() != kind::CONST_STRING ) {
+ throw TypeCheckingExceptionPrivate(n, "expecting a constant string term in regexp range");
+ }
+ if( (*it).getConst<String>().size() != 1 ) {
+ throw TypeCheckingExceptionPrivate(n, "expecting a single constant string term in regexp range");
+ }
+ ch[i] = (*it).getConst<String>().getFirstChar();
+ ++it;
+ }
+ if(ch[0] > ch[1]) {
+ throw TypeCheckingExceptionPrivate(n, "expecting the first constant is less or equal to the second one in regexp range");
+ }
+
+ if( it != it_end ) {
+ throw TypeCheckingExceptionPrivate(n, "too many terms in regexp range");
+ }
+
+ return nodeManager->regexpType();
+ }
+};
+
class StringToRegExpTypeRule {
public:
inline static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check)
}
}
+ String(const char c) {
+ d_str.push_back( convertCharToUnsignedInt(c) );
+ }
+
String(const std::vector<unsigned int> &s) : d_str(s) { }
~String() {}
return d_str.size();
}
+ char getFirstChar() const {
+ return convertUnsignedIntToChar( d_str[0] );
+ }
+
String substr(unsigned i) const {
std::vector<unsigned int> ret_vec;
std::vector<unsigned int>::const_iterator itr = d_str.begin() + i;
str005.smt2 \
str006.smt2 \
fmf001.smt2 \
+ fmf002.smt2 \
model001.smt2 \
substr001.smt2 \
regexp001.smt2 \
--- /dev/null
+(set-logic QF_S)\r
+(set-option :fmf-strings true)\r
+(set-info :status sat)\r
+\r
+(declare-fun x () String)\r
+(declare-fun y () String)\r
+(declare-fun z () String)\r
+\r
+(assert (str.in.re x\r
+ (re.+ (re.range "a" "c"))\r
+ ))\r
+\r
+(assert (= x (str.++ y "c" z "b")))\r
+(assert (> (str.len z) 1))\r
+\r
+(check-sat)\r