@@ -49,6 +49,10 @@ let empty_full_state =
49
49
user_state = GramState. empty;
50
50
}
51
51
52
+ let assert_synterp () =
53
+ if ! Flags. in_synterp_phase = Some false then
54
+ CErrors. anomaly Pp. (str " The grammar cannot be modified during the interp phase." )
55
+
52
56
(* * Not marshallable! *)
53
57
let state = ref empty_full_state
54
58
@@ -73,7 +77,9 @@ let modify_state_unsync f state =
73
77
let current_state = if is_base then base_state else f state.current_state in
74
78
{ state with base_state; current_state }
75
79
76
- let modify_state_unsync f () = state := modify_state_unsync f ! state
80
+ let modify_state_unsync f () =
81
+ assert_synterp () ;
82
+ state := modify_state_unsync f ! state
77
83
78
84
let modify_keyword_state f =
79
85
modify_state_unsync (fun {estate;kwstate;recover;has_non_assoc} -> {estate; kwstate = f kwstate; recover; has_non_assoc})
@@ -90,6 +96,7 @@ let make_entry_unsync make remake state =
90
96
{ state with base_state; current_state }, e
91
97
92
98
let make_entry_unsync make remake () =
99
+ assert_synterp() ;
93
100
let statev, e = make_entry_unsync make remake ! state in
94
101
state := statev;
95
102
e
@@ -129,7 +136,9 @@ let grammar_extend_sync user_state entry rules state =
129
136
current_sync_extensions = GramExt entry :: state .current_sync_extensions;
130
137
}
131
138
132
- let grammar_extend_sync st e r () = state := grammar_extend_sync st e r ! state
139
+ let grammar_extend_sync st e r () =
140
+ assert_synterp() ;
141
+ state := grammar_extend_sync st e r ! state
133
142
134
143
type ('a,'b) entry_extension = {
135
144
eext_fun : 'a -> 'b Entry .t -> GramState .t -> GramState .t ;
@@ -157,6 +166,7 @@ let extend_entry_sync (type a b)
157
166
state, e
158
167
159
168
let extend_entry_sync tag interp data () =
169
+ assert_synterp() ;
160
170
let statev, e = extend_entry_sync tag interp data ! state in
161
171
state := statev;
162
172
e
@@ -469,19 +479,21 @@ let replay_sync_extension = function
469
479
| GramExt (Dyn (tag ,g )) -> extend_grammar_command tag g
470
480
| EntryExt (tag ,data ) -> ignore (extend_entry_command tag data : _ Entry.t )
471
481
472
- let unfreeze = function
473
- | {frozen_sync;} as frozen ->
474
- let to_remove, to_add, _common = factorize_grams (! state).current_sync_extensions frozen_sync in
475
- if CList. is_empty to_remove then begin
476
- List. iter replay_sync_extension (List. rev to_add);
477
- unfreeze_only_keywords frozen
478
- end
479
- else begin
480
- state := reset_to_base ! state;
481
- List. iter replay_sync_extension (List. rev frozen_sync);
482
- (* put back the keyword state, needed to support ssr hacks *)
483
- unfreeze_only_keywords frozen
484
- end
482
+ let unfreeze ({frozen_sync;} as frozen ) =
483
+ (* allow unfreezing synterp state even during interp phase *)
484
+ Flags. with_modified_ref Flags. in_synterp_phase (fun _ -> None ) (fun () ->
485
+ let to_remove, to_add, _common = factorize_grams (! state).current_sync_extensions frozen_sync in
486
+ if CList. is_empty to_remove then begin
487
+ List. iter replay_sync_extension (List. rev to_add);
488
+ unfreeze_only_keywords frozen
489
+ end
490
+ else begin
491
+ state := reset_to_base ! state;
492
+ List. iter replay_sync_extension (List. rev frozen_sync);
493
+ (* put back the keyword state, needed to support ssr hacks *)
494
+ unfreeze_only_keywords frozen
495
+ end )
496
+ ()
485
497
486
498
let freeze_state state = {
487
499
frozen_sync = state.current_sync_extensions;
0 commit comments