{"id":99,"date":"2014-07-03T15:41:09","date_gmt":"2014-07-03T15:41:09","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=99"},"modified":"2014-07-06T20:09:57","modified_gmt":"2014-07-06T20:09:57","slug":"the-ovm_regex_t-type","status":"publish","type":"post","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=99","title":{"rendered":"The ovm_regex_t type"},"content":{"rendered":"<p>The <code>ovm_regex_t<\/code> type is the OrchIDS type of regular expression matchers.<!--more--><\/p>\n<p>It is defined this way in <tt>src\/lang.h<\/tt>:<\/p>\n<pre>typedef struct ovm_regex_s ovm_regex_t;\r\nstruct ovm_regex_s\r\n{\r\n  gc_header_t gc;\r\n  char     *regex_str;\r\n  regex_t   regex;\r\n  int splits;\r\n};\r\n<\/pre>\n<p>The <code>regex_str<\/code> field will in general be a NUL-terminated, C-like string \u2014 the regular expression itself.\u00a0 This string must be allocated using <code>Xmalloc()<\/code>; this is <em>not<\/em> a pointer to an <code>ovm_str_t<\/code> object, for example.<\/p>\n<p>The <code>regex<\/code> field is meant to contain the compiled regular expression matcher itself, as produced by the <code>regcomp<\/code> function from the standard <code>regex<\/code> library.<\/p>\n<p>The <code>splits<\/code> field is meant to contain the number of subexpressions to match.\u00a0 These are the subexpressions refered to by parentheses in the regular expression (and that one can compare to using <code>\\\\1<\/code>, <code>\\\\2<\/code>, &#8230;).<\/p>\n<p>The type <code>ovm_regex_t<\/code> is a type of <a title=\"Garbage collection\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?p=18\">garbage-collectable<\/a> data. To allocate a new object of type <code>ovm_vstr_t<\/code>, the following low-level function is provided:<\/p>\n<pre>ovm_var_t *ovm_regex_new(gc_t *gc_ctx);<\/pre>\n<p>This creates a new <code>ovm_regex_t<\/code> object, with a <code>NULL<\/code> <code>regex_str<\/code> field, and an uninitialized <code>regex<\/code> field. Calling <code>res<\/code> the result, one always has <code>TYPE(res)==T_REGEX<\/code>.\u00a0 One can access the\u00a0<code>regex_str,<\/code> <code>regex<\/code> and <code>splits<\/code> fields using <code>REGEXSTR(res),<\/code> <code>REGEX(res)<\/code>, and\u00a0<code>REGEXNUM(res)<\/code> respectively, all to write into or to read from.<\/p>\n<p>The return type of <code>ovm_regex_new()<\/code> is the universal type <a title=\"The ovm_var_t universal type\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/?page_id=121\"><code>ovm_var_t<\/code><\/a> instead of <code>ovm_regex_t<\/code>, for practical reasons.<\/p>\n<p>An example of how to use <code>ovm_regex_new()<\/code> is given by the <code>issdl_regex_from_str()<\/code> function, in <tt>src\/lang.c<\/tt>, which implements the OrchIDS <code>regex_from_str()<\/code> primitive.<\/p>\n<p>The result of <code>ovm_regex_new()<\/code> is created white, and much be <code>gc_touch()<\/code>ed before storing it into a garbage-collectable object.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ovm_regex_t type is the OrchIDS type of regular expression matchers.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-data-types","category-virtual-machine"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=99"}],"version-history":[{"count":7,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions"}],"predecessor-version":[{"id":146,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=\/wp\/v2\/posts\/99\/revisions\/146"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}