/usr/lib/ats-anairiats-0.2.11/libats/DATS/regexp.dats is in ats-lang-anairiats 0.2.11-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(* Hongwei Xi *)
(* *)
(***********************************************************************)
(*
** ATS - Unleashing the Potential of Types!
**
** Copyright (C) 2002-2011 Hongwei Xi, Boston University
**
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the
** Free Software Foundation; either version 2.1, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* author: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *)
(* ****** ****** *)
// some basic IO operations
(* ****** ****** *)
staload UN = "prelude/SATS/unsafe.sats"
(* ****** ****** *)
staload _(*anon*) = "prelude/DATS/list_vt.dats"
(* ****** ****** *)
staload "libats/SATS/regexp.sats"
(* ****** ****** *)
#define i2sz size1_of_int1
#define sz2i int1_of_size1
(* ****** ****** *)
%{^
ats_ptr_type
atslib_regexp_compile
(ats_ptr_type pattern) {
const char *errptr ;
int erroffset ; pcre *rc ;
rc = pcre_compile (
(char*)pattern
, 0 /* option bits */
, &errptr, &erroffset
, (unsigned char*)0 /* tableptr */
) ; // end of [pcre_compile]
return rc ;
} /* end of [atslib_regexp_compile] */
%} // end of [%{^]
implement
regexp_compile_exn (pattern) = let
val re0 = regexp_compile (pattern)
val p_re0 = ptr_of (re0)
in
if (p_re0 <> null) then re0
else let
val () = prerrf (
"exit(ATS): [pcre_comiple] failed: pattern = %s\n", @(pattern)
) // end of [val]
prval () = regexp_free_null (re0)
in
exit(1)
end // end of [if]
end // end of [regexp_compile_exn]
(* ****** ****** *)
implement
regexp_match_string (re, str) = let
val str = string1_of_string (str)
val len = string_length (str); val len = sz2i (len)
in
regexp_match_substring (re, str, 0(*ofs*), len)
end // end of [regexp_match_string]
(* ****** ****** *)
%{$
ats_bool_type
atslib_regexp_match_substring (
ats_ptr_type re, ats_ptr_type str, ats_int_type ofs, ats_int_type len
) {
int rc ;
//
rc = pcre_exec (
(pcre*)re
, (pcre_extra*)0 /* [re] is not studied */
, ((char*)str)+ofs, len, 0 // strlenofs
, 0 /* option bits */
, (int*)0 /* ovector */
, 0 /* ovecsize */
) ; // end of [pcre_exec]
//
if (rc >= 0) return ats_true_bool ;
//
switch (rc) {
case PCRE_ERROR_NOMATCH: return ats_false_bool ;
default: fprintf
(stderr, "exit(ATS): [regexp_match_substring] failed\n"); exit (1);
} /* end of [switch] */
//
return ats_false_bool ; /* deadcode */
//
} /* end of [atslib_regexp_match_substring] */
%} // end of [%{$]
(* ****** ****** *)
implement
regexp_match_string_strposlst (re, str) = let
val len = string_length (str); val len = sz2i (len)
in
regexp_match_substring_strposlst (re, str, 0(*ofs*), len)
end // end of [regexp_match_string_strpostlst]
(* ****** ****** *)
local
extern
fun strposlst_make_arrptr
{n:nat} (A: &(@[int][n+n]), n: int n): List_vt @(int, int)
= "atslib_strposlst_make_arrptr"
// end of [strposlst_make_arrptr]
in // in of [local]
implement
strposlst_make_arrptr
{n} (A, n) = let
typedef int2 = (int, int)
stavar l:addr
val p = (&A): ptr l
//
viewdef V1 = array_v (int, n+n, l) and V2 = array_v (int2, n, l)
//
prval () = __assert (view@ (A)) where {
extern prfun __assert (pf: !V1 >> V2): void
} // end of [prval]
val xs = list_vt_make_array<int2> (A, size1_of_int1 (n))
prval () = __assert (view@ (A)) where {
extern prfun __assert (pf: !V2 >> V1): void
} // end of [prval]
//
in
xs
end // end of [strposlst_make_arrptr]
end // end of [local]
(* ****** ****** *)
%{$
ats_ptr_type
atslib_regexp_match_substring_strposlst (
ats_ptr_type re, ats_ptr_type str, ats_int_type ofs, ats_int_type len
) {
int rc ;
int ncapture ;
int ovecsize, *ovector ;
int err ;
//
ats_ptr_type res ;
//
err = pcre_fullinfo (
(pcre*)re, (pcre_extra*)0, PCRE_INFO_CAPTURECOUNT, &ncapture
) ; // end of [pcre_fullinfo]
//
ovecsize = 3 * (ncapture + 1) ;
ovector = ATS_MALLOC (ovecsize * sizeof(int)) ;
//
rc = pcre_exec (
(pcre*)re
, (pcre_extra*)0 /* [re] is not studied */
, ((char*)str)+ofs, len, 0 // strlenofs
, 0 /* option bits */
, ovector
, ovecsize
) ; // end of [pcre_exec]
//
if (rc >= 0) {
res = atslib_strposlst_make_arrptr (ovector, rc) ;
} else {
res = (ats_ptr_type)0 ;
} // end of [if]
//
ATS_FREE (ovector) ;
//
if (rc >= 0) return res ;
//
switch (rc) { // [rc] is negative
case PCRE_ERROR_NOMATCH: return res ;
default: fprintf (
stderr, "exit(ATS): [regexp_match_substring_strposlst] failed\n"
) ; exit (1) ;
} // end of [switch]
//
return res ; /* deadcode */
//
} /* end of [atslib_regexp_match_substring_strposlst] */
%} // end of [%{$]
(* ****** ****** *)
%{^
ATSinline()
ats_int_type
atslib_regexp_split_substring_search (
ats_ptr_type re
, ats_ptr_type str
, ats_int_type ofs
, ats_int_type len
, ats_ptr_type ofsvec
) {
int rc ;
rc = pcre_exec (
(pcre*)re
, (pcre_extra*)0 /* [re] is not study */
, ((char*)str)+ofs, len, 0 // strlenofs
, 0 /* option bits */
, (int*)ofsvec /* ovector */
, 3 /* ovecsize */
) ; // end of [pcre_exec]
return rc ;
} /* end of [atslib_regexp_split_substring_search] */
%} // end of [%{^]
(* ****** ****** *)
implement
regexp_split_string_list
(re, str) = let
//
val str = string1_of_string (str)
val len = string1_length (str)
val len = int1_of_size1 (len)
in
regexp_split_substring_list (re, str, 0, len)
end // end of [regexp_split_string_list]
implement
regexp_split_substring_list
{l0} {n} (re, str, ofs, len) = let
//
extern fun search
{i,ln:nat | i + ln <= n} {l:addr} (
pf_arr: ! @[int?][3] @ l >> @[int][3] @ l
| re: !REGEXPptr l0, str: string n, ofs: int i, len: int ln, l: ptr l
) : int = "atslib_regexp_split_substring_search"
//
viewtypedef res = List_vt (strptr1)
//
fun loop {i,ln:nat | i+ln <= n} {l:addr} (
pf_arr: !(@[int?][3] @ l)
| re: !REGEXPptr l0
, str: string n, ofs: int i, len: int ln, p: ptr l, res: &res? >> res
) : void = case+ 0 of
| _ when (len > 0) => let
val rc = search (pf_arr | re, str, ofs, len, p)
in
case+ rc of
| _ when rc >= 0 => let
val [i1:int] i1 = int1_of p->[0]
and [i2:int] i2 = int1_of p->[1]
prval () = __assert () where {
extern prfun __assert (): [0 <= i1; i1 <= i2; i2 <= ln] void
} // end of [prval]
(*
val () = if (i1 = i2) then let
val () = prerr (
"exit(ATS): [regexp_split_substring_list]: nullable separator"
) // end of [val]
val () = prerr_newline ()
in
exit (1)
end // end of [val]
*)
val sbp = string_make_substring (str, (i2sz)ofs, (i2sz)i1)
val s = strptr_of_strbuf (sbp) // no-op cast
val () = res := list_vt_cons {strptr1} {0} (s, ?)
val+ list_vt_cons (_, !p_res) = res
val () = loop (pf_arr | re, str, ofs+i2, len-i2, p, !p_res)
prval () = fold@ (res)
in
// nothing
end // end of [_ when rc >= 0]
| _ => let
val sbp = string_make_substring (str, (i2sz)ofs, (i2sz)len)
val s = strptr_of_strbuf (sbp) // no-op cast
val () = res := list_vt_cons {strptr1} {0} (s, ?)
val+ list_vt_cons (_, !p_res) = res
val () = loop (pf_arr | re, str, ofs+len, 0, p, !p_res)
prval () = fold@ (res)
in
// nothing
end // end of [_]
end // end of [_ when (i < n)]
| _ (* i = n *) => (res := list_vt_nil)
//
var !p_arr with pf_arr = @[int][3]()
var res: res? // uninitialized
val () = loop (pf_arr | re, str, ofs, len, p_arr, res)
//
in
res
end // end of [regexp_split_substring_list]
(* ****** ****** *)
val () = initialize () where {
extern fun initialize (): void = "atslib_libats_regexp_initialize"
} // end of [val]
(* ****** ****** *)
%{$
//
// HX-2010-02-20: is this really necessary?
//
ats_void_type
atslib_libats_regexp_initialize () {
pcre_malloc = (void *(*)(size_t))ats_malloc_gc ;
pcre_free = (void (*)(void*))ats_free_gc ;
pcre_stack_malloc = (void *(*)(size_t))ats_malloc_gc ;
pcre_stack_free = (void (*)(void*))ats_free_gc ;
return ;
} /* end of [atslib_libats_regexp_initialize] */
%} // end of [%{$]
(* ****** ****** *)
(* end of [regexp.dats] *)
|