Commit c19f0d33c83014a58892466ce8b3dbbdda7121aa
1 parent
ebbf9d05
Exists in
master
- AST loading may now have modifying goal (IN > OUT :- MOD), which is executed with the translation.
- new command line structure, now it's a sequence of action verbs.
Showing
1 changed file
with
24 additions
and
12 deletions
Show diff stats
fzn-parser/fznslurp.pl
... | ... | @@ -6,24 +6,39 @@ main :- |
6 | 6 | argument_list(A), |
7 | 7 | main(A). |
8 | 8 | |
9 | -main([load]) :- !, load_ast(AST), dump_ast(AST), halt. | |
10 | -main([]) :- !. | |
9 | +main([ACTION|REST]) :- action(ACTION), !, main(REST). | |
10 | +main([]). | |
11 | + | |
12 | +action(load) :- !, load_ast(AST), g_assign(ast, AST). | |
13 | +action(dump) :- !, g_read(ast, AST), dump_ast(AST). | |
14 | +action(halt) :- !, halt. | |
15 | +action(ACTION) :- format("%w: unknown action.\n", [ACTION]). | |
11 | 16 | |
12 | 17 | |
13 | 18 | % ----------------------------------------------------------------------------- |
14 | 19 | |
15 | -load_ast(AST) :- load_ast(_>[], [], AST). | |
20 | +%% beware: fails if load_ast/3 does not finish with 3rd arg singular list | |
21 | + | |
22 | +load_ast(AST) :- g_read(ast_debug, true), !, load_ast_deb(_>[], [], [AST]). | |
23 | +load_ast(AST) :- load_ast(_>[], [], [AST]). | |
16 | 24 | |
17 | 25 | 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). | |
21 | -load_ast(IN > INT, IN, OUT) :- read(OP), !, | |
22 | - load_ast(OP, INT, OUT). | |
26 | +load_ast((IN > INT :- MOD), IN, OUT) :- | |
27 | + call(MOD), | |
28 | + read(OP), !, | |
29 | + load_ast(OP, INT, OUT). | |
30 | +load_ast((IN > INT), IN, OUT) :- | |
31 | + read(OP), !, | |
32 | + load_ast(OP, INT, OUT). | |
33 | + | |
34 | +load_ast_deb(end_of_file, AST, AST). | |
35 | +load_ast_deb(IN > INT, IN, OUT) :- read(OP), !, | |
36 | + write(OP), nl, | |
37 | + load_ast_deb(OP, INT, OUT). | |
23 | 38 | |
24 | 39 | % ----------------------------------------------------------------------------- |
25 | 40 | |
26 | -dump_ast([fzn(PREDS, VARS, CONSTRS, SOLVE)]) :- | |
41 | +dump_ast(fzn(PREDS, VARS, CONSTRS, SOLVE)) :- | |
27 | 42 | !, |
28 | 43 | format("AST:\n", []), |
29 | 44 | format(" preds:\n", []), PREDS=preds(PS), dump_list(PS), |
... | ... | @@ -39,6 +54,3 @@ dump_list([]). |
39 | 54 | dump_list([I|Is]) :- format(" ~w\n", [I]), dump_list(Is). |
40 | 55 | |
41 | 56 | % ----------------------------------------------------------------------------- |
42 | - | |
43 | -slurp(FILE, AST) :- see(FILE), load_ast(AST), !, seen. | |
44 | -slurp(_, end_of_file) :- seen. | ... | ... |