Skip to content

Commit 7463cda

Browse files
committed
Fix order of working set rules. Now they are printed in the right order and numbered from 0 upwards.
1 parent f3fcac3 commit 7463cda

File tree

8 files changed

+645
-634
lines changed

8 files changed

+645
-634
lines changed

core/grammar/cst.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let add_working_set_guard guard k loc =
1313
| None -> Some guard_param, guard_name
1414
| Some guard -> Some (Logical_formulae.AND (guard_param, guard)), guard_name
1515

16-
let append_to_ast_compil rev_instr compil =
16+
let append_to_ast_compil (nr_working_set_rules, rev_instr) compil =
1717
fst
1818
@@ List.fold_left
1919
(fun (r, k) -> function
@@ -30,7 +30,7 @@ let append_to_ast_compil rev_instr compil =
3030
Mods.StringMap.add new_guard_p_name true
3131
r.Ast.guard_param_values;
3232
},
33-
k + 1 )
33+
k - 1 )
3434
) else
3535
( { r with Ast.rules = (label, guard, (rule, loc)) :: r.Ast.rules },
3636
k )
@@ -86,4 +86,5 @@ let append_to_ast_compil rev_instr compil =
8686
(agent, site1, site2) :: r.Ast.sequential_bonds;
8787
},
8888
k ))
89-
(compil, 0) (List.rev rev_instr)
89+
(compil, nr_working_set_rules - 1)
90+
(List.rev rev_instr)

core/grammar/cst.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
(******************************************************************************)
88

99
val append_to_ast_compil :
10-
Ast.parsing_instruction list -> Ast.parsing_compil -> Ast.parsing_compil
10+
int * Ast.parsing_instruction list -> Ast.parsing_compil -> Ast.parsing_compil

core/grammar/klexer4.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
val model :
2-
Lexing.lexbuf -> Ast.parsing_instruction list * string Loc.annoted list
2+
Lexing.lexbuf ->
3+
(int * Ast.parsing_instruction list) * string Loc.annoted list
34

45
val compile :
56
Format.formatter ->

core/grammar/kparser4.mly

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515
let end_pos = Parsing.rhs_end_pos
1616
let start_pos = Parsing.rhs_start_pos
1717

18+
let nr_working_set_rules = ref 0
19+
let inc_working_set_rules () = nr_working_set_rules := !nr_working_set_rules + 1
20+
1821
let internal_memory = ref []
1922
let add x = internal_memory := x :: !internal_memory
2023
let output () =
21-
let o = List.rev !internal_memory in let () = internal_memory := [] in o
24+
let o = (!nr_working_set_rules, List.rev !internal_memory) in
25+
let () = internal_memory := [] in
26+
let () = nr_working_set_rules := 0 in
27+
o
2228
%}
2329

2430
%token EOF COMMA DOT OP_PAR CL_PAR OP_CUR CL_CUR OP_BRA CL_BRA AT SEMICOLON
@@ -35,7 +41,7 @@
3541
%token <string> SPACE COMMENT
3642

3743
%start model
38-
%type <Ast.parsing_instruction list> model
44+
%type <int * Ast.parsing_instruction list> model
3945

4046
%start interactive_command
4147
%type <(Ast.mixture,Ast.mixture,string,Ast.rule) Ast.command> interactive_command
@@ -812,10 +818,13 @@ perturbation_declaration:
812818
($1,None,e,post) }
813819
;
814820

821+
working_set_rule:
822+
| LABEL annoted rule
823+
{let guard, rule = $3 in add (Ast.RULE (Some ($1, rhs_pos 1), guard, rule, true)); inc_working_set_rules () }
824+
| rule { let guard, rule = $1 in add (Ast.RULE (None, guard, rule, true)); inc_working_set_rules () }
825+
815826
working_set:
816-
| LABEL annoted rule working_set
817-
{ add (let guard, rule = $3 in Ast.RULE(Some ($1, rhs_pos 1),guard, rule, true)) }
818-
| rule working_set { let guard,rule = $1 in add (Ast.RULE (None, guard, rule, true)) }
827+
| working_set_rule working_set { }
819828
| { }
820829

821830
sentence:

0 commit comments

Comments
 (0)