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
|
(* ****** ****** *)
//
// CATS-parsemit
//
(* ****** ****** *)
//
// HX-2014-07-02: start
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
staload UN = $UNSAFE
(* ****** ****** *)
//
staload
DA = "libats/SATS/dynarray.sats"
staload
_(*DA*) = "libats/DATS/dynarray.dats"
//
(* ****** ****** *)
staload "./../SATS/catsparse.sats"
(* ****** ****** *)
assume tokbuf_vt0ype = _tokbuf_vt0ype
(* ****** ****** *)
implement
tokbuf_initize_string
(buf, inp) = let
//
#define TOKBUFSZ 1024
//
val () = buf.tokbuf_ntok := i2sz(0)
val () = buf.tokbuf_tkbf := $DA.dynarray_make_nil(i2sz(TOKBUFSZ))
val () = lexbuf_initize_string (buf.tokbuf_lxbf, inp)
//
in
// nothing
end // end of [tokbuf_initize_string]
(* ****** ****** *)
implement
tokbuf_initize_fileref
(buf, inp) = let
//
#define TOKBUFSZ 1024
//
val () = buf.tokbuf_ntok := i2sz(0)
val () = buf.tokbuf_tkbf := $DA.dynarray_make_nil(i2sz(TOKBUFSZ))
val () = lexbuf_initize_fileref (buf.tokbuf_lxbf, inp)
//
in
// nothing
end // end of [tokbuf_initize_fileref]
(* ****** ****** *)
implement
tokbuf_reset
(buf) = () where
{
val ntok = buf.tokbuf_ntok
val ((*void*)) = buf.tokbuf_ntok := i2sz(0)
val ntok2 = $DA.dynarray_removeseq_at (buf.tokbuf_tkbf, i2sz(0), ntok)
} (* end of [tokbuf_reset] *)
(* ****** ****** *)
implement
tokbuf_uninitize
(buf) = () where
{
//
val () =
$DA.dynarray_free (buf.tokbuf_tkbf)
//
val (
) = lexbuf_uninitize (buf.tokbuf_lxbf)
//
} (* end of [tokbuf_uninitize] *)
(* ****** ****** *)
implement
tokbuf_get_ntok (buf) = buf.tokbuf_ntok
implement
tokbuf_set_ntok (buf, ntok) = buf.tokbuf_ntok := ntok
(* ****** ****** *)
//
implement
tokbuf_incby1
(buf) = buf.tokbuf_ntok := succ(buf.tokbuf_ntok)
implement
tokbuf_incby_count
(buf, n) = buf.tokbuf_ntok := buf.tokbuf_ntok + n
//
(* ****** ****** *)
implement
tokbuf_get_token
(buf) = let
//
val ntok = buf.tokbuf_ntok
val ptok =
$DA.dynarray_getref_at (buf.tokbuf_tkbf, ntok)
//
in
//
if
isneqz(ptok)
then $UN.cptr_get (ptok)
else let
//
val tok = lexbuf_get_token_skip (buf.tokbuf_lxbf)
val ((*void*)) =
$DA.dynarray_insert_atend_exn (buf.tokbuf_tkbf, tok)
//
in
tok
end // end of [else]
//
end // end of [tokbuf_get_token]
(* ****** ****** *)
implement
tokbuf_get_token_any
(buf) = let
//
val ntok = buf.tokbuf_ntok
val ptok =
$DA.dynarray_getref_at (buf.tokbuf_tkbf, ntok)
//
in
//
if
isneqz(ptok)
then $UN.cptr_get<token>(ptok)
else let
//
val tok = lexbuf_get_token_any(buf.tokbuf_lxbf)
val ((*void*)) =
$DA.dynarray_insert_atend_exn(buf.tokbuf_tkbf, tok)
//
in
tok
end // end of [else]
//
end // end of [tokbuf_get_token_any]
(* ****** ****** *)
implement
tokbuf_getinc_token
(buf) = tok where
{
val tok = tokbuf_get_token(buf)
val ((*void*)) = tokbuf_incby1(buf)
} (* end of [tokbuf_getinc_token] *)
(* ****** ****** *)
implement
tokbuf_get_location (buf) =
let val tok = tokbuf_get_token(buf) in tok.token_loc end
// end of [tokbuf_get_location]
(* ****** ****** *)
(* end of [catsparse_tokbuf.dats] *)
|