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
|
(* ****** ****** *)
//
// CATS-parsemit
//
(* ****** ****** *)
//
// HX-2014-08-04: start
//
(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
//
staload
UN = "prelude/SATS/unsafe.sats"
//
(* ****** ****** *)
//
staload "./../SATS/catsparse.sats"
staload "./../SATS/catsparse_syntax.sats"
//
(* ****** ****** *)
//
staload "./../SATS/catsparse_emit.sats"
//
(* ****** ****** *)
implement
emit_ENDL(out) = emit_text(out, "\n")
(* ****** ****** *)
implement
emit_SPACE(out) = emit_text(out, " ")
(* ****** ****** *)
implement
emit_DOT(out) = emit_text(out, ".")
(* ****** ****** *)
//
implement
emit_COLON(out) = emit_text(out, ":")
//
implement
emit_COMMA(out) = emit_text(out, ",")
//
implement
emit_SEMICOLON(out) = emit_text(out, ";")
//
(* ****** ****** *)
implement
emit_AMPER(out) = emit_text(out, "&")
(* ****** ****** *)
implement
emit_SHARP(out) = emit_text(out, "#")
(* ****** ****** *)
implement
emit_DOLLAR(out) = emit_text(out, "$")
(* ****** ****** *)
implement
emit_SQUOTE(out) = emit_text(out, "'")
implement
emit_DQUOTE(out) = emit_text(out, "\"")
(* ****** ****** *)
//
implement
emit_LPAREN(out) = emit_text(out, "(")
implement
emit_RPAREN(out) = emit_text(out, ")")
//
implement
emit_LBRACKET(out) = emit_text(out, "[")
implement
emit_RBRACKET(out) = emit_text(out, "]")
//
implement
emit_LBRACE(out) = emit_text(out, "{")
implement
emit_RBRACE(out) = emit_text(out, "}")
//
(* ****** ****** *)
implement
emit_MINUSGT(out) = emit_text(out, "->")
(* ****** ****** *)
implement
emit_flush(out) = fileref_flush(out)
implement
emit_newline(out) = fprint_newline(out)
(* ****** ****** *)
//
implement
emit_nspc(out, ind) =
(
//
if
(ind > 0)
then
(
emit_text(out, " "); emit_nspc(out, ind-1)
) (* end of [if] *)
//
) (* end of [emit_nspc] *)
//
(* ****** ****** *)
//
implement
emit_int(out, x) = fprint_int(out, x)
//
implement
emit_char(out, x) = fprint_char(out, x)
//
implement
emit_text(out, x) = fprint_string(out, x)
//
(* ****** ****** *)
//
implement
emit_symbol(out, x) =
fprint_string(out, symbol_get_name(x))
//
(* ****** ****** *)
//
implement
emit_i0de
(out, id) = emit_symbol(out, id.i0dex_sym)
implement
emit_label
(out, lab) = emit_symbol(out, lab.i0dex_sym)
//
(* ****** ****** *)
implement
emit_tokenlst
(out, toks) = let
//
fun
auxtok
(
out: FILEref, tok: token
) : void =
(
case+
tok.token_node of
//
| T_KWORD _ => ()
//
| T_ENDL() => emit_ENDL(out)
| T_SPACES(cs) => emit_text(out, cs)
//
| T_COMMENT_line _ => emit_COMMENT_line(out, tok)
| T_COMMENT_block _ => emit_COMMENT_block(out, tok)
//
| T_INT(_, rep) => emit_text(out, rep)
| T_FLOAT(_, rep) => emit_text(out, rep)
//
| T_STRING(str) => emit_text(out, str)
//
| T_IDENT_alp(name) =>
(
emit_text(out, name)
) (* end of [T_IDENT_alp] *)
| T_IDENT_srp(name) =>
(
emit_SHARP(out); emit_text(out, name)
) (* end of [T_IDENT_srp] *)
//
| T_IDENT_sym(name) => emit_text(out, name)
//
| T_LPAREN() => emit_LPAREN(out)
| T_RPAREN() => emit_RPAREN(out)
//
| T_LBRACKET() => emit_LBRACKET(out)
| T_RBRACKET() => emit_RBRACKET(out)
//
| T_LBRACE() => emit_LBRACE(out)
| T_RBRACE() => emit_RBRACE(out)
//
| T_LT((*void*)) => emit_text(out, "<")
| T_GT((*void*)) => emit_text(out, ">")
//
| T_MINUS() => emit_text(out, "-")
//
| T_COLON() => emit_text(out, ":")
//
| T_COMMA() => emit_text(out, ",")
| T_SEMICOLON() => emit_text(out, ";")
//
| T_SLASH() => emit_text(out, "/")
//
| _ (*unrecognized*) =>
{
val () = fprint!(out, "TOKERR(", tok, ")")
}
) (* end of [auxtok] *)
//
in
//
case+ toks of
| list_nil () => ()
| list_cons (tok, toks) =>
(
auxtok (out, tok); emit_extcode (out, toks)
) (* end of [list_cons] *)
//
end // end of [emit_tokenlst]
(* ****** ****** *)
//
implement
emit_extcode
(out, toks) = emit_tokenlst (out, toks)
//
(* ****** ****** *)
(* end of [catsparse_emit.dats] *)
|