diff --git a/src/parsing/lpParser.ml b/src/parsing/lpParser.ml index 3bdd29d4c..9f953b0ed 100644 --- a/src/parsing/lpParser.ml +++ b/src/parsing/lpParser.ml @@ -433,11 +433,15 @@ let term_id (lb:'token lexbuf): p_term = (* commands *) -let open_ (priv:bool) (lb:'token lexbuf) : p_command_aux = +(* [req] tells whether the command starts with the [require] keyword: + [require [private] open] loads the modules and opens them + ([P_require]), while a bare [[private] open] only opens modules + that are already loaded ([P_open]). *) +let open_ (req:bool) (priv:bool) (lb:'token lexbuf) : p_command_aux = if log_enabled() then log "%s" __FUNCTION__; consume OPEN lb; let ps = nelist path_tks path lb in - P_require(Some priv,ps) + if req then P_require(Some priv,ps) else P_open(priv,ps) let rec symbol (p_sym_mod:p_modifier list) (lb:'token lexbuf): p_command_aux = if log_enabled() then log "%s" __FUNCTION__; @@ -520,7 +524,7 @@ and command (lb:'token lexbuf) : p_command = end | [{elt=P_expo Term.Privat;_}] -> begin match current_token lb with - | OPEN -> extend_pos lb (*__FUNCTION__*) pos1 (open_ true lb) + | OPEN -> extend_pos lb (*__FUNCTION__*) pos1 (open_ false true lb) | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | L_PAREN @@ -546,10 +550,10 @@ and command (lb:'token lexbuf) : p_command = begin match current_token lb with | OPEN -> - extend_pos lb (*__FUNCTION__*) pos1 (open_ false lb) + extend_pos lb (*__FUNCTION__*) pos1 (open_ true false lb) | PRIVATE -> consume_token lb; - extend_pos lb (*__FUNCTION__*) pos1 (open_ true lb) + extend_pos lb (*__FUNCTION__*) pos1 (open_ true true lb) | QID _ -> let ps = nelist path_tks path lb in begin @@ -570,7 +574,7 @@ and command (lb:'token lexbuf) : p_command = | _ -> expected lb "" [OPEN;PRIVATE;QID[]] end | OPEN -> - extend_pos lb (*__FUNCTION__*) pos1 (open_ false lb) + extend_pos lb (*__FUNCTION__*) pos1 (open_ false false lb) | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | L_PAREN diff --git a/tests/KO/open_not_required.lp b/tests/KO/open_not_required.lp new file mode 100644 index 000000000..dfc4496a9 --- /dev/null +++ b/tests/KO/open_not_required.lp @@ -0,0 +1,3 @@ +// A bare [open] does not load modules: the module must have been +// required first (with [require] or [require open]). +open tests.OK.boolean;