Commit ebbf9d0596c5185358cecd6a2b4c97e7a023746d
1 parent
39c71c9f
Exists in
master
dump_ast looks prettier
Showing
1 changed file
with
34 additions
and
3 deletions
Show diff stats
fzn-parser/fznslurp.pl
1 | 1 | % == No, Emacs this is -*-Prolog-*- code, not what you thought... ============= |
2 | 2 | |
3 | +:- initialization(main). | |
4 | + | |
5 | +main :- | |
6 | + argument_list(A), | |
7 | + main(A). | |
8 | + | |
9 | +main([load]) :- !, load_ast(AST), dump_ast(AST), halt. | |
10 | +main([]) :- !. | |
11 | + | |
12 | + | |
13 | +% ----------------------------------------------------------------------------- | |
14 | + | |
3 | 15 | load_ast(AST) :- load_ast(_>[], [], AST). |
4 | 16 | |
5 | 17 | load_ast(end_of_file, AST, AST). |
18 | +load_ast(IN > INT, IN, OUT) :- g_read(ast_debug, true), read(OP), !, | |
19 | + write(OP), nl, | |
20 | + load_ast(OP, INT, OUT). | |
6 | 21 | load_ast(IN > INT, IN, OUT) :- read(OP), !, |
7 | - ( g_read(ast_debug, true) -> | |
8 | - write(OP), nl | |
9 | - ; true ), | |
10 | 22 | load_ast(OP, INT, OUT). |
11 | 23 | |
24 | +% ----------------------------------------------------------------------------- | |
25 | + | |
26 | +dump_ast([fzn(PREDS, VARS, CONSTRS, SOLVE)]) :- | |
27 | + !, | |
28 | + format("AST:\n", []), | |
29 | + format(" preds:\n", []), PREDS=preds(PS), dump_list(PS), | |
30 | + format(" vars:\n", []), VARS=vars(VS), dump_list(VS), | |
31 | + format(" constrs:\n", []), CONSTRS=constrs(CS), dump_list(CS), | |
32 | + format(" goal:\n ~w\n", [SOLVE]). | |
33 | + | |
34 | +dump_ast(AST) :- write(AST), nl. | |
35 | + | |
36 | +% ----------------------------------------------------------------------------- | |
37 | + | |
38 | +dump_list([]). | |
39 | +dump_list([I|Is]) :- format(" ~w\n", [I]), dump_list(Is). | |
40 | + | |
41 | +% ----------------------------------------------------------------------------- | |
42 | + | |
12 | 43 | slurp(FILE, AST) :- see(FILE), load_ast(AST), !, seen. |
13 | 44 | slurp(_, end_of_file) :- seen. | ... | ... |