mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Replace .hats GPL sample with MIT one
This commit is contained in:
155
samples/ATS/csv_parse.hats
Normal file
155
samples/ATS/csv_parse.hats
Normal file
@@ -0,0 +1,155 @@
|
||||
// Source: https://github.com/githwxi/ATS-Postiats-contrib/blob/0f26aa0df8542d2ae21df9be1e13208f66f571d6/contrib/libats-/hwxi/teaching/mygrading/HATS/csv_parse.hats
|
||||
|
||||
(* ****** ****** *)
|
||||
//
|
||||
// Author: Hongwei Xi
|
||||
// Authoremail: gmhwxiATgmailDOTcom
|
||||
// Start time: the first of July, 2016
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
#ifdef
|
||||
MYGRADING_HATS
|
||||
#then
|
||||
#else
|
||||
//
|
||||
extern
|
||||
fun
|
||||
csv_parse_line
|
||||
(
|
||||
line: string
|
||||
) : List0_vt(Strptr1)
|
||||
//
|
||||
#endif // #ifdef
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
local
|
||||
//
|
||||
staload
|
||||
UN = "prelude/SATS/unsafe.sats"
|
||||
//
|
||||
extern
|
||||
fun{}
|
||||
getpos(): int
|
||||
//
|
||||
extern
|
||||
fun{}
|
||||
is_end(): bool
|
||||
//
|
||||
extern
|
||||
fun{}
|
||||
char_at(): int
|
||||
//
|
||||
extern
|
||||
fun{}
|
||||
Strptr1_at(i0: int): Strptr1
|
||||
//
|
||||
extern
|
||||
fun{}
|
||||
rmove(): void
|
||||
extern
|
||||
fun{}
|
||||
rmove_while(test: char -<cloref1> bool): void
|
||||
//
|
||||
in (* in-of-local *)
|
||||
//
|
||||
implement
|
||||
{}(*tmp*)
|
||||
rmove_while
|
||||
(test) = let
|
||||
//
|
||||
val c0 = char_at()
|
||||
//
|
||||
in
|
||||
//
|
||||
if c0 >= 0 then
|
||||
if test(int2char0(c0)) then (rmove(); rmove_while(test)) else ()
|
||||
// end of [if]
|
||||
//
|
||||
end // end of [rmove_while]
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
implement
|
||||
csv_parse_line
|
||||
(line) = let
|
||||
//
|
||||
val line = g1ofg0(line)
|
||||
//
|
||||
var i: int = 0
|
||||
val p_i = addr@i
|
||||
//
|
||||
val n0 = sz2i(length(line))
|
||||
//
|
||||
macdef get_i() = $UN.ptr0_get<int>(p_i)
|
||||
macdef inc_i() = $UN.ptr0_addby<int>(p_i, 1)
|
||||
macdef set_i(i0) = $UN.ptr0_set<int>(p_i, ,(i0))
|
||||
//
|
||||
implement
|
||||
getpos<>() = get_i()
|
||||
//
|
||||
implement
|
||||
is_end<>() = get_i() >= n0
|
||||
//
|
||||
implement
|
||||
char_at<>() = let
|
||||
val i = get_i()
|
||||
val i = ckastloc_gintGte(i, 0)
|
||||
//
|
||||
in
|
||||
if i < n0 then char2u2int0(line[i]) else ~1
|
||||
end // end of [char_at]
|
||||
//
|
||||
implement
|
||||
Strptr1_at<>(i0) = let
|
||||
//
|
||||
val i1 = get_i()
|
||||
val i0 = ckastloc_gintGte(i0, 0)
|
||||
val i1 = ckastloc_gintBtwe(i1, i0, n0)
|
||||
//
|
||||
in
|
||||
$UN.castvwtp0(
|
||||
string_make_substring(line, i2sz(i0), i2sz(i1-i0))
|
||||
) (* $UN.castvwtp0 *)
|
||||
end // end of [Strptr1_at]
|
||||
//
|
||||
implement
|
||||
rmove<>() =
|
||||
if get_i() < n0 then inc_i()
|
||||
//
|
||||
vtypedef res_vt = List0_vt(Strptr1)
|
||||
//
|
||||
fun
|
||||
loop
|
||||
(
|
||||
i: int, res: res_vt
|
||||
) : res_vt =
|
||||
if
|
||||
is_end()
|
||||
then res
|
||||
else let
|
||||
val () =
|
||||
(
|
||||
if i > 0 then rmove()
|
||||
)
|
||||
val i0 = getpos()
|
||||
var f0 =
|
||||
(
|
||||
lam@(c: char) =<clo> c != ','
|
||||
)
|
||||
val () = rmove_while($UN.cast(addr@f0))
|
||||
val s0 = Strptr1_at(i0)
|
||||
in
|
||||
loop(i+1, list_vt_cons(s0, res))
|
||||
end // end of [else]
|
||||
//
|
||||
in
|
||||
list_vt_reverse(loop(0(*i*), list_vt_nil((*void*))))
|
||||
end // end of [csv_parse_line]
|
||||
|
||||
end // end of [local]
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
(* end of [csv_parse.hats] *)
|
||||
@@ -1,187 +0,0 @@
|
||||
(***********************************************************************)
|
||||
(* *)
|
||||
(* Applied Type System *)
|
||||
(* *)
|
||||
(***********************************************************************)
|
||||
|
||||
(*
|
||||
** ATS/Postiats - Unleashing the Potential of Types!
|
||||
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
|
||||
** All rights reserved
|
||||
**
|
||||
** ATS is free software; you can redistribute it and/or modify it under
|
||||
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
|
||||
** Free Software Foundation; either version 3, 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 *)
|
||||
(* Authoremail: hwxi AT cs DOT bu DOT edu *)
|
||||
(* Start time: December, 2012 *)
|
||||
|
||||
(* ****** ****** *)
|
||||
//
|
||||
// HX: shared by linset_listord (* ordered list *)
|
||||
// HX: shared by linset_avltree (* AVL-tree-based *)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
// HX-2013-02:
|
||||
// for sets of nonlinear elements
|
||||
//
|
||||
absvtype set_vtype (a:t@ype+) = ptr
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
vtypedef set (a:t0p) = set_vtype (a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
compare_elt_elt (x1: a, x2: a):<> int
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{} linset_nil{a:t0p} ():<> set(a)
|
||||
fun{} linset_make_nil{a:t0p} ():<> set(a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p} linset_sing (x: a):<!wrt> set(a)
|
||||
fun{a:t0p} linset_make_sing (x: a):<!wrt> set(a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_make_list (xs: List(INV(a))):<!wrt> set(a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{}
|
||||
linset_is_nil {a:t0p} (xs: !set(INV(a))):<> bool
|
||||
fun{}
|
||||
linset_isnot_nil {a:t0p} (xs: !set(INV(a))):<> bool
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p} linset_size (!set(INV(a))): size_t
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_is_member (xs: !set(INV(a)), x0: a):<> bool
|
||||
fun{a:t0p}
|
||||
linset_isnot_member (xs: !set(INV(a)), x0: a):<> bool
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_copy (!set(INV(a))):<!wrt> set(a)
|
||||
fun{a:t0p}
|
||||
linset_free (xs: set(INV(a))):<!wrt> void
|
||||
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_insert
|
||||
(xs: &set(INV(a)) >> _, x0: a):<!wrt> bool
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_takeout
|
||||
(
|
||||
&set(INV(a)) >> _, a, res: &(a?) >> opt(a, b)
|
||||
) :<!wrt> #[b:bool] bool(b) // endfun
|
||||
fun{a:t0p}
|
||||
linset_takeout_opt (&set(INV(a)) >> _, a):<!wrt> Option_vt(a)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_remove
|
||||
(xs: &set(INV(a)) >> _, x0: a):<!wrt> bool
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
// HX: choosing an element in an unspecified manner
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_choose
|
||||
(
|
||||
xs: !set(INV(a)), x: &a? >> opt (a, b)
|
||||
) :<!wrt> #[b:bool] bool(b)
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_choose_opt (xs: !set(INV(a))):<!wrt> Option_vt(a)
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_takeoutmax
|
||||
(
|
||||
xs: &set(INV(a)) >> _, res: &a? >> opt(a, b)
|
||||
) :<!wrt> #[b:bool] bool (b)
|
||||
fun{a:t0p}
|
||||
linset_takeoutmax_opt (xs: &set(INV(a)) >> _):<!wrt> Option_vt(a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_takeoutmin
|
||||
(
|
||||
xs: &set(INV(a)) >> _, res: &a? >> opt(a, b)
|
||||
) :<!wrt> #[b:bool] bool (b)
|
||||
fun{a:t0p}
|
||||
linset_takeoutmin_opt (xs: &set(INV(a)) >> _):<!wrt> Option_vt(a)
|
||||
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun{}
|
||||
fprint_linset$sep (FILEref): void // ", "
|
||||
//
|
||||
fun{a:t0p}
|
||||
fprint_linset (out: FILEref, xs: !set(INV(a))): void
|
||||
//
|
||||
overload fprint with fprint_linset
|
||||
//
|
||||
(* ****** ****** *)
|
||||
//
|
||||
fun{
|
||||
a:t0p}{env:vt0p
|
||||
} linset_foreach$fwork
|
||||
(x: a, env: &(env) >> _): void
|
||||
//
|
||||
fun{a:t0p}
|
||||
linset_foreach (set: !set(INV(a))): void
|
||||
fun{
|
||||
a:t0p}{env:vt0p
|
||||
} linset_foreach_env
|
||||
(set: !set(INV(a)), env: &(env) >> _): void
|
||||
// end of [linset_foreach_env]
|
||||
//
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_listize (xs: set(INV(a))): List0_vt (a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
fun{a:t0p}
|
||||
linset_listize1 (xs: !set(INV(a))): List0_vt (a)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
(* end of [linset.hats] *)
|
||||
Reference in New Issue
Block a user