File: catsparse_parsing_d0ecl.dats

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (503 lines) | stat: -rw-r--r-- 13,843 bytes parent folder | download | duplicates (4)
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
(* ****** ****** *)
//
// CATS-parsemit
//
(* ****** ****** *)
//
// HX-2014-07-02: start
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)

staload UN = $UNSAFE

(* ****** ****** *)
//
staload "./../SATS/catsparse.sats"
//
staload "./../SATS/catsparse_syntax.sats"
staload "./../SATS/catsparse_parsing.sats"
//
(* ****** ****** *)

infix ++
overload ++ with location_combine

(* ****** ****** *)

implement
parse_tmpdec
  (buf, bt, err) = let
//
val err0 = err
val n0 = tokbuf_get_ntok (buf)
val tok = tokbuf_get_token (buf)
val loc = tok.token_loc
//
macdef incby1 () = tokbuf_incby1 (buf)
//
in
//
case+
tok.token_node of
| T_KWORD(ATStmpdec()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent5 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then tmpdec_make_some (tok, ent2, ent4, ent5)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATStmpdec]
| T_KWORD(ATStmpdec_void()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then tmpdec_make_none (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATStmpdec_void]
//
| _ (*error*) => let
    val () = err := err + 1 in synent_null ()
  end (* end of [_] *)
//
end // end of [parse_tmpdec]

(* ****** ****** *)
//
implement
parse_tmpdecs
  (buf, bt, err) =
  list_vt2t (pstar_fun (buf, bt, parse_tmpdec))
//
(* ****** ****** *)

implement
parse_f0body
  (buf, bt, err) = let
//
val err0 = err
val n0 = tokbuf_get_ntok (buf)
val tok = tokbuf_get_token (buf)
val loc = tok.token_loc
//
macdef incby1 () = tokbuf_incby1 (buf)
//
in
//
case+
tok.token_node of
| T_LBRACE () => let
    val bt = 0
    val () = incby1 ()
    val ent1 =
      pif_fun (buf, bt, err, parse_tmpdecs, err0)
    val ent2 =
      pif_fun (buf, bt, err, parse_instrseq, err0)
    val ent3 = pif_fun (buf, bt, err, p_RBRACE, err0)
  in
    if err = err0
      then f0body_make (tok, ent1, ent2, ent3)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [T_LBRACE]
| _ (*error*) => let
    val () = err := err + 1 in synent_null ()
  end (* end of [_] *)
//
end // end of [parse_f0body]

(* ****** ****** *)

implement
parse_f0decl
  (buf, bt, err) = let
//
val err0 = err
var ent: synent?
val ntok0 = tokbuf_get_ntok (buf)
//
val ent1 = parse_f0head (buf, bt, err)
//
in
//
if (
err = err0
) then (
case+ 0 of
| _ when ptest_fun
  (
    buf, parse_f0body, ent
  ) => let
    val ent2 = synent_decode2{f0body}(ent)
  in
    f0decl_some (ent1, ent2)
  end // ...
//
| _ when
    p_SEMICOLON_test (buf) => f0decl_none (ent1)
//
| _ (*error*) => let
    val () = err := err + 1 in f0decl_none (ent1)
  end // end of [_]
//
) else tokbuf_set_ntok_null (buf, ntok0)
//
end // end of [parse_f0decl]

(* ****** ****** *)

implement
parse_d0ecl
  (buf, bt, err) = let
//
val err0 = err
var ent: synent?
//
val n0 = tokbuf_get_ntok (buf)
val tok = tokbuf_get_token (buf)
val loc = tok.token_loc
//
macdef incby1 () = tokbuf_incby1 (buf)
//
in
//
case+
tok.token_node of
//
| _ when
    ptest_SRPif0 (buf) => let
(*
    val bt = 0 // HX-2015-09-30: fixed
*)
    val () = pskip_SRPif0 (buf, 1(*level*))
  in
    parse_d0ecl (buf, bt, err)
  end // end of [#if(0)]
//
| T_KWORD(SRPinclude()) => let
    val bt = 0
    val () = incby1 ()
    val tok2 = tokbuf_get_token (buf)
  in
    case+ tok2.token_node of
    | T_STRING _ => let
        val () = incby1 () in d0ecl_include (tok, tok2)
      end // end of [T_STRING]
    | T_IDENT_alp _ => let
        val () = incby1 () in d0ecl_include (tok, tok2)
      end // end of [T_IDENT_alp]
    | _ (*error*) => tokbuf_set_ntok_null (buf, n0) 


  end // end of [SRPinclude]
//
| T_KWORD(SRPifdef()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = parse_i0dex (buf, bt, err) 
    val ent2 = pif_fun (buf, bt, err, parse_d0eclseq, err0)
    val ent3 = pif_fun (buf, bt, err, p_SRPendif, err0)
  in
    if err = err0
      then (
        d0ecl_ifdef (tok, ent1, ent2, ent3)
      ) else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [SRPifdef]
//
| T_KWORD(SRPifndef()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = parse_i0dex (buf, bt, err) 
    val ent2 = pif_fun (buf, bt, err, parse_d0eclseq, err0)
    val ent3 = pif_fun (buf, bt, err, p_SRPendif, err0)
  in
    if err = err0
      then (
        d0ecl_ifdef (tok, ent1, ent2, ent3)
      ) else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [SRPifndef]
//
| T_KWORD(TYPEDEF()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = parse_tyrec (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then let
(*
        val name = ent2.i0dex_sym
        val ((*void*)) =
          typedef_insert (name, ent3)
        // end of [val]
*)
      in
        d0ecl_typedef (tok, ent1, ent2)
      end // end of [then]
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [TYPEDEF]
//
| T_KWORD(ATSassume()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_assume (tok, ent2, ent3)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSassume]
//
| T_KWORD(ATSdyncst_mac()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
  in
    if err = err0
      then d0ecl_dyncst_mac (tok, ent2, ent3)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSdyncst_mac]
//
| T_KWORD(ATSdyncst_extfun()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent5 = pif_fun (buf, bt, err, parse_s0expseq, err0)
    val ent6 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent7 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent8 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent9 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent10 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dyncst_extfun (tok, ent2, ent5, ent8, ent9)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSdyncst_extfun]
//
| T_KWORD(ATSdyncst_valdec()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent5 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dyncst_valdec (tok, ent2, ent4, ent5)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSdyncst_valdec]
//
| T_KWORD(ATSdyncst_valimp()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent5 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dyncst_valimp (tok, ent2, ent4, ent5)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSdyncst_valimp]
//
| T_KWORD(ATSextcode_beg()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent2 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent3 = pif_fun (buf, bt, err, parse_extcode, err0)
    val ent4 = pif_fun (buf, bt, err, p_ATSextcode_end, err0)
    val ent5 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_RPAREN, err0)
  in
    if err = err0
      then d0ecl_extcode (tok, ent3, ent6)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSextcode_beg]
//
| T_KWORD(ATSstatmpdec()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent5 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then (
        d0ecl_statmp_some (tok, ent2, ent4, ent5)
      ) else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSstatmpdec]
//
| T_KWORD(ATSstatmpdec_void()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_statmp_none (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [ATSstatmpdec]
//
| _ when ptest_fun
  (
    buf, parse_fkind, ent
  ) => let
    val bt = 0
    val ent1 =
      synent_decode2{fkind}(ent)
    // end of [val]
    val ent2 = parse_f0decl (buf, bt, err)
  in
    if err = err0
      then d0ecl_fundecl (ent1, ent2)
      else tokbuf_set_ntok_null (buf, n0)
    // end of [if]
  end // end of [parse_fkind]
//
| T_KWORD(ATSclosurerize_beg()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_label, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, parse_s0exparg, err0)
    val ent5 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent6 = pif_fun (buf, bt, err, parse_s0exparg, err0)
    val ent7 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent8 = pif_fun (buf, bt, err, parse_s0exp, err0)
    val ent9 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent10 = pif_fun (buf, bt, err, parse_closurerize, err0)
    val ent11 = pif_fun (buf, bt, err, p_LPAREN, err0)
    val ent12 = pif_fun (buf, bt, err, p_RPAREN, err0)
  in
    if err = err0
      then (
        d0ecl_closurerize (tok, ent2, ent4, ent6, ent8, ent9)
      ) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSclosurerize_beg]
//
| T_KWORD(ATSdynloadflag_init()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dynloadflag_init (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSdynloadflag_init]
//
| T_KWORD(ATSdynloadflag_minit()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dynloadflag_minit (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSdynloadflag_minit]
//
| T_KWORD(ATSdynexn_dec()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dynexn_dec (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSdynexn_dec]
| T_KWORD(ATSdynexn_extdec()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent4 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dynexn_extdec (tok, ent2, ent3) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSdynexn_extdec]
| T_KWORD(ATSdynexn_initize()) => let
    val bt = 0
    val () = incby1 ()
    val ent1 = p_LPAREN (buf, bt, err)
    val ent2 = pif_fun (buf, bt, err, parse_i0dex, err0)
    val ent3 = pif_fun (buf, bt, err, p_COMMA, err0)
    val ent4 = pif_fun (buf, bt, err, p_STRING, err0)
    val ent5 = pif_fun (buf, bt, err, p_RPAREN, err0)
    val ent6 = pif_fun (buf, bt, err, p_SEMICOLON, err0)
  in
    if err = err0
      then d0ecl_dynexn_initize (tok, ent2, ent4, ent5) else tokbuf_set_ntok_null (buf, n0)
  end // end of [ATSdynexn_extdec]
//
| _ (*error*) => let
    val () = err := err + 1
    val () = the_parerrlst_add_ifnbt (bt, loc, PARERR_d0ecl)
  in
    synent_null ((*void*))
  end // end of [_]
//
end // end of [parse_d0ecl]

(* ****** ****** *)
//
implement
parse_d0eclseq
  (buf, bt, err) =
  list_vt2t (pstar_fun (buf, bt, parse_d0ecl))
//
(* ****** ****** *)

(* end of [catsparse_parsing_d0ecl.dats] *)